From 72758864e47eded99c85d1243dffc06af2b56d61 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 18 Apr 2010 07:55:42 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + compiler/ptconst.pas | 11 ++++++++--- tests/webtbf/tw16234.pp | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/webtbf/tw16234.pp diff --git a/.gitattributes b/.gitattributes index bedc3679bd..cd69213ce6 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/ptconst.pas b/compiler/ptconst.pas index 81a5e5b245..bfcc40de1a 100644 --- a/compiler/ptconst.pas +++ b/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 diff --git a/tests/webtbf/tw16234.pp b/tests/webtbf/tw16234.pp new file mode 100644 index 0000000000..7ce0d7b064 --- /dev/null +++ b/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.