Browse Source

compiler: don't compile incorrect statements if operators are involved (issue #0015338) + test

git-svn-id: trunk@14458 -
paul 15 years ago
parent
commit
d89463588c
3 changed files with 17 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/pstatmnt.pas
  3. 12 0
      tests/test/toperator7.pp

+ 1 - 0
.gitattributes

@@ -9083,6 +9083,7 @@ tests/test/toperator3.pp svneol=native#text/plain
 tests/test/toperator4.pp svneol=native#text/plain
 tests/test/toperator4.pp svneol=native#text/plain
 tests/test/toperator5.pp svneol=native#text/plain
 tests/test/toperator5.pp svneol=native#text/plain
 tests/test/toperator6.pp svneol=native#text/plain
 tests/test/toperator6.pp svneol=native#text/plain
+tests/test/toperator7.pp svneol=native#text/plain
 tests/test/tover1.pp svneol=native#text/plain
 tests/test/tover1.pp svneol=native#text/plain
 tests/test/tover2.pp svneol=native#text/plain
 tests/test/tover2.pp svneol=native#text/plain
 tests/test/tover3.pp svneol=native#text/plain
 tests/test/tover3.pp svneol=native#text/plain

+ 4 - 1
compiler/pstatmnt.pas

@@ -1182,7 +1182,10 @@ implementation
              if not(p.nodetype in [nothingn,errorn,calln,ifn,assignn,breakn,inlinen,
              if not(p.nodetype in [nothingn,errorn,calln,ifn,assignn,breakn,inlinen,
                                    continuen,labeln,blockn,exitn]) or
                                    continuen,labeln,blockn,exitn]) or
                 ((p.nodetype=inlinen) and
                 ((p.nodetype=inlinen) and
-                 not is_void(p.resultdef)) then
+                 not is_void(p.resultdef)) or
+                ((p.nodetype=calln) and
+                 (assigned(tcallnode(p).procdefinition)) and
+                 (tcallnode(p).procdefinition.proctypeoption=potype_operator)) then
                Message(parser_e_illegal_expression);
                Message(parser_e_illegal_expression);
 
 
              { Specify that we don't use the value returned by the call.
              { Specify that we don't use the value returned by the call.

+ 12 - 0
tests/test/toperator7.pp

@@ -0,0 +1,12 @@
+{%FAIL}
+program toperator7;
+{$mode objfpc}
+
+uses
+  Variants;
+var
+  AValue: Variant;
+begin
+  // this construction must fail
+  AValue = 1;
+end.