From a954b2077aa766ea82988ec952952ee8af8e858d Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 21 Jul 2023 16:01:07 +0200 Subject: [PATCH 1/9] Name resolution: don't create fake items for interfaces --- src/Compiler/Checking/CheckExpressions.fs | 61 ++++++++++--------- src/Compiler/Checking/NameResolution.fs | 41 +++++-------- src/Compiler/Checking/NameResolution.fsi | 3 - src/Compiler/Service/FSharpCheckerResults.fs | 9 +-- src/Compiler/Service/ItemKey.fs | 1 - .../Service/SemanticClassification.fs | 2 - .../Service/ServiceDeclarationLists.fs | 22 +------ src/Compiler/Symbols/SymbolHelpers.fs | 13 +--- src/Compiler/Symbols/Symbols.fs | 1 - 9 files changed, 53 insertions(+), 100 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 98138270658..b4cc9441de4 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -7011,31 +7011,34 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI TcRecordConstruction cenv objTy true env tpenv None objTy fldsList mWholeExpr else - let item = ForceRaise (ResolveObjectConstructor cenv.nameResolver env.DisplayEnv mObjTy ad objTy) + let ctorCall, baseIdOpt, tpenv = + if isInterfaceTy g objTy then + match argopt with + | None -> + BuildObjCtorCall g mWholeExpr, None, tpenv + | Some _ -> + error(Error(FSComp.SR.tcConstructorForInterfacesDoNotTakeArguments(), mNewExpr)) + else + let item = ForceRaise (ResolveObjectConstructor cenv.nameResolver env.DisplayEnv mObjTy ad objTy) - if isFSharpObjModelTy g objTy && GetCtorShapeCounter env = 1 then - error(Error(FSComp.SR.tcObjectsMustBeInitializedWithObjectExpression(), mNewExpr)) + if isFSharpObjModelTy g objTy && GetCtorShapeCounter env = 1 then + error(Error(FSComp.SR.tcObjectsMustBeInitializedWithObjectExpression(), mNewExpr)) - let ctorCall, baseIdOpt, tpenv = - match item, argopt with - | Item.CtorGroup(methodName, minfos), Some (arg, baseIdOpt) -> - let meths = minfos |> List.map (fun minfo -> minfo, None) - let afterResolution = ForNewConstructors cenv.tcSink env mObjTy methodName minfos - let ad = env.AccessRights - - let expr, tpenv = TcMethodApplicationThen cenv env (MustEqual objTy) None tpenv None [] mWholeExpr mObjTy methodName ad PossiblyMutates false meths afterResolution CtorValUsedAsSuperInit [arg] ExprAtomicFlag.Atomic None [] - // The 'base' value is always bound - let baseIdOpt = (match baseIdOpt with None -> Some(ident("base", mObjTy)) | Some id -> Some id) - expr, baseIdOpt, tpenv - | Item.FakeInterfaceCtor intfTy, None -> - UnifyTypes cenv env mWholeExpr objTy intfTy - let expr = BuildObjCtorCall g mWholeExpr - expr, None, tpenv - | Item.FakeInterfaceCtor _, Some _ -> - error(Error(FSComp.SR.tcConstructorForInterfacesDoNotTakeArguments(), mNewExpr)) - | Item.CtorGroup _, None -> - error(Error(FSComp.SR.tcConstructorRequiresArguments(), mNewExpr)) - | _ -> error(Error(FSComp.SR.tcNewRequiresObjectConstructor(), mNewExpr)) + match item, argopt with + | Item.CtorGroup(methodName, minfos), Some (arg, baseIdOpt) -> + let meths = minfos |> List.map (fun minfo -> minfo, None) + let afterResolution = ForNewConstructors cenv.tcSink env mObjTy methodName minfos + let ad = env.AccessRights + + let expr, tpenv = TcMethodApplicationThen cenv env (MustEqual objTy) None tpenv None [] mWholeExpr mObjTy methodName ad PossiblyMutates false meths afterResolution CtorValUsedAsSuperInit [arg] ExprAtomicFlag.Atomic None [] + // The 'base' value is always bound + let baseIdOpt = (match baseIdOpt with None -> Some(ident("base", mObjTy)) | Some id -> Some id) + expr, baseIdOpt, tpenv + + | Item.CtorGroup _, None -> + error(Error(FSComp.SR.tcConstructorRequiresArguments(), mNewExpr)) + + | _ -> error(Error(FSComp.SR.tcNewRequiresObjectConstructor(), mNewExpr)) let baseValOpt = MakeAndPublishBaseVal cenv env baseIdOpt objTy let env = Option.foldBack (AddLocalVal g cenv.tcSink mNewExpr) baseValOpt env @@ -8142,7 +8145,7 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) = (match item with | Item.DelegateCtor _ | Item.CtorGroup _ - | Item.FakeInterfaceCtor _ -> false + | Item.Types _ when delayed.IsEmpty -> false | _ -> true) -> let overallTy = match overallTyOpt with None -> MustEqual (NewInferenceType g) | Some t -> t let _, _ = TcItemThen cenv overallTy env tpenv res None delayed @@ -8374,9 +8377,6 @@ and TcItemThen (cenv: cenv) (overallTy: OverallTy) env tpenv (tinstEnclosing, it | Item.CtorGroup(nm, minfos) -> TcCtorItemThen cenv overallTy env item nm minfos tinstEnclosing tpenv mItem afterResolution delayed - | Item.FakeInterfaceCtor _ -> - error(Error(FSComp.SR.tcInvalidUseOfInterfaceType(), mItem)) - | Item.ImplicitOp(id, sln) -> TcImplicitOpItemThen cenv overallTy env id sln tpenv mItem delayed @@ -8614,7 +8614,10 @@ and TcTypeItemThen (cenv: cenv) overallTy env nm ty tpenv mItem tinstEnclosing d // In this case the type is not generic, and indeed we should never have returned Item.Types. // That's because ResolveTypeNamesToCtors should have been set at the original // call to ResolveLongIdentAsExprAndComputeRange - error(Error(FSComp.SR.tcInvalidUseOfTypeName(), mItem)) + if isInterfaceTy g ty then + error(Error(FSComp.SR.tcInvalidUseOfInterfaceType(), mItem)) + else + error(Error(FSComp.SR.tcInvalidUseOfTypeName(), mItem)) and TcMethodItemThen (cenv: cenv) overallTy env item methodName minfos tpenv mItem afterResolution staticTyOpt delayed = let ad = env.eAccessRights @@ -9305,7 +9308,7 @@ and TcLookupItemThen cenv overallTy env tpenv mObjExpr objExpr objExprTy delayed | Item.Trait traitInfo -> TcTraitItemThen cenv overallTy env (Some objExpr) traitInfo tpenv mItem delayed - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ -> error (Error (FSComp.SR.tcConstructorsCannotBeFirstClassValues(), mItem)) + | Item.DelegateCtor _ -> error (Error (FSComp.SR.tcConstructorsCannotBeFirstClassValues(), mItem)) // These items are not expected here - they can't be the result of a instance member dot-lookup "expr.Ident" | Item.ActivePatternResult _ diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 7b660d3d21d..9e39ff2b1e2 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -201,9 +201,6 @@ type Item = /// Represents the resolution of a name to a constructor | CtorGroup of string * MethInfo list - /// Represents the resolution of a name to the fake constructor simulated for an interface type. - | FakeInterfaceCtor of TType - /// Represents the resolution of a name to a delegate | DelegateCtor of TType @@ -276,8 +273,7 @@ type Item = | ValueSome tcref -> tcref.DisplayNameCore | _ -> nm |> DemangleGenericTypeName - | Item.CtorGroup(nm, _) -> nm |> DemangleGenericTypeName - | Item.FakeInterfaceCtor ty + |Item.CtorGroup(nm, _) -> nm |> DemangleGenericTypeName | Item.DelegateCtor ty -> match ty with | AbbrevOrAppTy tcref -> tcref.DisplayNameCore @@ -1786,8 +1782,7 @@ let (|EntityUse|_|) (item: Item) = | Item.UnqualifiedType (tcref :: _) -> Some tcref | Item.ExnCase tcref -> Some tcref | Item.Types(_, [AbbrevOrAppTy tcref]) - | Item.DelegateCtor(AbbrevOrAppTy tcref) - | Item.FakeInterfaceCtor(AbbrevOrAppTy tcref) -> Some tcref + | Item.DelegateCtor(AbbrevOrAppTy tcref) -> Some tcref | Item.CtorGroup(_, ctor :: _) -> match ctor.ApparentEnclosingType with | AbbrevOrAppTy tcref -> Some tcref @@ -2229,7 +2224,6 @@ let CheckAllTyparsInferrable amap m item = | Item.Trait _ | Item.CtorGroup _ - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ | Item.Types _ | Item.ModuleOrNamespaces _ @@ -2469,23 +2463,20 @@ let private ResolveObjectConstructorPrim (ncenv: NameResolver) edenv resInfo m a success (resInfo, Item.DelegateCtor ty) else let ctorInfos = GetIntrinsicConstructorInfosOfType ncenv.InfoReader m ty - if isNil ctorInfos && isInterfaceTy g ty then - success (resInfo, Item.FakeInterfaceCtor ty) + let defaultStructCtorInfo = + if (not (ctorInfos |> List.exists (fun x -> x.IsNullary)) && + isStructTy g ty && + not (isRecdTy g ty) && + not (isUnionTy g ty)) + then + [DefaultStructCtor(g, ty)] + else [] + if (isNil defaultStructCtorInfo && isNil ctorInfos) || (not (isAppTy g ty) && not (isAnyTupleTy g ty)) then + raze (Error(FSComp.SR.nrNoConstructorsAvailableForType(NicePrint.minimalStringOfType edenv ty), m)) else - let defaultStructCtorInfo = - if (not (ctorInfos |> List.exists (fun x -> x.IsNullary)) && - isStructTy g ty && - not (isRecdTy g ty) && - not (isUnionTy g ty)) - then - [DefaultStructCtor(g, ty)] - else [] - if (isNil defaultStructCtorInfo && isNil ctorInfos) || (not (isAppTy g ty) && not (isAnyTupleTy g ty)) then - raze (Error(FSComp.SR.nrNoConstructorsAvailableForType(NicePrint.minimalStringOfType edenv ty), m)) - else - let ctorInfos = ctorInfos |> List.filter (IsMethInfoAccessible amap m ad) - let metadataTy = convertToTypeWithMetadataIfPossible g ty - success (resInfo, Item.MakeCtorGroup ((tcrefOfAppTy g metadataTy).LogicalName, (defaultStructCtorInfo@ctorInfos))) + let ctorInfos = ctorInfos |> List.filter (IsMethInfoAccessible amap m ad) + let metadataTy = convertToTypeWithMetadataIfPossible g ty + success (resInfo, Item.MakeCtorGroup ((tcrefOfAppTy g metadataTy).LogicalName, (defaultStructCtorInfo@ctorInfos))) /// Perform name resolution for an identifier which must resolve to be an object constructor. let ResolveObjectConstructor (ncenv: NameResolver) denv m ad ty = @@ -4500,7 +4491,6 @@ let InfosForTyconConstructors (ncenv: NameResolver) m ad (tcref: TyconRef) = match ResolveObjectConstructor ncenv (DisplayEnv.Empty g) m ad ty with | Result item -> match item with - | Item.FakeInterfaceCtor _ -> None | Item.CtorGroup(nm, ctorInfos) -> let ctors = ctorInfos @@ -5301,7 +5291,6 @@ let rec GetCompletionForItem (ncenv: NameResolver) (nenv: NameResolutionEnv) m a | _ -> () | Item.DelegateCtor _ - | Item.FakeInterfaceCtor _ | Item.CtorGroup _ | Item.UnqualifiedType _ -> for tcref in nenv.TyconsByDemangledNameAndArity(OpenQualified).Values do diff --git a/src/Compiler/Checking/NameResolution.fsi b/src/Compiler/Checking/NameResolution.fsi index 3ba5113b004..4f64679dcd9 100755 --- a/src/Compiler/Checking/NameResolution.fsi +++ b/src/Compiler/Checking/NameResolution.fsi @@ -94,9 +94,6 @@ type Item = /// Represents the resolution of a name to a constructor | CtorGroup of string * MethInfo list - /// Represents the resolution of a name to the fake constructor simulated for an interface type. - | FakeInterfaceCtor of TType - /// Represents the resolution of a name to a delegate | DelegateCtor of TType diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 2391f26655f..c80a29417d3 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -891,7 +891,6 @@ type internal TypeCheckInfo let CompletionItem (ty: TyconRef voption) (assemblySymbol: AssemblySymbol voption) (item: ItemWithInst) = let kind = match item.Item with - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ | Item.CtorGroup _ -> CompletionItemKind.Method false | Item.MethodGroup(_, minfos, _) -> @@ -1802,8 +1801,7 @@ type internal TypeCheckInfo match d.Item with | Item.Types(_, AbbrevOrAppTy tcref :: _) -> 1 + tcref.TyparsNoRange.Length // Put delegate ctors after types, sorted by #typars. RemoveDuplicateItems will remove FakeInterfaceCtor and DelegateCtor if an earlier type is also reported with this name - | Item.FakeInterfaceCtor(AbbrevOrAppTy tcref) - | Item.DelegateCtor(AbbrevOrAppTy tcref) -> 1000 + tcref.TyparsNoRange.Length + | Item.DelegateCtor (AbbrevOrAppTy tcref) -> 1000 + tcref.TyparsNoRange.Length // Put type ctors after types, sorted by #typars. RemoveDuplicateItems will remove DefaultStructCtors if a type is also reported with this name | Item.CtorGroup(_, cinfo :: _) -> 1000 + 10 * cinfo.DeclaringTyconRef.TyparsNoRange.Length | _ -> 0 @@ -1822,9 +1820,8 @@ type internal TypeCheckInfo | Item.Types(_, AbbrevOrAppTy tcref :: _) | Item.ExnCase tcref -> tcref.LogicalName | Item.UnqualifiedType(tcref :: _) - | Item.FakeInterfaceCtor(AbbrevOrAppTy tcref) - | Item.DelegateCtor(AbbrevOrAppTy tcref) -> tcref.CompiledName - | Item.CtorGroup(_, cinfo :: _) -> cinfo.ApparentEnclosingTyconRef.CompiledName + | Item.DelegateCtor (AbbrevOrAppTy tcref) -> tcref.CompiledName + | Item.CtorGroup (_, cinfo :: _) -> cinfo.ApparentEnclosingTyconRef.CompiledName | _ -> d.Item.DisplayName) // Filter out operators (and list) diff --git a/src/Compiler/Service/ItemKey.fs b/src/Compiler/Service/ItemKey.fs index daf6a28f544..7a904a235ed 100644 --- a/src/Compiler/Service/ItemKey.fs +++ b/src/Compiler/Service/ItemKey.fs @@ -562,7 +562,6 @@ and [] ItemKeyStoreBuilder(tcGlobals: TcGlobals) = // We should consider writing ItemKey for each of these | Item.OtherName _ -> () - | Item.FakeInterfaceCtor _ -> () | Item.CustomOperation _ -> () | Item.CustomBuilder _ -> () | Item.ImplicitOp _ -> () diff --git a/src/Compiler/Service/SemanticClassification.fs b/src/Compiler/Service/SemanticClassification.fs index 75516028fdf..6ebbb3c8ae0 100644 --- a/src/Compiler/Service/SemanticClassification.fs +++ b/src/Compiler/Service/SemanticClassification.fs @@ -287,8 +287,6 @@ module TcResolutionsExtensions = | Item.DelegateCtor _, _, m -> add m SemanticClassificationType.ConstructorForReferenceType - | Item.FakeInterfaceCtor _, _, m -> add m SemanticClassificationType.ConstructorForReferenceType - | Item.MethodGroup(_, minfos, _), _, m -> match minfos with | [] -> add m SemanticClassificationType.Method diff --git a/src/Compiler/Service/ServiceDeclarationLists.fs b/src/Compiler/Service/ServiceDeclarationLists.fs index 1b955ead042..14b506bff86 100644 --- a/src/Compiler/Service/ServiceDeclarationLists.fs +++ b/src/Compiler/Service/ServiceDeclarationLists.fs @@ -358,19 +358,7 @@ module DeclarationListHelpers = | Item.CtorGroup(_, minfos) | Item.MethodGroup(_, minfos, _) -> FormatOverloadsToList infoReader m denv item minfos symbol width - - // The 'fake' zero-argument constructors of .NET interfaces. - // This ideally should never appear in intellisense, but we do get here in repros like: - // type IFoo = abstract F : int - // type II = IFoo // remove 'type II = ' and quickly hover over IFoo before it gets squiggled for 'invalid use of interface type' - // and in that case we'll just show the interface type name. - | Item.FakeInterfaceCtor ty -> - let ty, _ = PrettyTypes.PrettifyType g ty - let layout = NicePrint.layoutTyconRef denv (tcrefOfAppTy g ty) - let layout = PrintUtilities.squashToWidth width layout - let layout = toArray layout - ToolTipElement.Single(layout, xml, ?symbol = symbol) - + // The 'fake' representation of constructors of .NET delegate types | Item.DelegateCtor delTy -> let delTy, _cxs = PrettyTypes.PrettifyType g delTy @@ -848,10 +836,6 @@ module internal DescriptionListsImpl = let _prettyTyparInst, prettyRetTyL = NicePrint.prettyLayoutOfUncurriedSig denv item.TyparInstantiation [] retTy [], prettyRetTyL // no parameter data available for binary operators like 'zip', 'join' and 'groupJoin' since they use bespoke syntax - | Item.FakeInterfaceCtor ty -> - let _prettyTyparInst, prettyRetTyL = NicePrint.prettyLayoutOfUncurriedSig denv item.TyparInstantiation [] ty - [], prettyRetTyL - | Item.DelegateCtor delTy -> let (SigOfFunctionForDelegate(_, _, _, delFuncTy)) = GetSigOfFunctionForDelegate infoReader delTy m AccessibleFromSomewhere @@ -940,7 +924,6 @@ module internal DescriptionListsImpl = | Item.Property _ -> FSharpGlyph.Property | Item.CtorGroup _ | Item.DelegateCtor _ - | Item.FakeInterfaceCtor _ | Item.CustomOperation _ -> FSharpGlyph.Method | Item.MethodGroup (_, minfos, _) when minfos |> List.forall (fun minfo -> minfo.IsExtensionMember) -> FSharpGlyph.ExtensionMethod | Item.MethodGroup _ -> FSharpGlyph.Method @@ -986,7 +969,6 @@ module internal DescriptionListsImpl = | Item.CtorGroup(nm, cinfos) -> List.map (fun minfo -> Item.CtorGroup(nm, [minfo])) cinfos | Item.Trait traitInfo -> if traitInfo.GetLogicalArgumentTypes(g).IsEmpty then [] else [item] - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ -> [item] | Item.NewDef _ | Item.ILField _ -> [] @@ -1107,9 +1089,9 @@ type DeclarationListInfo(declarations: DeclarationListItem[], isForType: bool, i items |> List.map (fun x -> match x.Item with + | Item.Types (_, TType_app(tcref, _, _) :: _) when isInterfaceTyconRef tcref -> { x with MinorPriority = 1000 + tcref.TyparsNoRange.Length } | Item.Types (_, TType_app(tcref, _, _) :: _) -> { x with MinorPriority = 1 + tcref.TyparsNoRange.Length } // Put delegate ctors after types, sorted by #typars. RemoveDuplicateItems will remove FakeInterfaceCtor and DelegateCtor if an earlier type is also reported with this name - | Item.FakeInterfaceCtor (TType_app(tcref, _, _)) | Item.DelegateCtor (TType_app(tcref, _, _)) -> { x with MinorPriority = 1000 + tcref.TyparsNoRange.Length } // Put type ctors after types, sorted by #typars. RemoveDuplicateItems will remove DefaultStructCtors if a type is also reported with this name | Item.CtorGroup (_, cinfo :: _) -> { x with MinorPriority = 1000 + 10 * cinfo.DeclaringTyconRef.TyparsNoRange.Length } diff --git a/src/Compiler/Symbols/SymbolHelpers.fs b/src/Compiler/Symbols/SymbolHelpers.fs index fda64a95282..3c669d7a64c 100644 --- a/src/Compiler/Symbols/SymbolHelpers.fs +++ b/src/Compiler/Symbols/SymbolHelpers.fs @@ -118,8 +118,7 @@ module internal SymbolHelpers = | Item.ImplicitOp (_, {contents = Some(TraitConstraintSln.FSMethSln(vref=vref))}) -> Some vref.Range | Item.ImplicitOp _ -> None | Item.UnqualifiedType tcrefs -> tcrefs |> List.tryPick (rangeOfEntityRef preferFlag >> Some) - | Item.DelegateCtor ty - | Item.FakeInterfaceCtor ty -> ty |> tryNiceEntityRefOfTyOption |> Option.map (rangeOfEntityRef preferFlag) + | Item.DelegateCtor ty -> ty |> tryNiceEntityRefOfTyOption |> Option.map (rangeOfEntityRef preferFlag) | Item.NewDef _ -> None // Provided type definitions do not have a useful F# CCU for the purposes of goto-definition. @@ -190,7 +189,6 @@ module internal SymbolHelpers = | Item.Types(_, tys) -> tys |> List.tryPick (tryNiceEntityRefOfTyOption >> Option.bind computeCcuOfTyconRef) - | Item.FakeInterfaceCtor(ty) | Item.DelegateCtor(ty) -> ty |> tryNiceEntityRefOfTyOption |> Option.bind computeCcuOfTyconRef @@ -283,7 +281,6 @@ module internal SymbolHelpers = | Item.ILField finfo -> mkXmlComment (GetXmlDocSigOfILFieldInfo infoReader m finfo) - | Item.FakeInterfaceCtor ty | Item.DelegateCtor ty | Item.Types(_, ty :: _) -> match ty with @@ -363,7 +360,6 @@ module internal SymbolHelpers = match item with | Item.DelegateCtor ty | Item.CtorGroup(_, [DefaultStructCtor(_, ty)]) - | Item.FakeInterfaceCtor ty | Item.Types(_, [ty]) -> Some ty | _ -> None @@ -398,7 +394,6 @@ module internal SymbolHelpers = | Item.ActivePatternResult _ | Item.AnonRecdField _ | Item.OtherName _ - | Item.FakeInterfaceCtor _ | Item.ImplicitOp _ | Item.NewDef _ | Item.UnionCaseField _ @@ -504,7 +499,6 @@ module internal SymbolHelpers = | Item.ActivePatternResult _ | Item.AnonRecdField _ | Item.OtherName _ - | Item.FakeInterfaceCtor _ | Item.ImplicitOp _ | Item.NewDef _ | Item.UnionCaseField _ @@ -571,7 +565,6 @@ module internal SymbolHelpers = | Item.MethodGroup(_, _, Some minfo) -> buildString (fun os -> NicePrint.outputTyconRef denv os minfo.DeclaringTyconRef; bprintf os ".%s" minfo.DisplayName) | Item.MethodGroup(_, minfo :: _, _) -> buildString (fun os -> NicePrint.outputTyconRef denv os minfo.DeclaringTyconRef; bprintf os ".%s" minfo.DisplayName) | Item.UnqualifiedType (tcref :: _) -> buildString (fun os -> NicePrint.outputTyconRef denv os tcref) - | Item.FakeInterfaceCtor ty | Item.DelegateCtor ty | Item.Types(_, ty :: _) -> match tryTcrefOfAppTy g ty with @@ -716,7 +709,6 @@ module internal SymbolHelpers = | Item.ActivePatternResult _ | Item.NewDef _ | Item.ILField _ - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ -> //| _ -> GetXmlCommentForItemAux None infoReader m item @@ -848,7 +840,6 @@ module internal SymbolHelpers = #endif | Item.Types(_, AppTy g (tcref, _) :: _) | Item.DelegateCtor(AppTy g (tcref, _)) - | Item.FakeInterfaceCtor(AppTy g (tcref, _)) | Item.UnqualifiedType (tcref :: _) | Item.ExnCase tcref -> // strip off any abbreviation @@ -859,7 +850,6 @@ module internal SymbolHelpers = // Pathological cases of the above | Item.Types _ | Item.DelegateCtor _ - | Item.FakeInterfaceCtor _ | Item.UnqualifiedType [] -> None @@ -958,7 +948,6 @@ module internal SymbolHelpers = minfos |> List.map (fun minfo -> { Item = Item.MethodGroup(nm, [minfo], orig); TyparInstantiation = item.TyparInstantiation }) | Item.CtorGroup(nm, cinfos) -> cinfos |> List.map (fun minfo -> { Item = Item.CtorGroup(nm, [minfo]); TyparInstantiation = item.TyparInstantiation }) - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ -> [item] | Item.NewDef _ | Item.ILField _ -> [] diff --git a/src/Compiler/Symbols/Symbols.fs b/src/Compiler/Symbols/Symbols.fs index e405ded53e5..5caf1bc1245 100644 --- a/src/Compiler/Symbols/Symbols.fs +++ b/src/Compiler/Symbols/Symbols.fs @@ -331,7 +331,6 @@ type FSharpSymbol(cenv: SymbolEnv, item: unit -> Item, access: FSharpSymbol -> C // TODO: the following don't currently return any interesting subtype | Item.ImplicitOp _ | Item.ILField _ - | Item.FakeInterfaceCtor _ | Item.NewDef _ -> dflt() // These cases cover unreachable cases | Item.CustomOperation (_, _, None) From 089cde3b02504978206d306b3eb70dc1844fba6e Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 21 Jul 2023 16:57:34 +0200 Subject: [PATCH 2/9] More experiments --- src/Compiler/Checking/NameResolution.fs | 100 ++++++++++++++---------- 1 file changed, 60 insertions(+), 40 deletions(-) diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 9e39ff2b1e2..5f13c7e0ac6 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -2463,20 +2463,24 @@ let private ResolveObjectConstructorPrim (ncenv: NameResolver) edenv resInfo m a success (resInfo, Item.DelegateCtor ty) else let ctorInfos = GetIntrinsicConstructorInfosOfType ncenv.InfoReader m ty - let defaultStructCtorInfo = - if (not (ctorInfos |> List.exists (fun x -> x.IsNullary)) && - isStructTy g ty && - not (isRecdTy g ty) && - not (isUnionTy g ty)) - then - [DefaultStructCtor(g, ty)] - else [] - if (isNil defaultStructCtorInfo && isNil ctorInfos) || (not (isAppTy g ty) && not (isAnyTupleTy g ty)) then - raze (Error(FSComp.SR.nrNoConstructorsAvailableForType(NicePrint.minimalStringOfType edenv ty), m)) + if isNil ctorInfos && isInterfaceTy g ty then + let tcref = tcrefOfAppTy g ty + success (resInfo, Item.Types(tcref.DisplayName, [ty])) else - let ctorInfos = ctorInfos |> List.filter (IsMethInfoAccessible amap m ad) - let metadataTy = convertToTypeWithMetadataIfPossible g ty - success (resInfo, Item.MakeCtorGroup ((tcrefOfAppTy g metadataTy).LogicalName, (defaultStructCtorInfo@ctorInfos))) + let defaultStructCtorInfo = + if (not (ctorInfos |> List.exists (fun x -> x.IsNullary)) && + isStructTy g ty && + not (isRecdTy g ty) && + not (isUnionTy g ty)) + then + [DefaultStructCtor(g, ty)] + else [] + if (isNil defaultStructCtorInfo && isNil ctorInfos) || (not (isAppTy g ty) && not (isAnyTupleTy g ty)) then + raze (Error(FSComp.SR.nrNoConstructorsAvailableForType(NicePrint.minimalStringOfType edenv ty), m)) + else + let ctorInfos = ctorInfos |> List.filter (IsMethInfoAccessible amap m ad) + let metadataTy = convertToTypeWithMetadataIfPossible g ty + success (resInfo, Item.MakeCtorGroup ((tcrefOfAppTy g metadataTy).LogicalName, (defaultStructCtorInfo@ctorInfos))) /// Perform name resolution for an identifier which must resolve to be an object constructor. let ResolveObjectConstructor (ncenv: NameResolver) denv m ad ty = @@ -3061,33 +3065,49 @@ let rec ResolveExprLongIdentPrim sink (ncenv: NameResolver) first fullyQualified match AtMostOneResult m innerSearch with | Result _ as res -> res | _ -> - let failingCase = - match typeError with - | Some e -> raze e - | _ -> - let suggestNamesAndTypes (addToBuffer: string -> unit) = - for e in nenv.eUnqualifiedItems do - if canSuggestThisItem e.Value then - addToBuffer e.Value.DisplayName - - for e in nenv.TyconsByDemangledNameAndArity fullyQualified do - if IsEntityAccessible ncenv.amap m ad e.Value then - addToBuffer e.Value.DisplayName - - for kv in nenv.ModulesAndNamespaces fullyQualified do - for modref in kv.Value do - if IsEntityAccessible ncenv.amap m ad modref then - addToBuffer modref.DisplayName - - // check if the user forgot to use qualified access - for e in nenv.eTyconsByDemangledNameAndArity do - let hasRequireQualifiedAccessAttribute = HasFSharpAttribute ncenv.g ncenv.g.attrib_RequireQualifiedAccessAttribute e.Value.Attribs - if hasRequireQualifiedAccessAttribute then - if e.Value.IsUnionTycon && e.Value.UnionCasesArray |> Array.exists (fun c -> c.LogicalName = id.idText) then - addToBuffer (e.Value.DisplayName + "." + id.idText) - - raze (UndefinedName(0, FSComp.SR.undefinedNameValueOfConstructor, id, suggestNamesAndTypes)) - failingCase + + match typeError with + | Some e -> raze e + | _ -> + + let tyconSearch () = + let tcrefs = LookupTypeNameInEnvNoArity fullyQualified id.idText nenv + if isNil tcrefs then NoResultsOrUsefulErrors else + + let tcrefs = ResolveUnqualifiedTyconRefs nenv tcrefs + let typeNameResInfo = TypeNameResolutionInfo.ResolveToTypeRefs typeNameResInfo.StaticArgsInfo + CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities (tcrefs, typeNameResInfo, PermitDirectReferenceToGeneratedType.No, unionRanges m id.idRange) + |> CollectResults success + + match tyconSearch () with + | Result ((resInfo, tcref) :: _) -> + let item = Item.Types(id.idText, [ generalizedTyconRef ncenv.g tcref ]) + success (resInfo, item) + | _ -> + + let suggestNamesAndTypes (addToBuffer: string -> unit) = + for e in nenv.eUnqualifiedItems do + if canSuggestThisItem e.Value then + addToBuffer e.Value.DisplayName + + for e in nenv.TyconsByDemangledNameAndArity fullyQualified do + if IsEntityAccessible ncenv.amap m ad e.Value then + addToBuffer e.Value.DisplayName + + for kv in nenv.ModulesAndNamespaces fullyQualified do + for modref in kv.Value do + if IsEntityAccessible ncenv.amap m ad modref then + addToBuffer modref.DisplayName + + // check if the user forgot to use qualified access + for e in nenv.eTyconsByDemangledNameAndArity do + let hasRequireQualifiedAccessAttribute = HasFSharpAttribute ncenv.g ncenv.g.attrib_RequireQualifiedAccessAttribute e.Value.Attribs + if hasRequireQualifiedAccessAttribute then + if e.Value.IsUnionTycon && e.Value.UnionCasesArray |> Array.exists (fun c -> c.LogicalName = id.idText) then + addToBuffer (e.Value.DisplayName + "." + id.idText) + + raze (UndefinedName(0, FSComp.SR.undefinedNameValueOfConstructor, id, suggestNamesAndTypes)) + match res with | Exception e -> raze e | Result (resInfo, item) -> From fcac93691582079dcb2a24bb6df4ade965ca4017 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 21 Jul 2023 18:06:09 +0200 Subject: [PATCH 3/9] Tweak nameof --- src/Compiler/Checking/CheckExpressions.fs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index b4cc9441de4..cf1b9bce32a 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -8144,8 +8144,11 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) = when (match item with | Item.DelegateCtor _ - | Item.CtorGroup _ - | Item.Types _ when delayed.IsEmpty -> false + | Item.CtorGroup _ -> false + | Item.Types _ when delayed.IsEmpty -> + match delayed with + | [] | [DelayedTypeApp _] -> false + | _ -> true | _ -> true) -> let overallTy = match overallTyOpt with None -> MustEqual (NewInferenceType g) | Some t -> t let _, _ = TcItemThen cenv overallTy env tpenv res None delayed From 786a84da59b553e496a382ef2421bff51fa8d13b Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 21 Jul 2023 18:33:53 +0200 Subject: [PATCH 4/9] Update baselines --- tests/fsharp/typecheck/sigs/neg06.bsl | 16 ++++++++-------- .../StructTypes/E_InvalidRecursiveGeneric01.fs | 2 +- .../StructTypes/E_InvalidRecursiveGeneric02.fs | 2 +- .../StructTypes/E_StructConstruction03.fs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/fsharp/typecheck/sigs/neg06.bsl b/tests/fsharp/typecheck/sigs/neg06.bsl index cc7fc113cfc..54b3c5d84e5 100644 --- a/tests/fsharp/typecheck/sigs/neg06.bsl +++ b/tests/fsharp/typecheck/sigs/neg06.bsl @@ -94,27 +94,27 @@ neg06.fs(128,53,128,61): typecheck error FS0043: A type parameter is missing a c neg06.fs(141,10,141,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(148,13,148,21): typecheck error FS0039: The value or constructor 'BadType1' is not defined. +neg06.fs(148,13,148,21): typecheck error FS0800: Invalid use of a type name neg06.fs(150,10,150,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(157,13,157,21): typecheck error FS0039: The value or constructor 'BadType2' is not defined. +neg06.fs(157,13,157,21): typecheck error FS0800: Invalid use of a type name neg06.fs(159,10,159,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(166,13,166,21): typecheck error FS0039: The value or constructor 'BadType3' is not defined. +neg06.fs(166,13,166,21): typecheck error FS0800: Invalid use of a type name neg06.fs(195,10,195,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(203,13,203,21): typecheck error FS0039: The value or constructor 'BadType1' is not defined. +neg06.fs(203,13,203,21): typecheck error FS0800: Invalid use of a type name neg06.fs(205,10,205,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(213,13,213,21): typecheck error FS0039: The value or constructor 'BadType2' is not defined. +neg06.fs(213,13,213,21): typecheck error FS0800: Invalid use of a type name neg06.fs(215,10,215,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(223,13,223,21): typecheck error FS0039: The value or constructor 'BadType3' is not defined. +neg06.fs(223,13,223,21): typecheck error FS0800: Invalid use of a type name neg06.fs(300,10,300,12): typecheck error FS0009: Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'. @@ -130,11 +130,11 @@ neg06.fs(320,10,320,12): typecheck error FS0937: Only structs and classes withou neg06.fs(326,10,326,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(335,13,335,21): typecheck error FS0039: The value or constructor 'BadType4' is not defined. +neg06.fs(335,13,335,21): typecheck error FS0800: Invalid use of a type name neg06.fs(340,10,340,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation -neg06.fs(350,13,350,21): typecheck error FS0039: The value or constructor 'BadType4' is not defined. +neg06.fs(350,13,350,21): typecheck error FS0800: Invalid use of a type name neg06.fs(375,9,375,10): typecheck error FS1197: The parameter 'x' was inferred to have byref type. Parameters of byref type must be given an explicit type annotation, e.g. 'x1: byref'. When used, a byref parameter is implicitly dereferenced. diff --git a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric01.fs b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric01.fs index 2d426f6244f..9324d3e4902 100644 --- a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric01.fs +++ b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric01.fs @@ -3,7 +3,7 @@ // Regression for FSB 3417 //This type definition involves an immediate cyclic reference through a struct field or inheritance relation -//The value or constructor 'BadType4' is not defined +//Invalid use of a type name type BadType4 = struct diff --git a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric02.fs b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric02.fs index 21854ced87a..f90ab777f41 100644 --- a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric02.fs +++ b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_InvalidRecursiveGeneric02.fs @@ -3,7 +3,7 @@ // Regression for FSB 3417 //This type definition involves an immediate cyclic reference through a struct field or inheritance relation -//The value or constructor 'BadType4' is not defined +//Invalid use of a type name type BadType4 = struct diff --git a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_StructConstruction03.fs b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_StructConstruction03.fs index de295146093..0ee07b3415e 100644 --- a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_StructConstruction03.fs +++ b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/StructTypes/E_StructConstruction03.fs @@ -2,8 +2,8 @@ // Regression test for FSHARP1.0:3143 //This type definition involves an immediate cyclic reference through a struct field or inheritance relation$ //This declaration element is not permitted in an augmentation$ -//The value or constructor 'S' is not defined -//The value or constructor 'S' is not defined +//Invalid use of a type name +//Invalid use of a type name type S(x:S) = struct end From 89bb97736266657d397de6c0a46b41023c37a529 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Tue, 25 Jul 2023 13:25:28 +0200 Subject: [PATCH 5/9] Record special occurrence kind --- src/Compiler/Checking/NameResolution.fs | 14 ++++++++++++++ src/Compiler/Checking/NameResolution.fsi | 1 + src/Compiler/Service/FSharpCheckerResults.fs | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 5f13c7e0ac6..f6a123d8f7c 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -1709,6 +1709,7 @@ type ItemOccurence = | RelatedText /// This is a usage of a module or namespace name in open statement | Open + | WrongUse type FormatStringCheckContext = { SourceText: ISourceText @@ -4008,6 +4009,14 @@ let NeedsWorkAfterResolution namedItem = | Item.ActivePatternCase apref -> not (List.isEmpty apref.ActivePatternVal.Typars) | _ -> false +let isWrongItemInExpr item = + match item with + | Item.Types _ -> true + | _ -> false + // | Item.TypeVar(s, typar) -> failwith "todo" + // | Item.ModuleOrNamespaces entityRefs -> failwith "todo" + // | Item.UnqualifiedType entityRefs -> failwith "todo" + /// Specifies additional work to do after an item has been processed further in type checking. [] type AfterResolution = @@ -4070,6 +4079,11 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso | Some _ -> if NeedsWorkAfterResolution item then AfterResolution.RecordResolution(None, (fun tpinst -> callSink(item, tpinst)), callSinkWithSpecificOverload, (fun () -> callSink (item, emptyTyparInst))) + + elif isWrongItemInExpr item then + CallNameResolutionSink sink (itemRange, nenv, item, emptyTyparInst, ItemOccurence.WrongUse, ad) + AfterResolution.DoNothing + else callSink (item, emptyTyparInst) AfterResolution.DoNothing diff --git a/src/Compiler/Checking/NameResolution.fsi b/src/Compiler/Checking/NameResolution.fsi index 4f64679dcd9..c466961bfc7 100755 --- a/src/Compiler/Checking/NameResolution.fsi +++ b/src/Compiler/Checking/NameResolution.fsi @@ -382,6 +382,7 @@ type internal ItemOccurence = | Implemented | RelatedText | Open + | WrongUse /// Check for equality, up to signature matching val ItemsAreEffectivelyEqual: TcGlobals -> Item -> Item -> bool diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index c80a29417d3..dfd8d26ccb3 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -483,6 +483,8 @@ type internal TypeCheckInfo // // If we're looking for members using a residue, we'd expect only // a single item (pick the first one) and we need the residue (which may be "") + | CNR (_, ItemOccurence.WrongUse, _, _, _, _) :: _, _ -> NameResResult.Empty + | CNR(Item.Types(_, ty :: _), _, denv, nenv, ad, m) :: _, Some _ -> let targets = ResolveCompletionTargets.All(ConstraintSolver.IsApplicableMethApprox g amap m) From 2f2e8441e20f981c80d1fbe566b87b0f1a93bf02 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Sun, 10 Dec 2023 09:33:43 +0100 Subject: [PATCH 6/9] Add tests --- tests/service/Symbols.fs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index c52865d8804..acbc02f6c98 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -301,6 +301,32 @@ type E = Ns1.Ns2.T | _ -> Assert.Fail (sprintf "Couldn't get entity: %s" symbolName)) + [] + let ``Interface 01`` () = + let _, checkResults = getParseAndCheckResults """ +open System + +IDisposable +""" + findSymbolUseByName "IDisposable" checkResults |> ignore + + [] + let ``Interface 02`` () = + let _, checkResults = getParseAndCheckResults """ +System.IDisposable +""" + findSymbolUseByName "IDisposable" checkResults |> ignore + + [] + let ``Interface 03`` () = + let _, checkResults = getParseAndCheckResults """ +open System + +{ new IDisposable with } +""" + findSymbolUseByName "IDisposable" checkResults |> ignore + + [] let ``FSharpType.Format can use prefix representations`` () = let _, checkResults = getParseAndCheckResults """ From 79ccf5fdd0ececd77dfa2cfa1a2bfc9dfd861cc3 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Mon, 11 Dec 2023 12:35:35 +0100 Subject: [PATCH 7/9] Fantomas --- src/Compiler/Service/FSharpCheckerResults.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index dfd8d26ccb3..762a18c410b 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -483,7 +483,7 @@ type internal TypeCheckInfo // // If we're looking for members using a residue, we'd expect only // a single item (pick the first one) and we need the residue (which may be "") - | CNR (_, ItemOccurence.WrongUse, _, _, _, _) :: _, _ -> NameResResult.Empty + | CNR(_, ItemOccurence.WrongUse, _, _, _, _) :: _, _ -> NameResResult.Empty | CNR(Item.Types(_, ty :: _), _, denv, nenv, ad, m) :: _, Some _ -> let targets = @@ -1803,7 +1803,7 @@ type internal TypeCheckInfo match d.Item with | Item.Types(_, AbbrevOrAppTy tcref :: _) -> 1 + tcref.TyparsNoRange.Length // Put delegate ctors after types, sorted by #typars. RemoveDuplicateItems will remove FakeInterfaceCtor and DelegateCtor if an earlier type is also reported with this name - | Item.DelegateCtor (AbbrevOrAppTy tcref) -> 1000 + tcref.TyparsNoRange.Length + | Item.DelegateCtor(AbbrevOrAppTy tcref) -> 1000 + tcref.TyparsNoRange.Length // Put type ctors after types, sorted by #typars. RemoveDuplicateItems will remove DefaultStructCtors if a type is also reported with this name | Item.CtorGroup(_, cinfo :: _) -> 1000 + 10 * cinfo.DeclaringTyconRef.TyparsNoRange.Length | _ -> 0 @@ -1822,8 +1822,8 @@ type internal TypeCheckInfo | Item.Types(_, AbbrevOrAppTy tcref :: _) | Item.ExnCase tcref -> tcref.LogicalName | Item.UnqualifiedType(tcref :: _) - | Item.DelegateCtor (AbbrevOrAppTy tcref) -> tcref.CompiledName - | Item.CtorGroup (_, cinfo :: _) -> cinfo.ApparentEnclosingTyconRef.CompiledName + | Item.DelegateCtor(AbbrevOrAppTy tcref) -> tcref.CompiledName + | Item.CtorGroup(_, cinfo :: _) -> cinfo.ApparentEnclosingTyconRef.CompiledName | _ -> d.Item.DisplayName) // Filter out operators (and list) From 239c8b16669a9c6ba472b940f3bbb2c351955773 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 15 Dec 2023 15:52:02 +0100 Subject: [PATCH 8/9] Cleanup --- src/Compiler/Checking/NameResolution.fs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index f6a123d8f7c..3c9665fd9c6 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -273,7 +273,7 @@ type Item = | ValueSome tcref -> tcref.DisplayNameCore | _ -> nm |> DemangleGenericTypeName - |Item.CtorGroup(nm, _) -> nm |> DemangleGenericTypeName + | Item.CtorGroup(nm, _) -> nm |> DemangleGenericTypeName | Item.DelegateCtor ty -> match ty with | AbbrevOrAppTy tcref -> tcref.DisplayNameCore @@ -4013,9 +4013,6 @@ let isWrongItemInExpr item = match item with | Item.Types _ -> true | _ -> false - // | Item.TypeVar(s, typar) -> failwith "todo" - // | Item.ModuleOrNamespaces entityRefs -> failwith "todo" - // | Item.UnqualifiedType entityRefs -> failwith "todo" /// Specifies additional work to do after an item has been processed further in type checking. [] From b96fa07fc563e38ccc0fbad0c88e377460fb2e79 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 15 Dec 2023 15:53:38 +0100 Subject: [PATCH 9/9] Rename --- src/Compiler/Checking/NameResolution.fs | 5 +++-- src/Compiler/Checking/NameResolution.fsi | 2 +- src/Compiler/Service/FSharpCheckerResults.fs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 3c9665fd9c6..5afdada9b05 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -1709,7 +1709,8 @@ type ItemOccurence = | RelatedText /// This is a usage of a module or namespace name in open statement | Open - | WrongUse + /// Not permitted item uses like interface names used as expressions + | InvalidUse type FormatStringCheckContext = { SourceText: ISourceText @@ -4078,7 +4079,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso AfterResolution.RecordResolution(None, (fun tpinst -> callSink(item, tpinst)), callSinkWithSpecificOverload, (fun () -> callSink (item, emptyTyparInst))) elif isWrongItemInExpr item then - CallNameResolutionSink sink (itemRange, nenv, item, emptyTyparInst, ItemOccurence.WrongUse, ad) + CallNameResolutionSink sink (itemRange, nenv, item, emptyTyparInst, ItemOccurence.InvalidUse, ad) AfterResolution.DoNothing else diff --git a/src/Compiler/Checking/NameResolution.fsi b/src/Compiler/Checking/NameResolution.fsi index c466961bfc7..43cfdd12d5c 100755 --- a/src/Compiler/Checking/NameResolution.fsi +++ b/src/Compiler/Checking/NameResolution.fsi @@ -382,7 +382,7 @@ type internal ItemOccurence = | Implemented | RelatedText | Open - | WrongUse + | InvalidUse /// Check for equality, up to signature matching val ItemsAreEffectivelyEqual: TcGlobals -> Item -> Item -> bool diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 762a18c410b..37ae0083298 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -483,7 +483,7 @@ type internal TypeCheckInfo // // If we're looking for members using a residue, we'd expect only // a single item (pick the first one) and we need the residue (which may be "") - | CNR(_, ItemOccurence.WrongUse, _, _, _, _) :: _, _ -> NameResResult.Empty + | CNR(_, ItemOccurence.InvalidUse, _, _, _, _) :: _, _ -> NameResResult.Empty | CNR(Item.Types(_, ty :: _), _, denv, nenv, ad, m) :: _, Some _ -> let targets =