pastojs: pass class var to var argument

This commit is contained in:
mattias 2019-03-07 14:49:46 +00:00
parent 8f6a355ec5
commit e9d041e0d5
2 changed files with 29 additions and 17 deletions

View File

@ -7871,16 +7871,18 @@ var
var
Call: TJSCallExpression;
begin
if AssignContext=nil then exit;
if AssignContext.LeftResolved.LoTypeEl is TPasRecordType then
if AssignContext<>nil then
begin
// aRecord:=right -> aRecord.$assign(right)
Call:=CreateCallExpression(El);
AssignContext.Call:=Call;
Call.Expr:=CreateDotNameExpr(El,Result,TJSString(GetBIName(pbifnRecordAssign)));
Call.AddArg(AssignContext.RightSide);
AssignContext.RightSide:=nil;
Result:=Call;
if AssignContext.LeftResolved.LoTypeEl is TPasRecordType then
begin
// aRecord:=right -> aRecord.$assign(right)
Call:=CreateCallExpression(El);
AssignContext.Call:=Call;
Call.Expr:=CreateDotNameExpr(El,Result,TJSString(GetBIName(pbifnRecordAssign)));
Call.AddArg(AssignContext.RightSide);
AssignContext.RightSide:=nil;
Result:=Call;
end;
end;
end;
@ -7996,8 +7998,8 @@ begin
end;
end; // property redirect
if (AContext.Access=caAssign)
and aResolver.IsClassField(Decl) then
if aResolver.IsClassField(Decl)
and (AContext.Access in [caAssign,caByReference]) then
begin
// writing a class var -> aClass.VarName
PathExpr:=CreateReferencePathExpr(Decl.Parent,AContext);

View File

@ -11896,7 +11896,7 @@ begin
' class var vI: longint;',
' class var Sub: TObject;',
' constructor Create;',
' class function GetIt(Par: longint): tobject;',
' class function GetIt(var Par: longint): tobject;',
' end;',
'constructor tobject.create;',
'begin',
@ -11904,12 +11904,13 @@ begin
' Self.vi:=Self.vi+1;',
' inc(vi);',
'end;',
'class function tobject.getit(par: longint): tobject;',
'class function tobject.getit(var par: longint): tobject;',
'begin',
' vi:=vi+par;',
' Self.vi:=Self.vi+par;',
' vi:=vi+3;',
' Self.vi:=Self.vi+4;',
' inc(vi);',
' Result:=self.sub;',
' GetIt(vi);',
'end;',
'var Obj: tobject;',
'begin',
@ -11937,10 +11938,19 @@ begin
' };',
' this.GetIt = function(Par){',
' var Result = null;',
' $mod.TObject.vI = this.vI + Par;',
' $mod.TObject.vI = this.vI + Par;',
' $mod.TObject.vI = this.vI + 3;',
' $mod.TObject.vI = this.vI + 4;',
' $mod.TObject.vI += 1;',
' Result = this.Sub;',
' this.GetIt({',
' p: $mod.TObject,',
' get: function () {',
' return this.p.vI;',
' },',
' set: function (v) {',
' this.p.vI = v;',
' }',
' });',
' return Result;',
' };',
'});',