pastojs: fixed await() as aclass, issue 39028

This commit is contained in:
mattias 2022-02-04 14:48:05 +01:00
parent 9bf4f9e2ce
commit 664a96c584
3 changed files with 68 additions and 0 deletions

View File

@ -13502,8 +13502,13 @@ begin
begin
if (LeftResolved.IdentEl is TPasType)
or (not (rrfReadable in LeftResolved.Flags)) then
begin
{ $IFDEF VerbosePasResolver}
writeln('TPasResolver.ComputeBinaryExprRes as-operator: left=',GetResolverResultDbg(LeftResolved),' right=',GetResolverResultDbg(RightResolved));
{ $ENDIF}
RaiseIncompatibleTypeRes(20180204124711,nOperatorIsNotOverloadedAOpB,
[OpcodeStrings[Bin.OpCode]],LeftResolved,RightResolved,Bin);
end;
if RightResolved.IdentEl=nil then
RaiseXExpectedButYFound(20170216152630,'class',GetElementTypeName(RightResolved.LoTypeEl),Bin.right);
if not (RightResolved.IdentEl is TPasType) then

View File

@ -6232,6 +6232,7 @@ begin
// await(T;promise):T
end;
ComputeElement(Param,ResolvedEl,[]);
ResolvedEl.IdentEl:=nil;
Include(ResolvedEl.Flags,rrfReadable);
if Proc=nil then ;
end;

View File

@ -909,6 +909,7 @@ type
Procedure TestAsync_Inherited;
Procedure TestAsync_ClassInterface;
Procedure TestAsync_ClassInterface_AsyncMissmatchFail;
Procedure TestAWait_ClassAs;
// Library
Procedure TestLibrary_Empty;
@ -33996,6 +33997,67 @@ begin
ConvertProgram;
end;
procedure TTestModule.TestAWait_ClassAs;
begin
StartProgram(false);
Add([
'{$mode objfpc}',
'{$modeswitch externalclass}',
'type',
' TJSPromise = class external name ''Promise''',
' end;',
' TObject = class',
' function Run: TObject; async;',
' end;',
' TBird = class',
' function Fly: TBird; async;',
' end;',
'function TObject.Run: TObject; async;',
'begin',
'end;',
'function TBird.Fly: TBird;', // async modifier not needed in impl
'var o: TObject;',
'begin',
' o:=await(TObject,Run);',
' o:=await(TObject,Fly);',
' o:=await(TBird,Fly);',
' o:=await(TObject,inherited Run);',
' o:=await(TObject,inherited Run) as TBird;',
'end;',
'begin',
' ']);
ConvertProgram;
CheckSource('TestAWait_ClassAs',
LinesToStr([ // statements
'rtl.createClass(this, "TObject", null, function () {',
' this.$init = function () {',
' };',
' this.$final = function () {',
' };',
' this.Run = async function () {',
' var Result = null;',
' return Result;',
' };',
'});',
'rtl.createClass(this, "TBird", this.TObject, function () {',
' this.Fly = async function () {',
' var Result = null;',
' var o = null;',
' o = await this.Run();',
' o = await this.Fly();',
' o = await this.Fly();',
' o = await $mod.TObject.Run.call(this);',
' o = rtl.as(await $mod.TObject.Run.call(this), $mod.TBird);',
' return Result;',
' };',
'});',
'']),
LinesToStr([
'']));
CheckResolverUnexpectedHints();
end;
procedure TTestModule.TestLibrary_Empty;
begin
StartLibrary(false);