patch 8.2.4582: useless code handling a type declaration

Problem:    Useless code handling a type declaration.
Solution:   Remove the code and give an error.
diff --git a/src/testdir/dumps/Test_misplaced_type.dump b/src/testdir/dumps/Test_misplaced_type.dump
new file mode 100644
index 0000000..afb82a0
--- /dev/null
+++ b/src/testdir/dumps/Test_misplaced_type.dump
@@ -0,0 +1,6 @@
+|~+0#4040ff13#ffffff0| @73
+|~| @73
+|~| @73
+|~| @73
+|E+0#ffffff16#e000002|1|2|7|2|:| |U|s|i|n|g| |t|y|p|e| |n|o|t| |i|n| |a| |s|c|r|i|p|t| |c|o|n|t|e|x|t|:| |:| |s|t|r|i|n|g| +0#0000000#ffffff0@23
+|P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| |c|o|n|t|i|n|u|e> +0#0000000&@35
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index ec0d547..3ad9c9d 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -3942,10 +3942,6 @@
       enddef
 
       def Profile()
-        profile start Xprofile.log
-        profile func ProfiledWithLambda
-        # mark ProfiledNested for profiling to avoid E1271
-        profile func ProfiledNested
         ProfiledWithLambda()
         ProfiledNested()
 
@@ -3957,8 +3953,20 @@
         profdel func *
         profile pause
       enddef
-      Profile()
-      writefile(['done'], 'Xdidprofile')
+
+      var result = 'done'
+      try
+        # mark functions for profiling now to avoid E1271
+        profile start Xprofile.log
+        profile func ProfiledWithLambda
+        profile func ProfiledNested
+
+        Profile()
+      catch
+        result = 'failed: ' .. v:exception
+      finally
+        writefile([result], 'Xdidprofile')
+      endtry
   END
   writefile(lines, 'Xprofile.vim')
   call system(g:GetVimCommand()
@@ -3974,6 +3982,16 @@
   delete('Xprofile.vim')
 enddef
 
+def Test_misplaced_type()
+  writefile(['let g:somevar = "asdf"'], 'XTest_misplaced_type')
+  var buf = g:RunVimInTerminal('-S XTest_misplaced_type', {'rows': 6})
+  term_sendkeys(buf, ":vim9cmd echo islocked('g:somevar: string')\<CR>")
+  g:VerifyScreenDump(buf, 'Test_misplaced_type', {})
+
+  g:StopVimInTerminal(buf)
+  delete('XTest_misplaced_type')
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new