Browse Source

* properly reject function calls as target of absolute, resolves #40977
* better error message on invalid expressions for absolute

florian 9 months ago
parent
commit
b28681e91d
3 changed files with 25 additions and 2 deletions
  1. 8 1
      compiler/htypechk.pas
  2. 1 1
      compiler/msg/errore.msg
  3. 16 0
      tests/webtbf/tw40977.pp

+ 8 - 1
compiler/htypechk.pas

@@ -1852,7 +1852,7 @@ implementation
                      mayberesettypeconvs;
                      mayberesettypeconvs;
                      exit;
                      exit;
                    end
                    end
-                 else
+                 else if hp.nodetype=blockn then
                    begin
                    begin
                      hp2:=tblocknode(hp).statements;
                      hp2:=tblocknode(hp).statements;
                      if assigned(hp2) then
                      if assigned(hp2) then
@@ -1870,6 +1870,13 @@ implementation
                          mayberesettypeconvs;
                          mayberesettypeconvs;
                          exit;
                          exit;
                        end;
                        end;
+                   end
+                 else
+                   begin
+                     if report_errors then
+                      CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
+                     mayberesettypeconvs;
+                     exit;
                    end;
                    end;
                end;
                end;
              inlinen :
              inlinen :

+ 1 - 1
compiler/msg/errore.msg

@@ -789,7 +789,7 @@ parser_e_directive_only_one_var=03095_E_$1 can be associated with only one varia
 % Var Z : Longint;
 % Var Z : Longint;
 %     X,Y : Longint absolute Z;
 %     X,Y : Longint absolute Z;
 % \end{verbatim}
 % \end{verbatim}
-parser_e_absolute_only_to_var_or_const=03096_E_absolute can only be associated with a var or const
+parser_e_absolute_only_to_var_or_const=03096_E_absolute can only be associated with a variable or constant representing an address
 % The address of an \var{absolute} directive can only point to a variable or
 % The address of an \var{absolute} directive can only point to a variable or
 % constant. Therefore, the following code will produce this error:
 % constant. Therefore, the following code will produce this error:
 % \begin{verbatim}
 % \begin{verbatim}

+ 16 - 0
tests/webtbf/tw40977.pp

@@ -0,0 +1,16 @@
+{ %fail }
+program Project1;
+
+procedure foo2;
+begin
+end;
+
+procedure foo(bar: integer);
+var x: integer absolute foo(1);
+begin
+  foo2;
+end;
+
+begin
+  foo(1);
+end.