瀏覽代碼

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 年之前
父節點
當前提交
ab01b0ebd7
共有 3 個文件被更改,包括 18 次插入4 次删除
  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.