diff --git a/compiler/packages/fcl-passrc/src/pasresolver.pp b/compiler/packages/fcl-passrc/src/pasresolver.pp index e792e37..b065aee 100644 --- a/compiler/packages/fcl-passrc/src/pasresolver.pp +++ b/compiler/packages/fcl-passrc/src/pasresolver.pp @@ -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 diff --git a/compiler/packages/fcl-passrc/tests/tcresolver.pas b/compiler/packages/fcl-passrc/tests/tcresolver.pas index b77a997..d4e9cbd 100644 --- a/compiler/packages/fcl-passrc/tests/tcresolver.pas +++ b/compiler/packages/fcl-passrc/tests/tcresolver.pas @@ -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; diff --git a/compiler/packages/pastojs/tests/tcmodules.pas b/compiler/packages/pastojs/tests/tcmodules.pas index f06951e..55c400a 100644 --- a/compiler/packages/pastojs/tests/tcmodules.pas +++ b/compiler/packages/pastojs/tests/tcmodules.pas @@ -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;