Browse Source

Typed constants: no internalerror on failure

Don't check whether the expression queue is empty in the destructor in case
there was an error. Also improved error messages (constant expression instead
of variable expression expected).

Resolves #39393
Jonas Maebe 3 năm trước cách đây
mục cha
commit
ab01b0ebd7

+ 4 - 2
compiler/aasmcnst.pas

@@ -1244,8 +1244,10 @@ implementation
 
 
    destructor ttai_typedconstbuilder.destroy;
    destructor ttai_typedconstbuilder.destroy;
      begin
      begin
-       { the queue should have been flushed if it was used }
-       if fqueue_offset<>low(fqueue_offset) then
+       { the queue should have been flushed if it was used
+         (but if there were errors, we may have aborted before that happened) }
+       if (fqueue_offset<>low(fqueue_offset)) and
+          (ErrorCount=0) then
          internalerror(2014062901);
          internalerror(2014062901);
        faggregateinformation.free;
        faggregateinformation.free;
        fasmlist.free;
        fasmlist.free;

+ 2 - 2
compiler/ngtcon.pas

@@ -1014,9 +1014,9 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                       if tconstsym(srsym).consttyp=constresourcestring then
                       if tconstsym(srsym).consttyp=constresourcestring then
                         ftcb.queue_emit_const(tconstsym(srsym))
                         ftcb.queue_emit_const(tconstsym(srsym))
                       else
                       else
-                        Message(type_e_variable_id_expected);
+                        Message(type_e_constant_expr_expected);
                     else
                     else
-                      Message(type_e_variable_id_expected);
+                      Message(type_e_constant_expr_expected);
                   end;
                   end;
                 end
                 end
               else
               else

+ 12 - 0
tests/webtbf/tw39393.pp

@@ -0,0 +1,12 @@
+{ %fail }
+
+program project1;
+{$mode objfpc}{$H+}
+function bug(s: string): string;
+var
+  p:pointer=@s;//internal error 2014062901
+begin
+end;
+
+begin
+end.