diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 98138270658..cf1b9bce32a 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 @@ -8141,8 +8144,11 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) = when (match item with | Item.DelegateCtor _ - | Item.CtorGroup _ - | Item.FakeInterfaceCtor _ -> 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 @@ -8374,9 +8380,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 +8617,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 +9311,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..5afdada9b05 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 @@ -1713,6 +1709,8 @@ type ItemOccurence = | RelatedText /// This is a usage of a module or namespace name in open statement | Open + /// Not permitted item uses like interface names used as expressions + | InvalidUse type FormatStringCheckContext = { SourceText: ISourceText @@ -1786,8 +1784,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 +2226,6 @@ let CheckAllTyparsInferrable amap m item = | Item.Trait _ | Item.CtorGroup _ - | Item.FakeInterfaceCtor _ | Item.DelegateCtor _ | Item.Types _ | Item.ModuleOrNamespaces _ @@ -2470,7 +2466,8 @@ let private ResolveObjectConstructorPrim (ncenv: NameResolver) edenv resInfo m a else let ctorInfos = GetIntrinsicConstructorInfosOfType ncenv.InfoReader m ty if isNil ctorInfos && isInterfaceTy g ty then - success (resInfo, Item.FakeInterfaceCtor ty) + let tcref = tcrefOfAppTy g ty + success (resInfo, Item.Types(tcref.DisplayName, [ty])) else let defaultStructCtorInfo = if (not (ctorInfos |> List.exists (fun x -> x.IsNullary)) && @@ -3070,33 +3067,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) -> @@ -3997,6 +4010,11 @@ let NeedsWorkAfterResolution namedItem = | Item.ActivePatternCase apref -> not (List.isEmpty apref.ActivePatternVal.Typars) | _ -> false +let isWrongItemInExpr item = + match item with + | Item.Types _ -> true + | _ -> false + /// Specifies additional work to do after an item has been processed further in type checking. [] type AfterResolution = @@ -4059,6 +4077,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.InvalidUse, ad) + AfterResolution.DoNothing + else callSink (item, emptyTyparInst) AfterResolution.DoNothing @@ -4500,7 +4523,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 +5323,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..43cfdd12d5c 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 @@ -385,6 +382,7 @@ type internal ItemOccurence = | Implemented | RelatedText | Open + | 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 2391f26655f..37ae0083298 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.InvalidUse, _, _, _, _) :: _, _ -> NameResResult.Empty + | CNR(Item.Types(_, ty :: _), _, denv, nenv, ad, m) :: _, Some _ -> let targets = ResolveCompletionTargets.All(ConstraintSolver.IsApplicableMethApprox g amap m) @@ -891,7 +893,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,7 +1803,6 @@ 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 // 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 @@ -1822,7 +1822,6 @@ 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 | _ -> d.Item.DisplayName) 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) 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 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 """