瀏覽代碼

* throw proper error if no suitable NewInstance method is found, resolves #41274

florian 1 月之前
父節點
當前提交
18f2553e8e
共有 3 個文件被更改,包括 19 次插入1 次删除
  1. 3 0
      compiler/msg/errore.msg
  2. 1 1
      compiler/psub.pas
  3. 15 0
      tests/webtbf/tw41274.pp

+ 3 - 0
compiler/msg/errore.msg

@@ -1705,6 +1705,9 @@ parser_e_cannot_evaluate_expression_at_compile_time=03372_E_Expression cannot be
 parser_e_type_alread_forward=03373_E_Duplicate forward type declaration: $1
 parser_e_type_alread_forward=03373_E_Duplicate forward type declaration: $1
 % Types might be defined only once as forward:
 % Types might be defined only once as forward:
 % \var{type myclass = class; myclass = class;} is not allowed
 % \var{type myclass = class; myclass = class;} is not allowed
+parser_e_no_suitable_newinstance_method_found=03374_E_No suitable NewInstance method for class instance creation found
+% To create a new instance of a class, a suitable NewInstance (like \var{TObject.NewInstance}) method must be found. The symbol name NewInstance
+% might not be used for other purposes than to create a new instance of a class.
 %
 %
 % \end{description}
 % \end{description}
 %
 %

+ 1 - 1
compiler/psub.pas

@@ -493,7 +493,7 @@ implementation
                             nil));
                             nil));
                       end
                       end
                     else
                     else
-                      internalerror(200305108);
+                      Message(parser_e_no_suitable_newinstance_method_found);
                   end
                   end
                 else
                 else
                   if is_object(current_structdef) then
                   if is_object(current_structdef) then

+ 15 - 0
tests/webtbf/tw41274.pp

@@ -0,0 +1,15 @@
+{ %fail }
+{$mode objfpc}
+type
+  tt = class
+    ff: byte;
+    property NewInstance: byte read ff;
+    constructor Create;
+  end;
+
+constructor tt.Create;
+begin // Error: Internal error 200305108
+end;
+
+begin
+end.