* 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 -
This commit is contained in:
Jonas Maebe 2009-06-23 18:42:53 +00:00
parent 77a3e52caf
commit b7235b21c9
3 changed files with 39 additions and 1 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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

23
tests/tbf/tb0214a.pp Normal file
View File

@ -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.