diff --git a/src/fsharp/ConstraintSolver.fs b/src/fsharp/ConstraintSolver.fs index dc811b33ebd..c1cb1daaef9 100644 --- a/src/fsharp/ConstraintSolver.fs +++ b/src/fsharp/ConstraintSolver.fs @@ -2604,7 +2604,7 @@ let CodegenWitnessThatTypSupportsTraitConstraint tcVal g amap m (traitInfo:Trait | Some sln -> match sln with | ILMethSln(origTy, extOpt, mref, minst) -> - let metadataTy = helpEnsureTypeHasMetadata g origTy + let metadataTy = convertToTypeWithMetadataIfPossible g origTy let tcref, _tinst = destAppTy g metadataTy let mdef = IL.resolveILMethodRef tcref.ILTyconRawMetadata mref let ilMethInfo = diff --git a/src/fsharp/InfoReader.fs b/src/fsharp/InfoReader.fs index baad78b4b1b..4f3eac2487d 100644 --- a/src/fsharp/InfoReader.fs +++ b/src/fsharp/InfoReader.fs @@ -71,12 +71,12 @@ let rec GetImmediateIntrinsicMethInfosOfTypeAux (optFilter,ad) g amap m origTy m // Tuple types also support the methods get_Item1-8, get_Rest from the compiled tuple type. // In this case convert to the .NET Tuple type that carries metadata and try again if isAnyTupleTy g metadataTy then - let betterMetadataTy = helpEnsureTypeHasMetadata g metadataTy + let betterMetadataTy = convertToTypeWithMetadataIfPossible g metadataTy GetImmediateIntrinsicMethInfosOfTypeAux (optFilter,ad) g amap m origTy betterMetadataTy // Function types support methods FSharpFunc<_,_>.FromConverter and friends from .NET metadata, // but not instance methods (you can't write "f.Invoke(x)", you have to write "f x") elif isFunTy g metadataTy then - let betterMetadataTy = helpEnsureTypeHasMetadata g metadataTy + let betterMetadataTy = convertToTypeWithMetadataIfPossible g metadataTy GetImmediateIntrinsicMethInfosOfTypeAux (optFilter,ad) g amap m origTy betterMetadataTy |> List.filter (fun minfo -> not minfo.IsInstance) else @@ -165,7 +165,7 @@ let rec GetImmediateIntrinsicPropInfosOfTypeAux (optFilter,ad) g amap m origTy m // Tuple types also support the properties Item1-8, Rest from the compiled tuple type // In this case convert to the .NET Tuple type that carries metadata and try again if isAnyTupleTy g metadataTy || isFunTy g metadataTy then - let betterMetadataTy = helpEnsureTypeHasMetadata g metadataTy + let betterMetadataTy = convertToTypeWithMetadataIfPossible g metadataTy GetImmediateIntrinsicPropInfosOfTypeAux (optFilter,ad) g amap m origTy betterMetadataTy else match tryDestAppTy g metadataTy with @@ -465,7 +465,7 @@ let rec GetIntrinsicConstructorInfosOfTypeAux (infoReader:InfoReader) m origTy m // Tuple types also support constructors. In this case convert to the .NET Tuple type that carries metadata and try again // Function types also support constructors. In this case convert to the FSharpFunc type that carries metadata and try again if isAnyTupleTy g metadataTy || isFunTy g metadataTy then - let betterMetadataTy = helpEnsureTypeHasMetadata g metadataTy + let betterMetadataTy = convertToTypeWithMetadataIfPossible g metadataTy GetIntrinsicConstructorInfosOfTypeAux infoReader m origTy betterMetadataTy else match tryDestAppTy g metadataTy with diff --git a/src/fsharp/NameResolution.fs b/src/fsharp/NameResolution.fs index ce0d34a1c2c..499d2cb7709 100644 --- a/src/fsharp/NameResolution.fs +++ b/src/fsharp/NameResolution.fs @@ -1889,7 +1889,7 @@ let private ResolveObjectConstructorPrim (ncenv:NameResolver) edenv resInfo m ad raze (Error(FSComp.SR.nrNoConstructorsAvailableForType(NicePrint.minimalStringOfType edenv typ),m)) else let ctorInfos = ctorInfos |> List.filter (IsMethInfoAccessible amap m ad) - let metadataTy = helpEnsureTypeHasMetadata g typ + let metadataTy = convertToTypeWithMetadataIfPossible g typ success (resInfo,Item.MakeCtorGroup ((tcrefOfAppTy g metadataTy).LogicalName, (defaultStructCtorInfo@ctorInfos))) /// Perform name resolution for an identifier which must resolve to be an object constructor. diff --git a/src/fsharp/TastOps.fs b/src/fsharp/TastOps.fs index 27f89a5e2fd..fe8f0dd49ca 100644 --- a/src/fsharp/TastOps.fs +++ b/src/fsharp/TastOps.fs @@ -795,7 +795,7 @@ let mkInstForAppTy g typ = let domainOfFunTy g ty = fst (destFunTy g ty) let rangeOfFunTy g ty = snd (destFunTy g ty) -let helpEnsureTypeHasMetadata g ty = +let convertToTypeWithMetadataIfPossible g ty = if isAnyTupleTy g ty then let (tupInfo, tupElemTys) = destAnyTupleTy g ty mkOuterCompiledTupleTy g (evalTupInfoIsStruct tupInfo) tupElemTys diff --git a/src/fsharp/TastOps.fsi b/src/fsharp/TastOps.fsi index 2b6ec4e6ec1..55e1086a0a8 100755 --- a/src/fsharp/TastOps.fsi +++ b/src/fsharp/TastOps.fsi @@ -252,7 +252,7 @@ val mkGetTupleItemN : TcGlobals -> range -> int -> ILType -> bool -> Expr -> TTy val evalTupInfoIsStruct : TupInfo -> bool /// If it is a tuple type, ensure it's outermost type is a .NET tuple type, otherwise leave unchanged -val helpEnsureTypeHasMetadata : TcGlobals -> TType -> TType +val convertToTypeWithMetadataIfPossible : TcGlobals -> TType -> TType //------------------------------------------------------------------------- diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index e20862db353..23e9508e29a 100755 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -4923,7 +4923,7 @@ and TcTypeAndRecover cenv newOk checkCxs occ env tpenv ty = TcTypeOrMeasureAndRecover (Some TyparKind.Type) cenv newOk checkCxs occ env tpenv ty and TcNestedTypeApplication cenv newOk checkCxs occ env tpenv mWholeTypeApp typ tyargs = - let typ = helpEnsureTypeHasMetadata cenv.g typ + let typ = convertToTypeWithMetadataIfPossible cenv.g typ if not (isAppTy cenv.g typ) then error(Error(FSComp.SR.tcTypeHasNoNestedTypes(), mWholeTypeApp)) match typ with | TType_app(tcref, tinst) -> @@ -13226,7 +13226,7 @@ module MutRecBindingChecking = // Phase2B: typecheck the argument to an 'inherits' call and build the new object expr for the inherit-call | Phase2AInherit (synBaseTy, arg, baseValOpt, m) -> let baseTy, tpenv = TcType cenv NoNewTypars CheckCxs ItemOccurence.Use envInstance tpenv synBaseTy - let baseTy = baseTy |> helpEnsureTypeHasMetadata cenv.g + let baseTy = baseTy |> convertToTypeWithMetadataIfPossible cenv.g let inheritsExpr, tpenv = TcNewExpr cenv envInstance tpenv baseTy (Some synBaseTy.Range) true arg m let envInstance = match baseValOpt with Some baseVal -> AddLocalVal cenv.tcSink scopem baseVal envInstance | None -> envInstance let envNonRec = match baseValOpt with Some baseVal -> AddLocalVal cenv.tcSink scopem baseVal envNonRec | None -> envNonRec diff --git a/src/fsharp/infos.fs b/src/fsharp/infos.fs index 192254a9d60..eb9e78ff617 100755 --- a/src/fsharp/infos.fs +++ b/src/fsharp/infos.fs @@ -670,7 +670,7 @@ type ILTypeInfo = member x.ToType = let (ILTypeInfo(_,ty,_,_)) = x in ty /// Get the compiled nominal type. In the case of tuple types, this is a .NET tuple type - member x.ToAppType = helpEnsureTypeHasMetadata x.TcGlobals x.ToType + member x.ToAppType = convertToTypeWithMetadataIfPossible x.TcGlobals x.ToType member x.TyconRefOfRawMetadata = tcrefOfAppTy x.TcGlobals x.ToAppType @@ -690,7 +690,7 @@ type ILTypeInfo = if isAnyTupleTy g ty then // When getting .NET metadata for the properties and methods // of an F# tuple type, use the compiled nominal type, which is a .NET tuple type - let metadataTy = helpEnsureTypeHasMetadata g ty + let metadataTy = convertToTypeWithMetadataIfPossible g ty assert (isILAppTy g metadataTy) let metadataTyconRef = tcrefOfAppTy g metadataTy let (TILObjectReprData(scoref, enc, tdef)) = metadataTyconRef.ILTyconInfo @@ -727,7 +727,7 @@ type ILMethInfo = member x.ApparentEnclosingType = match x with ILMethInfo(_,ty,_,_,_) -> ty /// Like ApparentEnclosingType but use the compiled nominal type if this is a method on a tuple type - member x.ApparentEnclosingAppType = helpEnsureTypeHasMetadata x.TcGlobals x.ApparentEnclosingType + member x.ApparentEnclosingAppType = convertToTypeWithMetadataIfPossible x.TcGlobals x.ApparentEnclosingType /// Get the declaring type associated with an extension member, if any. member x.ILExtensionMethodDeclaringTyconRef = match x with ILMethInfo(_,_,tcrefOpt,_,_) -> tcrefOpt @@ -897,9 +897,7 @@ type MethInfo = /// Get the enclosing type of the method info, using a nominal type for tuple types member x.ApparentEnclosingAppType = - match x with - | ILMeth(_,ilminfo,_) -> ilminfo.ApparentEnclosingAppType - | _ -> x.ApparentEnclosingType + convertToTypeWithMetadataIfPossible x.TcGlobals x.ApparentEnclosingType member x.ApparentEnclosingTyconRef = tcrefOfAppTy x.TcGlobals x.ApparentEnclosingAppType @@ -1005,7 +1003,8 @@ type MethInfo = member x.FormalMethodTypars = match x with | ILMeth(_,ilmeth,_) -> ilmeth.FormalMethodTypars - | FSMeth(g,typ,vref,_) -> + | FSMeth(g,_,vref,_) -> + let typ = x.ApparentEnclosingAppType let _,memberMethodTypars,_,_ = AnalyzeTypeOfMemberVal x.IsCSharpStyleExtensionMember g (typ,vref) memberMethodTypars | DefaultStructCtor _ -> [] @@ -1283,7 +1282,8 @@ type MethInfo = match x with | ILMeth(_g,ilminfo,_) -> ilminfo.GetCompiledReturnTy(amap, m, minst) - | FSMeth(g,typ,vref,_) -> + | FSMeth(g,_,vref,_) -> + let typ = x.ApparentEnclosingAppType let inst = GetInstantiationForMemberVal g x.IsCSharpStyleExtensionMember (typ,vref,minst) let _,_,retTy,_ = AnalyzeTypeOfMemberVal x.IsCSharpStyleExtensionMember g (typ,vref) retTy |> Option.map (instType inst) @@ -1320,8 +1320,9 @@ type MethInfo = member x.GetObjArgTypes (amap, m, minst) = match x with | ILMeth(_,ilminfo,_) -> ilminfo.GetObjArgTypes(amap, m, minst) - | FSMeth(g,typ,vref,_) -> + | FSMeth(g,_,vref,_) -> if x.IsInstance then + let typ = x.ApparentEnclosingAppType // The 'this' pointer of an extension member can depend on the minst if x.IsExtensionMember then let inst = GetInstantiationForMemberVal g x.IsCSharpStyleExtensionMember (typ,vref,minst) @@ -1521,7 +1522,8 @@ type MethInfo = match x with | ILMeth(_g,ilminfo,_) -> [ ilminfo.GetParamNamesAndTypes(amap,m,minst) ] - | FSMeth(g,typ,vref,_) -> + | FSMeth(g,_,vref,_) -> + let typ = x.ApparentEnclosingAppType let items = ParamNameAndType.FromMember x.IsCSharpStyleExtensionMember g vref let inst = GetInstantiationForMemberVal g x.IsCSharpStyleExtensionMember (typ,vref,minst) items |> ParamNameAndType.InstantiateCurried inst @@ -1561,7 +1563,8 @@ type MethInfo = if x.IsExtensionMember then [] else match x with - | FSMeth(g,typ,vref,_) -> + | FSMeth(g,_,vref,_) -> + let typ = x.ApparentEnclosingAppType let memberParentTypars,_,_,_ = AnalyzeTypeOfMemberVal false g (typ,vref) memberParentTypars | _ -> @@ -1790,7 +1793,7 @@ type ILPropInfo = member x.ApparentEnclosingType = match x with ILPropInfo(tinfo,_) -> tinfo.ToType /// Like ApparentEnclosingType but use the compiled nominal type if this is a method on a tuple type - member x.ApparentEnclosingAppType = helpEnsureTypeHasMetadata x.TcGlobals x.ApparentEnclosingType + member x.ApparentEnclosingAppType = convertToTypeWithMetadataIfPossible x.TcGlobals x.ApparentEnclosingType /// Get the raw Abstract IL metadata for the IL property member x.RawMetadata = match x with ILPropInfo(_,pd) -> pd @@ -2096,8 +2099,9 @@ type PropInfo = member x.GetPropertyType (amap,m) = match x with | ILProp ilpinfo -> ilpinfo.GetPropertyType (amap,m) - | FSProp (g,typ,Some vref,_) - | FSProp (g,typ,_,Some vref) -> + | FSProp (g,_,Some vref,_) + | FSProp (g,_,_,Some vref) -> + let typ = x.ApparentEnclosingAppType let inst = GetInstantiationForPropertyVal g (typ,vref) ReturnTypeOfPropertyVal g vref.Deref |> instType inst