瀏覽代碼

* only allow field names in record/object typed constant declarations (mantis #16234)
* improved error recovery after encountering invalid field name in record/object typed constant
declaration

git-svn-id: trunk@15150 -

Jonas Maebe 15 年之前
父節點
當前提交
72758864e4
共有 3 個文件被更改,包括 27 次插入3 次删除
  1. 1 0
      .gitattributes
  2. 8 3
      compiler/ptconst.pas
  3. 18 0
      tests/webtbf/tw16234.pp

+ 1 - 0
.gitattributes

@@ -9664,6 +9664,7 @@ tests/webtbf/tw1599.pp svneol=native#text/plain
 tests/webtbf/tw1599b.pp svneol=native#text/plain
 tests/webtbf/tw16022.pp svneol=native#text/plain
 tests/webtbf/tw16203.pp svneol=native#text/plain
+tests/webtbf/tw16234.pp svneol=native#text/plain
 tests/webtbf/tw1633.pp svneol=native#text/plain
 tests/webtbf/tw1642.pp svneol=native#text/plain
 tests/webtbf/tw1655.pp svneol=native#text/plain

+ 8 - 3
compiler/ptconst.pas

@@ -1307,10 +1307,15 @@ implementation
                     st:=nil;
                 end;
 
-              if srsym=nil then
+              if (srsym=nil) or
+                 (srsym.typ<>fieldvarsym) then
                 begin
-                  Message1(sym_e_id_not_found,sorg);
-                  consume_all_until(_SEMICOLON);
+                  if (srsym=nil) then
+                    Message1(sym_e_id_not_found,sorg)
+                  else
+                    Message1(sym_e_illegal_field,sorg);
+                  consume_all_until(_RKLAMMER);
+                  break;
                 end
               else
                 with tfieldvarsym(srsym) do

+ 18 - 0
tests/webtbf/tw16234.pp

@@ -0,0 +1,18 @@
+{ %fail }
+
+type
+MyObjType = object	
+ Field1 : String;
+ Field2 : String;
+ Field3 : String;
+ property Prop3:String read Field3;
+end;
+
+var // or const
+ Obj: MyObjType = (Prop3:'prop3';Field3:'field3'); // actually sets Field1 ?!
+
+begin
+ writeln(Obj.Field1); // prints 'prop3' ?!
+ writeln(Obj.Field3); // prints 'field3'
+ writeln(Obj.Prop3); // prints 'field3'
+end.