From b7235b21c92168dd1c7456e82b3fcca71817defb Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Tue, 23 Jun 2009 18:42:53 +0000 Subject: [PATCH] * no longer allow assigning values to typecasted properties, because in case the getter is a function, the result is that first the getter is called, and subsequently the temp holding the function result is overwritten (thus not changing anything). This is Delphi-compatible, and fixes tests/tbf/tb0214* git-svn-id: trunk@13320 - --- .gitattributes | 1 + compiler/htypechk.pas | 16 +++++++++++++++- tests/tbf/tb0214a.pp | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/tbf/tb0214a.pp diff --git a/.gitattributes b/.gitattributes index 1a20504f8c..b302a933af 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6977,6 +6977,7 @@ tests/tbf/tb0211a.pp svneol=native#text/plain tests/tbf/tb0212.pp svneol=native#text/plain tests/tbf/tb0213.pp svneol=native#text/plain tests/tbf/tb0214.pp svneol=native#text/plain +tests/tbf/tb0214a.pp svneol=native#text/plain tests/tbf/tb0215.pp svneol=native#text/plain tests/tbf/tb0215a.pp svneol=native#text/plain tests/tbf/tb0215b.pp svneol=native#text/plain diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index 5397b5ac36..5af9a62751 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -955,7 +955,8 @@ implementation gotvec, gotclass, gotdynarray, - gotderef : boolean; + gotderef, + gottypeconv : boolean; fromdef, todef : tdef; errmsg, @@ -976,6 +977,7 @@ implementation gotpointer:=false; gotdynarray:=false; gotstring:=false; + gottypeconv:=false; hp:=p; if not(valid_void in opts) and is_void(hp.resultdef) then @@ -1013,6 +1015,17 @@ implementation { same when we got a class and subscript (= deref) } (gotclass and gotsubscript) or ( + { allowing assignments to typecasted properties + a) is Delphi-incompatible + b) causes problems in case the getter is a function + (because then the result of the getter is + typecasted to this type, and then we "assign" to + this typecasted function result) -> always + disallow, since property accessors should be + transparantly changeable to functions at all + times + } + not(gottypeconv) and not(gotsubscript and gotrecord) and not(gotstring and gotvec) ) then @@ -1059,6 +1072,7 @@ implementation end; typeconvn : begin + gottypeconv:=true; { typecast sizes must match, exceptions: - implicit typecast made by absolute - from formaldef diff --git a/tests/tbf/tb0214a.pp b/tests/tbf/tb0214a.pp new file mode 100644 index 0000000000..2d8571624a --- /dev/null +++ b/tests/tbf/tb0214a.pp @@ -0,0 +1,23 @@ +{ %fail } + +{$ifdef fpc} +{$mode delphi} +{$endif} + +type + tc = class + private + fl: longint; + public + property l: longint read fl write fl; + end; + +var + c: tc; +begin + { should give an error stating that you cannot assign to left hand side } + { (generated code also does not result in an assignment) } + cardinal(c.l):=cardinal(5); +end. + +