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 years ago
parent
commit
ab01b0ebd7
3 changed files with 18 additions and 4 deletions
  1. 4 2
      compiler/aasmcnst.pas
  2. 2 2
      compiler/ngtcon.pas
  3. 12 0
      tests/webtbf/tw39393.pp

+ 4 - 2
compiler/aasmcnst.pas

@@ -1244,8 +1244,10 @@ implementation
 
    destructor ttai_typedconstbuilder.destroy;
      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);
        faggregateinformation.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
                         ftcb.queue_emit_const(tconstsym(srsym))
                       else
-                        Message(type_e_variable_id_expected);
+                        Message(type_e_constant_expr_expected);
                     else
-                      Message(type_e_variable_id_expected);
+                      Message(type_e_constant_expr_expected);
                   end;
                 end
               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.