Skip to content

Commit

Permalink
Simplify type checks for nullable
Browse files Browse the repository at this point in the history
This was a hold over from earlier code when this arm was not protected by isMethodArg, causing it to need this solving complexity supported by op_Implicit conversions
  • Loading branch information
NinoFloris committed Aug 11, 2022
1 parent beca713 commit 5f8d5fc
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,8 @@ let rec AdjustRequiredTypeForTypeDirectedConversions (infoReader: InfoReader) ad
g.int32_ty, TypeDirectedConversionUsed.Yes(warn TypeDirectedConversion.BuiltIn), None

elif g.langVersion.SupportsFeature LanguageFeature.NullableOptionalInterop && isMethodArg && isNullableTy g reqdTy && not (isNullableTy g actualTy) then
let reqdTy2 =
if isTyparTy g reqdTy then
let tp = destTyparTy g reqdTy
match tp.Constraints |> List.choose (function TyparConstraint.CoercesTo (c, _) -> Some c | _ -> None) with
| [reqdTy2] when tp.Rigidity = TyparRigidity.Flexible -> reqdTy2
| _ -> reqdTy
else reqdTy

if not (isTyparTy g reqdTy2) &&
(not (TypeFeasiblySubsumesType 0 g infoReader.amap m reqdTy2 CanCoerce actualTy) ||
isTyparTy g actualTy && (let ftyvs = freeInType CollectAll reqdTy2 in ftyvs.FreeTypars.Contains(destTyparTy g actualTy))) then
actualTy, TypeDirectedConversionUsed.Yes(warn TypeDirectedConversion.BuiltIn), None

actualTy, TypeDirectedConversionUsed.Yes(warn TypeDirectedConversion.BuiltIn), Some (reqdTy, reqdTy2, ignore)
else
reqdTy, TypeDirectedConversionUsed.No, None
// Adhoc based on op_Implicit, perhaps returing a new equational type constraint to
// eliminate articifical constrained type variables.
elif g.langVersion.SupportsFeature LanguageFeature.AdditionalTypeDirectedConversions then
Expand Down

0 comments on commit 5f8d5fc

Please sign in to comment.