mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-09-13 10:39:06 +02:00
fcl-passrc: typecast nil to class, interface, dynarray
This commit is contained in:
parent
0687f40919
commit
689d85f7f7
@ -21092,7 +21092,9 @@ begin
|
||||
begin
|
||||
if IsBaseType(FromResolved.LoTypeEl,btPointer) then
|
||||
Result:=cExact; // untyped pointer to class instance
|
||||
end;
|
||||
end
|
||||
else if FromResolved.BaseType=btNil then
|
||||
Result:=cExact; // nil to class or interface
|
||||
end
|
||||
else if C=TPasClassOfType then
|
||||
begin
|
||||
@ -21113,7 +21115,9 @@ begin
|
||||
begin
|
||||
if IsBaseType(FromResolved.LoTypeEl,btPointer) then
|
||||
Result:=cExact; // untyped pointer to class-of
|
||||
end;
|
||||
end
|
||||
else if FromResolved.BaseType=btNil then
|
||||
Result:=cExact; // nil to class-of
|
||||
end
|
||||
else if C=TPasRecordType then
|
||||
begin
|
||||
@ -21144,7 +21148,12 @@ begin
|
||||
begin
|
||||
if IsDynArray(ToResolved.LoTypeEl)
|
||||
and IsBaseType(FromResolved.LoTypeEl,btPointer) then
|
||||
Result:=cExact; // untyped pointer to dynnamic array
|
||||
Result:=cExact; // untyped pointer to dynamic array
|
||||
end
|
||||
else if FromResolved.BaseType=btNil then
|
||||
begin
|
||||
if IsDynArray(ToResolved.LoTypeEl) then
|
||||
Result:=cExact; // nil to dynamic array
|
||||
end;
|
||||
end
|
||||
else if (C=TPasProcedureType) or (C=TPasFunctionType) then
|
||||
@ -21246,7 +21255,10 @@ begin
|
||||
else
|
||||
Result:=cCompatible;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else if FromResolved.BaseType=btNil then
|
||||
// typecast nil to procedure type
|
||||
Result:=cExact;
|
||||
end
|
||||
else if C=TPasPointerType then
|
||||
begin
|
||||
|
@ -7275,7 +7275,7 @@ begin
|
||||
Add('function GetIt: longint; begin end;');
|
||||
Add('var s: smallint;');
|
||||
Add('begin');
|
||||
Add(' s:=smallint(GetIt);');
|
||||
Add(' s:=smallint(GetIt);');
|
||||
ParseProgram;
|
||||
end;
|
||||
|
||||
@ -10053,6 +10053,7 @@ begin
|
||||
Add(' ProcA(TClassA({@o}o));');
|
||||
Add(' if TClassA({@o}o).id=3 then ;');
|
||||
Add(' if (o as TClassA).id=3 then ;');
|
||||
Add(' o:=TObject(nil);');
|
||||
ParseProgram;
|
||||
end;
|
||||
|
||||
|
@ -13111,6 +13111,7 @@ begin
|
||||
Add(' tcontrol(obj):=tcontrol(tcontrol(obj).getit());');
|
||||
Add(' tcontrol(obj):=tcontrol(tcontrol(obj).getit(1));');
|
||||
Add(' tcontrol(obj):=tcontrol(tcontrol(tcontrol(obj).getit).arr[2]);');
|
||||
Add(' obj:=tcontrol(nil);');
|
||||
ConvertProgram;
|
||||
CheckSource('TestClass_TypeCast',
|
||||
LinesToStr([ // statements
|
||||
@ -13149,6 +13150,7 @@ begin
|
||||
'$mod.Obj = $mod.Obj.GetIt(0);',
|
||||
'$mod.Obj = $mod.Obj.GetIt(1);',
|
||||
'$mod.Obj = $mod.Obj.GetIt(0).Arr[2];',
|
||||
'$mod.Obj = null;',
|
||||
'']));
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user