From f2fdd7228b1406a119543342acfc9468eafdc78a Mon Sep 17 00:00:00 2001 From: kerams Date: Tue, 24 Jan 2023 19:25:51 +0100 Subject: [PATCH 01/12] Allow modules to be used in type applications --- src/Compiler/Checking/CheckDeclarations.fs | 10 +++---- src/Compiler/Checking/CheckExpressions.fs | 30 ++++++++++++++----- .../Service/ServiceInterfaceStubGenerator.fs | 8 ++++- .../Service/ServiceParamInfoLocations.fs | 8 ++--- src/Compiler/Service/ServiceParsedInputOps.fs | 10 +++---- src/Compiler/Symbols/Symbols.fs | 2 +- src/Compiler/SyntaxTree/LexFilter.fs | 2 ++ src/Compiler/SyntaxTree/SyntaxTree.fs | 4 +-- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/SyntaxTree/SyntaxTreeOps.fs | 2 +- src/Compiler/pars.fsy | 27 +++++++++-------- tests/service/Symbols.fs | 8 ++--- tests/service/SyntaxTreeTests/MeasureTests.fs | 2 +- 13 files changed, 71 insertions(+), 44 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index d858368cd60..09bad33104a 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -2425,7 +2425,7 @@ module EstablishTypeDefinitionCores = let private (|TyconCoreAbbrevThatIsReallyAUnion|_|) (hasMeasureAttr, envinner: TcEnv, id: Ident) synTyconRepr = match synTyconRepr with - | SynTypeDefnSimpleRepr.TypeAbbrev(_, StripParenTypes (SynType.LongIdent(SynLongIdent([unionCaseName], _, _))), m) + | SynTypeDefnSimpleRepr.TypeAbbrev(_, StripParenTypes (SynType.LongIdent(SynLongIdent([unionCaseName], _, _), _)), m) when (not hasMeasureAttr && (isNil (LookupTypeNameInEnvNoArity OpenQualified unionCaseName.idText envinner.NameEnv) || @@ -2785,9 +2785,9 @@ module EstablishTypeDefinitionCores = /// Get the items on the r.h.s. of a 'type X = ABC<...>' definition let private TcTyconDefnCore_GetGenerateDeclaration_Rhs (StripParenTypes rhsType) = match rhsType with - | SynType.App (StripParenTypes (SynType.LongIdent(SynLongIdent(tc, _, _))), _, args, _commas, _, _postfix, m) -> Some(tc, args, m) - | SynType.LongIdent (SynLongIdent(tc, _, _) as lidwd) -> Some(tc, [], lidwd.Range) - | SynType.LongIdentApp (StripParenTypes (SynType.LongIdent (SynLongIdent(tc, _, _))), SynLongIdent(longId, _, _), _, args, _commas, _, m) -> Some(tc@longId, args, m) + | SynType.App (StripParenTypes (SynType.LongIdent(SynLongIdent(tc, _, _), _)), _, args, _commas, _, _postfix, m) -> Some(tc, args, m) + | SynType.LongIdent (SynLongIdent(tc, _, _) as lidwd, _) -> Some(tc, [], lidwd.Range) + | SynType.LongIdentApp (StripParenTypes (SynType.LongIdent (SynLongIdent(tc, _, _), _)), SynLongIdent(longId, _, _), _, args, _commas, _, m) -> Some(tc@longId, args, m) | _ -> None /// Check whether 'type X = ABC<...>' is a generative provided type definition @@ -4403,7 +4403,7 @@ module TcDeclarations = memberFlags.MemberKind=SynMemberKind.Constructor && // REVIEW: This is a syntactic approximation (match synValSig.SynType, synValSig.SynInfo.CurriedArgInfos with - | StripParenTypes (SynType.Fun (argType = StripParenTypes (SynType.LongIdent (SynLongIdent([id], _, _))))), [[_]] when id.idText = "unit" -> true + | StripParenTypes (SynType.Fun (argType = StripParenTypes (SynType.LongIdent (SynLongIdent([id], _, _), _)))), [[_]] when id.idText = "unit" -> true | _ -> false) | _ -> false) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 4c1c47f53b0..4cfa06e29b5 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4291,17 +4291,20 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn let g = cenv.g match synTy with - | SynType.LongIdent(SynLongIdent([], _, _)) -> + | SynType.LongIdent(SynLongIdent([], _, _), _) -> // special case when type name is absent - i.e. empty inherit part in type declaration g.obj_ty, tpenv - | SynType.LongIdent synLongId -> + | SynType.LongIdent (synLongId, false) -> TcLongIdentType kindOpt cenv newOk checkConstraints occ iwsam env tpenv synLongId + | SynType.LongIdent (synLongId, true) -> + TcLongIdentModule cenv newOk checkConstraints occ env tpenv synLongId + | MultiDimensionArrayType (rank, elemTy, m) -> TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m - | SynType.App (StripParenTypes (SynType.LongIdent longId), _, args, _, _, postfix, m) -> + | SynType.App (StripParenTypes (SynType.LongIdent (longId, _)), _, args, _, _, postfix, m) -> TcLongIdentAppType kindOpt cenv newOk checkConstraints occ iwsam env tpenv longId postfix args m | SynType.LongIdentApp (synLeftTy, synLongId, _, args, _commas, _, m) -> @@ -4366,6 +4369,19 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref = if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) +and TcLongIdentModule (cenv: cenv) newOk checkConstraints occ (env: TcEnv) tpenv synLongId = + let (SynLongIdent (tc, _, _)) = synLongId + let m = synLongId.Range + let id, rest = List.headAndTail tc + + let results = + ResolveLongIdentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AtMostOneResult cenv.amap m true OpenQualified env.NameEnv env.eAccessRights id rest false + |> ForceRaise + + match results with + | [] -> failwith "impossible" // handled in ResolveLongIdentAsModuleOrNamespace above + | (_, tcref, _) :: _ -> TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref [] [] + and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId = let (SynLongIdent(tc, _, _)) = synLongId let m = synLongId.Range @@ -4699,7 +4715,7 @@ and TcStaticConstantParameter (cenv: cenv) (env: TcEnv) tpenv kind (StripParenTy | _ -> error(Error(FSComp.SR.tcInvalidConstantExpression(), v.Range)) v, tpenv' - | SynType.LongIdent synLongId -> + | SynType.LongIdent (synLongId, _) -> let m = synLongId.Range TcStaticConstantParameter cenv env tpenv kind (SynType.StaticConstantExpr(SynExpr.LongIdent (false, synLongId, None, m), m)) idOpt container @@ -4709,7 +4725,7 @@ and TcStaticConstantParameter (cenv: cenv) (env: TcEnv) tpenv kind (StripParenTy and CrackStaticConstantArgs (cenv: cenv) env tpenv (staticParameters: Tainted[], args: SynType list, container, containerName, m) = let args = args |> List.map (function - | StripParenTypes (SynType.StaticConstantNamed(StripParenTypes (SynType.LongIdent(SynLongIdent([id], _, _))), v, _)) -> Some id, v + | StripParenTypes (SynType.StaticConstantNamed(StripParenTypes (SynType.LongIdent(SynLongIdent([id], _, _), _)), v, _)) -> Some id, v | v -> None, v) let unnamedArgs = args |> Seq.takeWhile (fst >> Option.isNone) |> Seq.toArray |> Array.map snd @@ -7240,7 +7256,7 @@ and TcConstExpr cenv (overallTy: OverallTy) env m tpenv c = else match ccuOfTyconRef mref with | Some ccu when ccuEq ccu g.fslibCcu -> - SynExpr.Typed (expr, SynType.LongIdent(SynLongIdent(pathToSynLid m ["System";"Numerics";"BigInteger"], [], [None;None;None])), m) + SynExpr.Typed (expr, SynType.LongIdent(SynLongIdent(pathToSynLid m ["System";"Numerics";"BigInteger"], [], [None;None;None]), false), m) | _ -> expr @@ -10524,7 +10540,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn let ad = env.eAccessRights match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInAttribute OpenQualified env.eNameResEnv ad tycon TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No with | Exception err -> raze err - | _ -> success(TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute WarnOnIWSAM.Yes env tpenv (SynType.App(SynType.LongIdent(SynLongIdent(tycon, [], List.replicate tycon.Length None)), None, [], [], None, false, mAttr)) ) + | _ -> success(TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute WarnOnIWSAM.Yes env tpenv (SynType.App(SynType.LongIdent(SynLongIdent(tycon, [], List.replicate tycon.Length None), false), None, [], [], None, false, mAttr)) ) ForceRaise ((try1 (tyid.idText + "Attribute")) |> otherwise (fun () -> (try1 tyid.idText))) let ad = env.eAccessRights diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 15f01224e78..205a1126e71 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -121,7 +121,13 @@ type InterfaceData = match req with | TyparStaticReq.None -> Some("'" + s.idText) | TyparStaticReq.HeadType -> Some("^" + s.idText) - | SynType.LongIdent (SynLongIdent (xs, _, _)) -> xs |> Seq.map (fun x -> x.idText) |> String.concat "." |> Some + | SynType.LongIdent (SynLongIdent (xs, _, _), isModule) -> + let ident = xs |> Seq.map (fun x -> x.idText) |> String.concat "." + + if isModule then + Some (sprintf "module %s" ident) + else + Some ident | SynType.App (t, _, ts, _, _, isPostfix, _) -> match t, ts with | TypeIdent typeName, [] -> Some typeName diff --git a/src/Compiler/Service/ServiceParamInfoLocations.fs b/src/Compiler/Service/ServiceParamInfoLocations.fs index b757120b628..01e8493bca1 100755 --- a/src/Compiler/Service/ServiceParamInfoLocations.fs +++ b/src/Compiler/Service/ServiceParamInfoLocations.fs @@ -89,8 +89,8 @@ module internal ParameterLocationsImpl = let digOutIdentFromStaticArg (StripParenTypes synType) = match synType with - | SynType.StaticConstantNamed (SynType.LongIdent (SynLongIdent ([ id ], _, _)), _, _) -> Some id.idText - | SynType.LongIdent (SynLongIdent ([ id ], _, _)) -> Some id.idText // NOTE: again, not a static constant, but may be a prefix of a Named in incomplete code + | SynType.StaticConstantNamed (SynType.LongIdent (SynLongIdent ([ id ], _, _), _), _, _) -> Some id.idText + | SynType.LongIdent (SynLongIdent ([ id ], _, _), _) -> Some id.idText // NOTE: again, not a static constant, but may be a prefix of a Named in incomplete code | _ -> None let getNamedParamName e = @@ -119,7 +119,7 @@ module internal ParameterLocationsImpl = let getTypeName synType = match synType with - | SynType.LongIdent (SynLongIdent (ids, _, _)) -> ids |> pathOfLid + | SynType.LongIdent (SynLongIdent (ids, _, _), _) -> ids |> pathOfLid | _ -> [ "" ] // TODO type name for other cases, see also unit test named "ParameterInfo.LocationOfParams.AfterQuicklyTyping.CallConstructorViaLongId.Bug94333" let handleSingleArg traverseSynExpr (pos, synExpr, parenRange, rpRangeOpt: _ option) = @@ -212,7 +212,7 @@ module internal ParameterLocationsImpl = let (|StaticParameters|_|) pos (StripParenTypes synType) = match synType with - | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent (lid, _, _) as lidwd)), + | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent (lid, _, _) as lidwd, _)), Some mLess, args, commas, diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index d41426a5e70..6d2f8aaa239 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -654,7 +654,7 @@ module ParsedInput = and walkType ty = match ty with - | SynType.LongIdent ident -> + | SynType.LongIdent (ident, _) -> // we protect it with try..with because System.Exception : rangeOfLidwd may raise // at FSharp.Compiler.Syntax.LongIdentWithDots.get_Range() in D:\j\workspace\release_ci_pa---3f142ccc\src\ast.fs: line 156 try @@ -1111,11 +1111,11 @@ module ParsedInput = let (|NewObjectOrMethodCall|_|) e = match e with - | SynExpr.New (_, SynType.LongIdent typeName, arg, _) -> + | SynExpr.New (_, SynType.LongIdent (typeName, _), arg, _) -> // new A() Some(endOfLastIdent typeName, findSetters arg) - | SynExpr.New (_, SynType.App (StripParenTypes (SynType.LongIdent typeName), _, _, _, mGreaterThan, _, _), arg, _) -> + | SynExpr.New (_, SynType.App (StripParenTypes (SynType.LongIdent (typeName, _)), _, _, _, mGreaterThan, _, _), arg, _) -> // new A<_>() Some(endOfClosingTokenOrLastIdent mGreaterThan typeName, findSetters arg) @@ -1344,7 +1344,7 @@ module ParsedInput = member _.VisitInheritSynMemberDefn(_, componentInfo, typeDefnKind, synType, _, _) = match synType with - | SynType.LongIdent lidwd -> + | SynType.LongIdent (lidwd, _) -> match parseLid pos lidwd with | Some completionPath -> GetCompletionContextForInheritSynMember(componentInfo, typeDefnKind, completionPath) | None -> Some CompletionContext.Invalid // A $ .B -> no completion list @@ -1678,7 +1678,7 @@ module ParsedInput = | SynType.Or (t1, t2, _, _) -> walkType t1 walkType t2 - | SynType.LongIdent ident -> addLongIdentWithDots ident + | SynType.LongIdent (ident, _) -> addLongIdentWithDots ident | SynType.App (ty, _, types, _, _, _, _) -> walkType ty List.iter walkType types diff --git a/src/Compiler/Symbols/Symbols.fs b/src/Compiler/Symbols/Symbols.fs index 56d19effb2a..c4c7bfe2eae 100644 --- a/src/Compiler/Symbols/Symbols.fs +++ b/src/Compiler/Symbols/Symbols.fs @@ -2868,7 +2868,7 @@ type FSharpOpenDeclaration(target: SynOpenDeclTarget, range: range option, modul | SynOpenDeclTarget.Type(synType, _) -> let rec get ty = match ty with - | SynType.LongIdent (SynLongIdent(lid, _, _)) -> lid + | SynType.LongIdent (SynLongIdent(lid, _, _), _) -> lid | SynType.App (ty2, _, _, _, _, _, _) -> get ty2 | SynType.LongIdentApp (ty2, _, _, _, _, _, _) -> get ty2 | SynType.Paren (ty2, _) -> get ty2 diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 09f0bafbea0..ad1814f056b 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1084,6 +1084,7 @@ type LexFilterImpl ( // f<{| C : int |}>x // fx // fx + // fx | DEFAULT | COLON | COLON_GREATER | STRUCT | NULL | DELEGATE | AND | WHEN | DOT_DOT | NEW @@ -1094,6 +1095,7 @@ type LexFilterImpl ( | INFIX_AT_HAT_OP "^-" | INFIX_STAR_DIV_MOD_OP "/" | MINUS + | MODULE | GLOBAL | CONST | KEYWORD_STRING _ diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index aa5535914d5..81d9301e826 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -391,7 +391,7 @@ type SynTupleTypeSegment = [] type SynType = - | LongIdent of longDotId: SynLongIdent + | LongIdent of longDotId: SynLongIdent * isModule: bool | App of typeName: SynType * @@ -460,7 +460,7 @@ type SynType = | SynType.Paren (range = m) | SynType.SignatureParameter (range = m) | SynType.Or (range = m) -> m - | SynType.LongIdent lidwd -> lidwd.Range + | SynType.LongIdent (lidwd, _) -> lidwd.Range [] type SynExpr = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 5190b8fd736..12573fe816a 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -443,7 +443,7 @@ type SynTupleTypeSegment = type SynType = /// F# syntax: A.B.C - | LongIdent of longDotId: SynLongIdent + | LongIdent of longDotId: SynLongIdent * isModule: bool /// F# syntax: type or type type or (type, ..., type) type /// isPostfix: indicates a postfix type application e.g. "int list" or "(int, string) dict" diff --git a/src/Compiler/SyntaxTree/SyntaxTreeOps.fs b/src/Compiler/SyntaxTree/SyntaxTreeOps.fs index 72cfa230342..324f10bb051 100644 --- a/src/Compiler/SyntaxTree/SyntaxTreeOps.fs +++ b/src/Compiler/SyntaxTree/SyntaxTreeOps.fs @@ -990,7 +990,7 @@ let getTypeFromTuplePath (path: SynTupleTypeSegment list) : SynType list = let (|MultiDimensionArrayType|_|) (t: SynType) = match t with - | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent ([ identifier ], _, _))), _, [ elementType ], _, _, true, m) -> + | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent ([ identifier ], _, _), _)), _, [ elementType ], _, _, true, m) -> if System.Text.RegularExpressions.Regex.IsMatch(identifier.idText, "^array\d\d?d$") then let rank = identifier.idText diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index a44a1e69527..3c47bc4b417 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -2010,7 +2010,7 @@ inheritsDefn: | INHERIT ends_coming_soon_or_recover { let mDecl = (rhs parseState 1) if not $2 then errorR(Error(FSComp.SR.parsTypeNameCannotBeEmpty(), mDecl)) - SynMemberDefn.Inherit(SynType.LongIdent(SynLongIdent([], [], [])), None, mDecl) } + SynMemberDefn.Inherit(SynType.LongIdent(SynLongIdent([], [], []), false), None, mDecl) } optAsSpec: | asSpec @@ -2099,7 +2099,7 @@ tyconDefnOrSpfnSimpleRepr: /* type MyAlias = SomeTypeProvider<@"foo"> is a common error, special-case it */ | opt_attributes opt_access path LQUOTE STRING recover { errorR(Error(FSComp.SR.parsUnexpectedQuotationOperatorInTypeAliasDidYouMeanVerbatimString(), rhs parseState 4)) - SynTypeDefnSimpleRepr.TypeAbbrev (ParserDetail.ErrorRecovery, SynType.LongIdent($3), unionRanges (rhs parseState 1) $3.Range) } + SynTypeDefnSimpleRepr.TypeAbbrev (ParserDetail.ErrorRecovery, SynType.LongIdent($3, false), unionRanges (rhs parseState 1) $3.Range) } /* A type abbreviation */ | opt_attributes opt_access typ @@ -2708,23 +2708,23 @@ externArg: cType: | path { let m = $1.Range - SynType.App(SynType.LongIdent($1), None, [], [], None, false, m) } + SynType.App(SynType.LongIdent($1, false), None, [], [], None, false, m) } | cType opt_HIGH_PRECEDENCE_APP LBRACK RBRACK { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("[]", m)], [], [None])), None, [$1], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("[]", m)], [], [None]), false), None, [$1], [], None, true, m) } | cType STAR { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeptr", m)], [], [ Some (IdentTrivia.OriginalNotation "*") ])), None, [$1], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeptr", m)], [], [ Some (IdentTrivia.OriginalNotation "*") ]), false), None, [$1], [], None, true, m) } | cType AMP { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("byref", m)], [], [ Some (IdentTrivia.OriginalNotation "&") ])), None, [$1], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("byref", m)], [], [ Some (IdentTrivia.OriginalNotation "&") ]), false), None, [$1], [], None, true, m) } | VOID STAR { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeint", m)], [], [ Some (IdentTrivia.OriginalNotation "void*") ])), None, [], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeint", m)], [], [ Some (IdentTrivia.OriginalNotation "void*") ]), false), None, [], [], None, true, m) } /* A return type in an 'extern' DllImport function definition */ @@ -2734,7 +2734,7 @@ cRetType: | opt_attributes VOID { let m = rhs parseState 2 - SynReturnInfo((SynType.App(SynType.LongIdent(SynLongIdent([ident("unit", m)], [], [ Some (IdentTrivia.OriginalNotation "void") ])), None, [], [], None, false, m), SynArgInfo($1, false, None)), m) } + SynReturnInfo((SynType.App(SynType.LongIdent(SynLongIdent([ident("unit", m)], [], [ Some (IdentTrivia.OriginalNotation "void") ]), false), None, [], [], None, false, m), SynArgInfo($1, false, None)), m) } localBindings: @@ -5060,7 +5060,7 @@ topTupleTypeElements: topAppType: | attributes appType COLON appType { match $2 with - | SynType.LongIdent(SynLongIdent([id], _, _)) -> + | SynType.LongIdent(SynLongIdent([id], _, _), _) -> let m = rhs2 parseState 1 4 SynType.SignatureParameter($1, false, Some id, $4, m), SynArgInfo($1, false, Some id) | _ -> raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsSyntaxErrorInLabeledType()) } @@ -5075,7 +5075,7 @@ topAppType: | appType COLON appType { match $1 with - | SynType.LongIdent(SynLongIdent([id], _, _)) -> + | SynType.LongIdent(SynLongIdent([id], _, _), _) -> let m = rhs2 parseState 1 3 SynType.SignatureParameter([], false, Some id, $3, m), SynArgInfo([], false, Some id) | _ -> raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsSyntaxErrorInLabeledType()) } @@ -5136,8 +5136,11 @@ tupleOrQuotTypeElements: { [ SynTupleTypeSegment.Type $1 ] } appTypeCon: + | moduleKeyword path %prec prec_atomtyp_path + { SynType.LongIdent($2, true) } + | path %prec prec_atomtyp_path - { SynType.LongIdent($1) } + { SynType.LongIdent($1, false) } | typar { SynType.Var($1, lhs parseState) } @@ -5487,7 +5490,7 @@ dummyTypeArg: | /* EMPTY */ { let m = rhs parseState 1 let dummyStatVal = SynType.StaticConstant(SynConst.Int32(0), m) - let dummyName = SynType.LongIdent(SynLongIdent([ident("", m)], [], [None])) + let dummyName = SynType.LongIdent(SynLongIdent([ident("", m)], [], [None]), false) let dummyTypeArg = SynType.StaticConstantNamed(dummyName, dummyStatVal, m) dummyTypeArg } diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index c5d8c5f53ba..b5614f8762e 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -118,7 +118,7 @@ extern void setCallbridgeSupportTarget(IntPtr newTarget) SynModuleDecl.Let(false, [ SynBinding(returnInfo = Some (SynBindingReturnInfo(typeName = SynType.App(typeName = - SynType.LongIdent(SynLongIdent([unitIdent], [], [Some (IdentTrivia.OriginalNotation "void")])))))) ] , _) + SynType.LongIdent(SynLongIdent([unitIdent], [], [Some (IdentTrivia.OriginalNotation "void")]), false))))) ] , _) ]) ])) -> Assert.AreEqual("unit", unitIdent.idText) @@ -139,7 +139,7 @@ extern int AccessibleChildren(int* x) SynPat.LongIdent(argPats = SynArgPats.Pats [ SynPat.Tuple(_, [ SynPat.Attrib(pat = SynPat.Typed(targetType = SynType.App(typeName = SynType.LongIdent( - SynLongIdent([nativeptrIdent], [], [Some (IdentTrivia.OriginalNotation "*")]) + SynLongIdent([nativeptrIdent], [], [Some (IdentTrivia.OriginalNotation "*")]), false )))) ], _) ])) ], _) @@ -163,7 +163,7 @@ extern int AccessibleChildren(obj& x) SynPat.LongIdent(argPats = SynArgPats.Pats [ SynPat.Tuple(_, [ SynPat.Attrib(pat = SynPat.Typed(targetType = SynType.App(typeName = SynType.LongIdent( - SynLongIdent([byrefIdent], [], [Some (IdentTrivia.OriginalNotation "&")]) + SynLongIdent([byrefIdent], [], [Some (IdentTrivia.OriginalNotation "&")]), false )))) ], _) ])) ], _) @@ -187,7 +187,7 @@ extern int AccessibleChildren(void* x) SynPat.LongIdent(argPats = SynArgPats.Pats [ SynPat.Tuple(_, [ SynPat.Attrib(pat = SynPat.Typed(targetType = SynType.App(typeName = SynType.LongIdent( - SynLongIdent([nativeintIdent], [], [Some (IdentTrivia.OriginalNotation "void*")]) + SynLongIdent([nativeintIdent], [], [Some (IdentTrivia.OriginalNotation "void*")]), false )))) ], _) ])) ], _) diff --git a/tests/service/SyntaxTreeTests/MeasureTests.fs b/tests/service/SyntaxTreeTests/MeasureTests.fs index f8c9f29271a..dd0c975a7a6 100644 --- a/tests/service/SyntaxTreeTests/MeasureTests.fs +++ b/tests/service/SyntaxTreeTests/MeasureTests.fs @@ -50,7 +50,7 @@ let ``SynMeasure.Paren has correct range`` () = let private (|TypeName|_|) t = match t with - | SynType.LongIdent(SynLongIdent([ident], _, _)) -> Some ident.idText + | SynType.LongIdent(SynLongIdent([ident], _, _), _) -> Some ident.idText | _ -> None [] From 3dc6e7b891e454af26cd47bd4c2f233a02cb2fca Mon Sep 17 00:00:00 2001 From: kerams Date: Wed, 25 Jan 2023 19:52:36 +0100 Subject: [PATCH 02/12] Stuff --- src/Compiler/Checking/CheckExpressions.fs | 10 +-- src/Compiler/Checking/NameResolution.fs | 75 +++++++++++++++++++ src/Compiler/Checking/NameResolution.fsi | 13 ++++ src/Compiler/FSComp.txt | 1 + .../Service/ServiceInterfaceStubGenerator.fs | 2 +- src/Compiler/SyntaxTree/LexFilter.fs | 8 +- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 ++ 19 files changed, 164 insertions(+), 10 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 4cfa06e29b5..5a8ae9b02e1 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4299,7 +4299,7 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn TcLongIdentType kindOpt cenv newOk checkConstraints occ iwsam env tpenv synLongId | SynType.LongIdent (synLongId, true) -> - TcLongIdentModule cenv newOk checkConstraints occ env tpenv synLongId + TcLongIdentModule cenv checkConstraints occ env tpenv synLongId | MultiDimensionArrayType (rank, elemTy, m) -> TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m @@ -4369,18 +4369,18 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref = if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) -and TcLongIdentModule (cenv: cenv) newOk checkConstraints occ (env: TcEnv) tpenv synLongId = +and TcLongIdentModule (cenv: cenv) checkConstraints occ (env: TcEnv) tpenv synLongId = let (SynLongIdent (tc, _, _)) = synLongId let m = synLongId.Range let id, rest = List.headAndTail tc let results = - ResolveLongIdentAsModuleOrNamespace cenv.tcSink ResultCollectionSettings.AtMostOneResult cenv.amap m true OpenQualified env.NameEnv env.eAccessRights id rest false + ResolveLongIdentAsModule cenv.tcSink cenv.amap m true OpenQualified env.NameEnv env.eAccessRights id rest |> ForceRaise match results with - | [] -> failwith "impossible" // handled in ResolveLongIdentAsModuleOrNamespace above - | (_, tcref, _) :: _ -> TcTypeApp cenv newOk checkConstraints occ env tpenv m tcref [] [] + | [] -> failwith "unreachable" // handled in ResolveLongIdentAsModule above + | (_, tcref, _) :: _ -> TcTypeApp cenv NoNewTypars checkConstraints occ env tpenv m tcref [] [] and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId = let (SynLongIdent(tc, _, _)) = synLongId diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 6bc0b3e73b7..2fd27f3801c 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -2455,6 +2455,81 @@ let rec ResolveLongIdentAsModuleOrNamespace sink (atMostOne: ResultCollectionSet else raze (namespaceNotFound.Force()) +/// Perform name resolution for an identifier which must resolve to be a module. +let rec ResolveLongIdentAsModule sink amap m first fullyQualified (nenv: NameResolutionEnv) ad (id: Ident) rest = + if first && id.idText = MangledGlobalName then + match rest with + | [] -> + error (Error(FSComp.SR.nrGlobalUsedOnlyAsFirstName(), id.idRange)) + | id2 :: rest2 -> + ResolveLongIdentAsModule sink amap m false FullyQualified nenv ad id2 rest2 + else + let notFoundAux (id: Ident) depth error (tcrefs: TyconRef seq) = + let suggestNames (addToBuffer: string -> unit) = + for tcref in tcrefs do + if IsEntityAccessible amap m ad tcref then + addToBuffer tcref.DisplayName + + UndefinedName(depth, error, id, suggestNames) + + let moduleOrNamespaces = nenv.ModulesAndNamespaces fullyQualified + let namespaceOrModuleNotFound = + lazy + seq { for kv in moduleOrNamespaces do + for modref in kv.Value do + modref } + |> notFoundAux id 0 FSComp.SR.undefinedNameNamespaceOrModule + + // Avoid generating the same error and name suggestion thunk twice It's not clear this is necessary + // since it's just saving an allocation. + let mutable moduleNotFoundErrorCache = None + let moduleNotFound (modref: ModuleOrNamespaceRef) (mty: ModuleOrNamespaceType) (id: Ident) depth = + match moduleNotFoundErrorCache with + | Some (oldId, error) when equals oldId id.idRange -> error + | _ -> + let error = + seq { for kv in mty.ModulesAndNamespacesByDemangledName do + if kv.Value.IsModule then + modref.NestedTyconRef kv.Value + } + |> notFoundAux id depth FSComp.SR.undefinedNameModule + |> raze + moduleNotFoundErrorCache <- Some(id.idRange, error) + error + + let notifyNameResolution (modref: ModuleOrNamespaceRef) m = + let item = Item.ModuleOrNamespaces [modref] + CallNameResolutionSink sink (m, nenv, item, emptyTyparInst, ItemOccurence.Use, ad) + + match moduleOrNamespaces.TryGetValue id.idText with + | true, modrefs -> + /// Look through the sub-namespaces and/or modules + let rec look depth (modref: ModuleOrNamespaceRef) (lid: Ident list) = + let mty = modref.ModuleOrNamespaceType + match lid with + | [] when modref.IsModule -> success [ (depth, modref, mty) ] + | [] -> moduleNotFound modref mty id depth + | id :: rest -> + match mty.ModulesAndNamespacesByDemangledName.TryGetValue id.idText with + | true, res -> + let subref = modref.NestedTyconRef res + if IsEntityAccessible amap m ad subref then + notifyNameResolution subref id.idRange + look (depth + 1) subref rest + else + moduleNotFound modref mty id depth + | _ -> moduleNotFound modref mty id depth + + modrefs + |> List.map (fun modref -> + if IsEntityAccessible amap m ad modref then + notifyNameResolution modref id.idRange + look 1 modref rest + else + raze (namespaceOrModuleNotFound.Force())) + |> List.reduce AddResults + | _ -> raze (namespaceOrModuleNotFound.Force()) + // Note - 'rest' is annotated due to a bug currently in Unity (see: https://github.com/dotnet/fsharp/pull/7427) let ResolveLongIdentAsModuleOrNamespaceThen sink atMostOne amap m fullyQualified (nenv: NameResolutionEnv) ad id (rest: Ident list) isOpenDecl f = match ResolveLongIdentAsModuleOrNamespace sink ResultCollectionSettings.AllResults amap m true fullyQualified nenv ad id [] isOpenDecl with diff --git a/src/Compiler/Checking/NameResolution.fsi b/src/Compiler/Checking/NameResolution.fsi index c93881d7712..8db848190aa 100755 --- a/src/Compiler/Checking/NameResolution.fsi +++ b/src/Compiler/Checking/NameResolution.fsi @@ -675,6 +675,19 @@ val internal ResolveLongIdentAsModuleOrNamespace: isOpenDecl: bool -> ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list> +/// Resolve a long identifier to a module. +val internal ResolveLongIdentAsModule: + sink: TcResultsSink -> + amap: ImportMap -> + m: range -> + first: bool -> + fullyQualified: FullyQualifiedFlag -> + nenv: NameResolutionEnv -> + ad: AccessorDomain -> + id: Ident -> + rest: Ident list -> + ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list> + /// Resolve a long identifier to an object constructor. val internal ResolveObjectConstructor: ncenv: NameResolver -> denv: DisplayEnv -> m: range -> ad: AccessorDomain -> ty: TType -> ResultOrException diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 46379fc0eb4..78e3cfa51ea 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1,6 +1,7 @@ # ------------------------------------------------------------------------------- # use a completely new error number and keep messages in their surrounding groups # ------------------------------------------------------------------------------- +undefinedNameModule,"The module '%s' is not defined." undefinedNameNamespace,"The namespace '%s' is not defined." undefinedNameNamespaceOrModule,"The namespace or module '%s' is not defined." undefinedNameFieldConstructorOrMember,"The field, constructor or member '%s' is not defined." diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 205a1126e71..c59b8396ad7 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -125,7 +125,7 @@ type InterfaceData = let ident = xs |> Seq.map (fun x -> x.idText) |> String.concat "." if isModule then - Some (sprintf "module %s" ident) + Some(sprintf "module %s" ident) else Some ident | SynType.App (t, _, ts, _, _, isPostfix, _) -> diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index ad1814f056b..41e6fe22b6e 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -779,7 +779,7 @@ type LexFilterImpl ( // 'fun ->' places no limit until we hit a CtxtLetDecl etc... (Recursive) | _, CtxtFun _ :: rest -> undentationLimit false rest - + // 'let ... = f ... begin' limited by 'let' (given RelaxWhitespace2) // 'let (' (pattern match) limited by 'let' (given RelaxWhitespace2) // 'let [' (pattern match) limited by 'let' (given RelaxWhitespace2) @@ -1352,7 +1352,7 @@ type LexFilterImpl ( | CtxtDo _ | CtxtLetDecl (true, _) -> Some ODECLEND - + | CtxtSeqBlock(_, _, AddBlockEnd) -> Some OBLOCKEND @@ -1926,7 +1926,7 @@ type LexFilterImpl ( returnToken tokenLexbufState token // module ... ~~~> CtxtModuleHead - | MODULE, _ :: _ -> + | MODULE, _ :: _ when offsideStack |> List.forall (fun x -> match x with CtxtParen (LESS _, _) -> false | _ -> true) -> insertComingSoonTokens("MODULE", MODULE_COMING_SOON, MODULE_IS_HERE) if debug then dprintf "MODULE: entering CtxtModuleHead, awaiting EQUALS to go to CtxtSeqBlock (%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtModuleHead (tokenStartPos, token, NotLexingModuleAttributes)) @@ -2385,7 +2385,7 @@ type LexFilterImpl ( returnToken tokenLexbufState token | _ -> - returnToken tokenLexbufState token + returnToken tokenLexbufState token and insertHighPrecedenceApp (tokenTup: TokenTup) = let dotTokenTup = peekNextTokenTup() diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index be4e61a8fe3..0799d0c64d7 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -1142,6 +1142,11 @@ Typ {0} nedefinuje pole, konstruktor ani člen {1}. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. Není definovaný obor názvů {0}. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 5d662b8bf27..80218ae3305 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -1142,6 +1142,11 @@ Der Typ "{0}" definiert nicht das Feld, den Konstruktor oder den Member "{1}". + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. Der Namespace "{0}" ist nicht definiert. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 1ddc22b8475..461b2aac239 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -1142,6 +1142,11 @@ El tipo "{0}" no define el campo, constructor o miembro "{1}". + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. El espacio de nombres "{0}" no está definido. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index a7b82e51172..3c969280e96 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -1142,6 +1142,11 @@ Le type '{0}' ne définit pas le champ, le constructeur ou le membre '{1}'. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. L'espace de noms '{0}' n'est pas défini. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index fcd590c3b39..67b3826d9e2 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -1142,6 +1142,11 @@ Il tipo '{0}' non definisce il campo, il costruttore o il membro '{1}'. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. Lo spazio dei nomi '{0}' non è definito. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index b064cc8d2b7..24ba5bac58c 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -1142,6 +1142,11 @@ 型 '{0}' は、フィールド、コンストラクター、またはメンバー '{1}' を定義していません。 + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. 名前空間 '{0}' が定義されていません。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 41fced8e047..d2cf0ff04f4 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -1142,6 +1142,11 @@ '{0}' 형식은 '{1}' 필드, 생성자 또는 멤버를 정의하지 않습니다. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. '{0}' 네임스페이스가 정의되지 않았습니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 764d818dcd4..7aa10b8c4d3 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -1142,6 +1142,11 @@ Typ „{0}” nie definiuje pola, konstruktora lub składowej „{1}”. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. Nie zdefiniowano przestrzeni nazw „{0}”. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index da8982c32ac..9ba6d9c4fa4 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -1142,6 +1142,11 @@ O tipo '{0}' não define o campo, o construtor ou o membro '{1}'. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. O namespace '{0}' não está definido. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 29827955000..a712a17bea3 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -1142,6 +1142,11 @@ Тип "{0}" не определяет поле, конструктор или член "{1}". + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. Пространство имен "{0}" не определено. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 3f3bb5dee68..93445c4a735 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -1142,6 +1142,11 @@ '{0}' türü; alanı, oluşturucuyu veya '{1}' üyesini tanımlamıyor. + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. '{0}' ad alanı tanımlı değil. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 3601169ca3a..70470f5b02d 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -1142,6 +1142,11 @@ 类型“{0}”未定义字段、构造函数或成员“{1}”。 + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. 未定义命名空间“{0}”。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index b767cad8784..2099c119ff4 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -1142,6 +1142,11 @@ 類型 '{0}' 未定義欄位、建構函式或成員 '{1}'。 + + The module '{0}' is not defined. + The module '{0}' is not defined. + + The namespace '{0}' is not defined. 未定義命名空間 '{0}'。 From a8c161b3cb9575b89a0d7eca07ca2bff0ea02ed2 Mon Sep 17 00:00:00 2001 From: kerams Date: Wed, 25 Jan 2023 21:09:08 +0100 Subject: [PATCH 03/12] Refactor --- src/Compiler/Checking/CheckDeclarations.fs | 10 +++---- src/Compiler/Checking/CheckExpressions.fs | 16 ++++++------ .../Service/ServiceInterfaceStubGenerator.fs | 9 +++---- .../Service/ServiceParamInfoLocations.fs | 8 +++--- src/Compiler/Service/ServiceParseTreeWalk.fs | 1 + src/Compiler/Service/ServiceParsedInputOps.fs | 12 +++++---- src/Compiler/Symbols/Symbols.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 7 +++-- src/Compiler/SyntaxTree/SyntaxTree.fsi | 5 +++- src/Compiler/SyntaxTree/SyntaxTreeOps.fs | 2 +- src/Compiler/pars.fsy | 26 +++++++++---------- ...ervice.SurfaceArea.netstandard20.debug.bsl | 2 ++ ...vice.SurfaceArea.netstandard20.release.bsl | 2 ++ tests/service/Symbols.fs | 8 +++--- tests/service/SyntaxTreeTests/MeasureTests.fs | 2 +- 15 files changed, 61 insertions(+), 51 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 09bad33104a..d858368cd60 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -2425,7 +2425,7 @@ module EstablishTypeDefinitionCores = let private (|TyconCoreAbbrevThatIsReallyAUnion|_|) (hasMeasureAttr, envinner: TcEnv, id: Ident) synTyconRepr = match synTyconRepr with - | SynTypeDefnSimpleRepr.TypeAbbrev(_, StripParenTypes (SynType.LongIdent(SynLongIdent([unionCaseName], _, _), _)), m) + | SynTypeDefnSimpleRepr.TypeAbbrev(_, StripParenTypes (SynType.LongIdent(SynLongIdent([unionCaseName], _, _))), m) when (not hasMeasureAttr && (isNil (LookupTypeNameInEnvNoArity OpenQualified unionCaseName.idText envinner.NameEnv) || @@ -2785,9 +2785,9 @@ module EstablishTypeDefinitionCores = /// Get the items on the r.h.s. of a 'type X = ABC<...>' definition let private TcTyconDefnCore_GetGenerateDeclaration_Rhs (StripParenTypes rhsType) = match rhsType with - | SynType.App (StripParenTypes (SynType.LongIdent(SynLongIdent(tc, _, _), _)), _, args, _commas, _, _postfix, m) -> Some(tc, args, m) - | SynType.LongIdent (SynLongIdent(tc, _, _) as lidwd, _) -> Some(tc, [], lidwd.Range) - | SynType.LongIdentApp (StripParenTypes (SynType.LongIdent (SynLongIdent(tc, _, _), _)), SynLongIdent(longId, _, _), _, args, _commas, _, m) -> Some(tc@longId, args, m) + | SynType.App (StripParenTypes (SynType.LongIdent(SynLongIdent(tc, _, _))), _, args, _commas, _, _postfix, m) -> Some(tc, args, m) + | SynType.LongIdent (SynLongIdent(tc, _, _) as lidwd) -> Some(tc, [], lidwd.Range) + | SynType.LongIdentApp (StripParenTypes (SynType.LongIdent (SynLongIdent(tc, _, _))), SynLongIdent(longId, _, _), _, args, _commas, _, m) -> Some(tc@longId, args, m) | _ -> None /// Check whether 'type X = ABC<...>' is a generative provided type definition @@ -4403,7 +4403,7 @@ module TcDeclarations = memberFlags.MemberKind=SynMemberKind.Constructor && // REVIEW: This is a syntactic approximation (match synValSig.SynType, synValSig.SynInfo.CurriedArgInfos with - | StripParenTypes (SynType.Fun (argType = StripParenTypes (SynType.LongIdent (SynLongIdent([id], _, _), _)))), [[_]] when id.idText = "unit" -> true + | StripParenTypes (SynType.Fun (argType = StripParenTypes (SynType.LongIdent (SynLongIdent([id], _, _))))), [[_]] when id.idText = "unit" -> true | _ -> false) | _ -> false) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 5a8ae9b02e1..d9aec7052d0 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4291,20 +4291,20 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn let g = cenv.g match synTy with - | SynType.LongIdent(SynLongIdent([], _, _), _) -> + | SynType.LongIdent(SynLongIdent([], _, _)) -> // special case when type name is absent - i.e. empty inherit part in type declaration g.obj_ty, tpenv - | SynType.LongIdent (synLongId, false) -> + | SynType.LongIdent synLongId -> TcLongIdentType kindOpt cenv newOk checkConstraints occ iwsam env tpenv synLongId - | SynType.LongIdent (synLongId, true) -> + | SynType.LongIdentModule synLongId -> TcLongIdentModule cenv checkConstraints occ env tpenv synLongId | MultiDimensionArrayType (rank, elemTy, m) -> TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m - | SynType.App (StripParenTypes (SynType.LongIdent (longId, _)), _, args, _, _, postfix, m) -> + | SynType.App (StripParenTypes (SynType.LongIdent longId), _, args, _, _, postfix, m) -> TcLongIdentAppType kindOpt cenv newOk checkConstraints occ iwsam env tpenv longId postfix args m | SynType.LongIdentApp (synLeftTy, synLongId, _, args, _commas, _, m) -> @@ -4715,7 +4715,7 @@ and TcStaticConstantParameter (cenv: cenv) (env: TcEnv) tpenv kind (StripParenTy | _ -> error(Error(FSComp.SR.tcInvalidConstantExpression(), v.Range)) v, tpenv' - | SynType.LongIdent (synLongId, _) -> + | SynType.LongIdent synLongId -> let m = synLongId.Range TcStaticConstantParameter cenv env tpenv kind (SynType.StaticConstantExpr(SynExpr.LongIdent (false, synLongId, None, m), m)) idOpt container @@ -4725,7 +4725,7 @@ and TcStaticConstantParameter (cenv: cenv) (env: TcEnv) tpenv kind (StripParenTy and CrackStaticConstantArgs (cenv: cenv) env tpenv (staticParameters: Tainted[], args: SynType list, container, containerName, m) = let args = args |> List.map (function - | StripParenTypes (SynType.StaticConstantNamed(StripParenTypes (SynType.LongIdent(SynLongIdent([id], _, _), _)), v, _)) -> Some id, v + | StripParenTypes (SynType.StaticConstantNamed(StripParenTypes (SynType.LongIdent(SynLongIdent([id], _, _))), v, _)) -> Some id, v | v -> None, v) let unnamedArgs = args |> Seq.takeWhile (fst >> Option.isNone) |> Seq.toArray |> Array.map snd @@ -7256,7 +7256,7 @@ and TcConstExpr cenv (overallTy: OverallTy) env m tpenv c = else match ccuOfTyconRef mref with | Some ccu when ccuEq ccu g.fslibCcu -> - SynExpr.Typed (expr, SynType.LongIdent(SynLongIdent(pathToSynLid m ["System";"Numerics";"BigInteger"], [], [None;None;None]), false), m) + SynExpr.Typed (expr, SynType.LongIdent(SynLongIdent(pathToSynLid m ["System";"Numerics";"BigInteger"], [], [None;None;None])), m) | _ -> expr @@ -10540,7 +10540,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn let ad = env.eAccessRights match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInAttribute OpenQualified env.eNameResEnv ad tycon TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No with | Exception err -> raze err - | _ -> success(TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute WarnOnIWSAM.Yes env tpenv (SynType.App(SynType.LongIdent(SynLongIdent(tycon, [], List.replicate tycon.Length None), false), None, [], [], None, false, mAttr)) ) + | _ -> success(TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute WarnOnIWSAM.Yes env tpenv (SynType.App(SynType.LongIdent(SynLongIdent(tycon, [], List.replicate tycon.Length None)), None, [], [], None, false, mAttr)) ) ForceRaise ((try1 (tyid.idText + "Attribute")) |> otherwise (fun () -> (try1 tyid.idText))) let ad = env.eAccessRights diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index c59b8396ad7..2c5f7b6ebf9 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -121,13 +121,10 @@ type InterfaceData = match req with | TyparStaticReq.None -> Some("'" + s.idText) | TyparStaticReq.HeadType -> Some("^" + s.idText) - | SynType.LongIdent (SynLongIdent (xs, _, _), isModule) -> + | SynType.LongIdent (SynLongIdent (xs, _, _)) -> xs |> Seq.map (fun x -> x.idText) |> String.concat "." |> Some + | SynType.LongIdentModule (SynLongIdent (xs, _, _)) -> let ident = xs |> Seq.map (fun x -> x.idText) |> String.concat "." - - if isModule then - Some(sprintf "module %s" ident) - else - Some ident + Some(sprintf "module %s" ident) | SynType.App (t, _, ts, _, _, isPostfix, _) -> match t, ts with | TypeIdent typeName, [] -> Some typeName diff --git a/src/Compiler/Service/ServiceParamInfoLocations.fs b/src/Compiler/Service/ServiceParamInfoLocations.fs index 01e8493bca1..b757120b628 100755 --- a/src/Compiler/Service/ServiceParamInfoLocations.fs +++ b/src/Compiler/Service/ServiceParamInfoLocations.fs @@ -89,8 +89,8 @@ module internal ParameterLocationsImpl = let digOutIdentFromStaticArg (StripParenTypes synType) = match synType with - | SynType.StaticConstantNamed (SynType.LongIdent (SynLongIdent ([ id ], _, _), _), _, _) -> Some id.idText - | SynType.LongIdent (SynLongIdent ([ id ], _, _), _) -> Some id.idText // NOTE: again, not a static constant, but may be a prefix of a Named in incomplete code + | SynType.StaticConstantNamed (SynType.LongIdent (SynLongIdent ([ id ], _, _)), _, _) -> Some id.idText + | SynType.LongIdent (SynLongIdent ([ id ], _, _)) -> Some id.idText // NOTE: again, not a static constant, but may be a prefix of a Named in incomplete code | _ -> None let getNamedParamName e = @@ -119,7 +119,7 @@ module internal ParameterLocationsImpl = let getTypeName synType = match synType with - | SynType.LongIdent (SynLongIdent (ids, _, _), _) -> ids |> pathOfLid + | SynType.LongIdent (SynLongIdent (ids, _, _)) -> ids |> pathOfLid | _ -> [ "" ] // TODO type name for other cases, see also unit test named "ParameterInfo.LocationOfParams.AfterQuicklyTyping.CallConstructorViaLongId.Bug94333" let handleSingleArg traverseSynExpr (pos, synExpr, parenRange, rpRangeOpt: _ option) = @@ -212,7 +212,7 @@ module internal ParameterLocationsImpl = let (|StaticParameters|_|) pos (StripParenTypes synType) = match synType with - | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent (lid, _, _) as lidwd, _)), + | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent (lid, _, _) as lidwd)), Some mLess, args, commas, diff --git a/src/Compiler/Service/ServiceParseTreeWalk.fs b/src/Compiler/Service/ServiceParseTreeWalk.fs index 8415ec401fd..673477fd931 100644 --- a/src/Compiler/Service/ServiceParseTreeWalk.fs +++ b/src/Compiler/Service/ServiceParseTreeWalk.fs @@ -826,6 +826,7 @@ module SyntaxTraversal = | SynType.Anon _ | SynType.AnonRecd _ | SynType.LongIdent _ + | SynType.LongIdentModule _ | SynType.Var _ | SynType.StaticConstant _ -> None diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index 6d2f8aaa239..a9fe43dd663 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -654,7 +654,8 @@ module ParsedInput = and walkType ty = match ty with - | SynType.LongIdent (ident, _) -> + | SynType.LongIdent ident + | SynType.LongIdentModule ident -> // we protect it with try..with because System.Exception : rangeOfLidwd may raise // at FSharp.Compiler.Syntax.LongIdentWithDots.get_Range() in D:\j\workspace\release_ci_pa---3f142ccc\src\ast.fs: line 156 try @@ -1111,11 +1112,11 @@ module ParsedInput = let (|NewObjectOrMethodCall|_|) e = match e with - | SynExpr.New (_, SynType.LongIdent (typeName, _), arg, _) -> + | SynExpr.New (_, SynType.LongIdent typeName, arg, _) -> // new A() Some(endOfLastIdent typeName, findSetters arg) - | SynExpr.New (_, SynType.App (StripParenTypes (SynType.LongIdent (typeName, _)), _, _, _, mGreaterThan, _, _), arg, _) -> + | SynExpr.New (_, SynType.App (StripParenTypes (SynType.LongIdent typeName), _, _, _, mGreaterThan, _, _), arg, _) -> // new A<_>() Some(endOfClosingTokenOrLastIdent mGreaterThan typeName, findSetters arg) @@ -1344,7 +1345,7 @@ module ParsedInput = member _.VisitInheritSynMemberDefn(_, componentInfo, typeDefnKind, synType, _, _) = match synType with - | SynType.LongIdent (lidwd, _) -> + | SynType.LongIdent lidwd -> match parseLid pos lidwd with | Some completionPath -> GetCompletionContextForInheritSynMember(componentInfo, typeDefnKind, completionPath) | None -> Some CompletionContext.Invalid // A $ .B -> no completion list @@ -1678,7 +1679,8 @@ module ParsedInput = | SynType.Or (t1, t2, _, _) -> walkType t1 walkType t2 - | SynType.LongIdent (ident, _) -> addLongIdentWithDots ident + | SynType.LongIdent ident + | SynType.LongIdentModule ident -> addLongIdentWithDots ident | SynType.App (ty, _, types, _, _, _, _) -> walkType ty List.iter walkType types diff --git a/src/Compiler/Symbols/Symbols.fs b/src/Compiler/Symbols/Symbols.fs index c4c7bfe2eae..56d19effb2a 100644 --- a/src/Compiler/Symbols/Symbols.fs +++ b/src/Compiler/Symbols/Symbols.fs @@ -2868,7 +2868,7 @@ type FSharpOpenDeclaration(target: SynOpenDeclTarget, range: range option, modul | SynOpenDeclTarget.Type(synType, _) -> let rec get ty = match ty with - | SynType.LongIdent (SynLongIdent(lid, _, _), _) -> lid + | SynType.LongIdent (SynLongIdent(lid, _, _)) -> lid | SynType.App (ty2, _, _, _, _, _, _) -> get ty2 | SynType.LongIdentApp (ty2, _, _, _, _, _, _) -> get ty2 | SynType.Paren (ty2, _) -> get ty2 diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index 81d9301e826..ed7cdab3561 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -391,7 +391,9 @@ type SynTupleTypeSegment = [] type SynType = - | LongIdent of longDotId: SynLongIdent * isModule: bool + | LongIdent of longDotId: SynLongIdent + + | LongIdentModule of longDotId: SynLongIdent | App of typeName: SynType * @@ -460,7 +462,8 @@ type SynType = | SynType.Paren (range = m) | SynType.SignatureParameter (range = m) | SynType.Or (range = m) -> m - | SynType.LongIdent (lidwd, _) -> lidwd.Range + | SynType.LongIdent lidwd -> lidwd.Range + | SynType.LongIdentModule lidwd -> lidwd.Range [] type SynExpr = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 12573fe816a..fde8d07e1be 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -443,7 +443,10 @@ type SynTupleTypeSegment = type SynType = /// F# syntax: A.B.C - | LongIdent of longDotId: SynLongIdent * isModule: bool + | LongIdent of longDotId: SynLongIdent + + /// F# syntax: typeof + | LongIdentModule of longDotId: SynLongIdent /// F# syntax: type or type type or (type, ..., type) type /// isPostfix: indicates a postfix type application e.g. "int list" or "(int, string) dict" diff --git a/src/Compiler/SyntaxTree/SyntaxTreeOps.fs b/src/Compiler/SyntaxTree/SyntaxTreeOps.fs index 324f10bb051..72cfa230342 100644 --- a/src/Compiler/SyntaxTree/SyntaxTreeOps.fs +++ b/src/Compiler/SyntaxTree/SyntaxTreeOps.fs @@ -990,7 +990,7 @@ let getTypeFromTuplePath (path: SynTupleTypeSegment list) : SynType list = let (|MultiDimensionArrayType|_|) (t: SynType) = match t with - | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent ([ identifier ], _, _), _)), _, [ elementType ], _, _, true, m) -> + | SynType.App (StripParenTypes (SynType.LongIdent (SynLongIdent ([ identifier ], _, _))), _, [ elementType ], _, _, true, m) -> if System.Text.RegularExpressions.Regex.IsMatch(identifier.idText, "^array\d\d?d$") then let rank = identifier.idText diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 3c47bc4b417..ce98fe208cd 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -2010,7 +2010,7 @@ inheritsDefn: | INHERIT ends_coming_soon_or_recover { let mDecl = (rhs parseState 1) if not $2 then errorR(Error(FSComp.SR.parsTypeNameCannotBeEmpty(), mDecl)) - SynMemberDefn.Inherit(SynType.LongIdent(SynLongIdent([], [], []), false), None, mDecl) } + SynMemberDefn.Inherit(SynType.LongIdent(SynLongIdent([], [], [])), None, mDecl) } optAsSpec: | asSpec @@ -2099,7 +2099,7 @@ tyconDefnOrSpfnSimpleRepr: /* type MyAlias = SomeTypeProvider<@"foo"> is a common error, special-case it */ | opt_attributes opt_access path LQUOTE STRING recover { errorR(Error(FSComp.SR.parsUnexpectedQuotationOperatorInTypeAliasDidYouMeanVerbatimString(), rhs parseState 4)) - SynTypeDefnSimpleRepr.TypeAbbrev (ParserDetail.ErrorRecovery, SynType.LongIdent($3, false), unionRanges (rhs parseState 1) $3.Range) } + SynTypeDefnSimpleRepr.TypeAbbrev (ParserDetail.ErrorRecovery, SynType.LongIdent($3), unionRanges (rhs parseState 1) $3.Range) } /* A type abbreviation */ | opt_attributes opt_access typ @@ -2708,23 +2708,23 @@ externArg: cType: | path { let m = $1.Range - SynType.App(SynType.LongIdent($1, false), None, [], [], None, false, m) } + SynType.App(SynType.LongIdent($1), None, [], [], None, false, m) } | cType opt_HIGH_PRECEDENCE_APP LBRACK RBRACK { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("[]", m)], [], [None]), false), None, [$1], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("[]", m)], [], [None])), None, [$1], [], None, true, m) } | cType STAR { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeptr", m)], [], [ Some (IdentTrivia.OriginalNotation "*") ]), false), None, [$1], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeptr", m)], [], [ Some (IdentTrivia.OriginalNotation "*") ])), None, [$1], [], None, true, m) } | cType AMP { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("byref", m)], [], [ Some (IdentTrivia.OriginalNotation "&") ]), false), None, [$1], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("byref", m)], [], [ Some (IdentTrivia.OriginalNotation "&") ])), None, [$1], [], None, true, m) } | VOID STAR { let m = lhs parseState - SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeint", m)], [], [ Some (IdentTrivia.OriginalNotation "void*") ]), false), None, [], [], None, true, m) } + SynType.App(SynType.LongIdent(SynLongIdent([ident("nativeint", m)], [], [ Some (IdentTrivia.OriginalNotation "void*") ])), None, [], [], None, true, m) } /* A return type in an 'extern' DllImport function definition */ @@ -2734,7 +2734,7 @@ cRetType: | opt_attributes VOID { let m = rhs parseState 2 - SynReturnInfo((SynType.App(SynType.LongIdent(SynLongIdent([ident("unit", m)], [], [ Some (IdentTrivia.OriginalNotation "void") ]), false), None, [], [], None, false, m), SynArgInfo($1, false, None)), m) } + SynReturnInfo((SynType.App(SynType.LongIdent(SynLongIdent([ident("unit", m)], [], [ Some (IdentTrivia.OriginalNotation "void") ])), None, [], [], None, false, m), SynArgInfo($1, false, None)), m) } localBindings: @@ -5060,7 +5060,7 @@ topTupleTypeElements: topAppType: | attributes appType COLON appType { match $2 with - | SynType.LongIdent(SynLongIdent([id], _, _), _) -> + | SynType.LongIdent(SynLongIdent([id], _, _)) -> let m = rhs2 parseState 1 4 SynType.SignatureParameter($1, false, Some id, $4, m), SynArgInfo($1, false, Some id) | _ -> raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsSyntaxErrorInLabeledType()) } @@ -5075,7 +5075,7 @@ topAppType: | appType COLON appType { match $1 with - | SynType.LongIdent(SynLongIdent([id], _, _), _) -> + | SynType.LongIdent(SynLongIdent([id], _, _)) -> let m = rhs2 parseState 1 3 SynType.SignatureParameter([], false, Some id, $3, m), SynArgInfo([], false, Some id) | _ -> raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsSyntaxErrorInLabeledType()) } @@ -5137,10 +5137,10 @@ tupleOrQuotTypeElements: appTypeCon: | moduleKeyword path %prec prec_atomtyp_path - { SynType.LongIdent($2, true) } + { SynType.LongIdentModule($2) } | path %prec prec_atomtyp_path - { SynType.LongIdent($1, false) } + { SynType.LongIdent($1) } | typar { SynType.Var($1, lhs parseState) } @@ -5490,7 +5490,7 @@ dummyTypeArg: | /* EMPTY */ { let m = rhs parseState 1 let dummyStatVal = SynType.StaticConstant(SynConst.Int32(0), m) - let dummyName = SynType.LongIdent(SynLongIdent([ident("", m)], [], [None]), false) + let dummyName = SynType.LongIdent(SynLongIdent([ident("", m)], [], [None])) let dummyTypeArg = SynType.StaticConstantNamed(dummyName, dummyStatVal, m) dummyTypeArg } diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index 8ce003becdf..fcecd326001 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -8373,6 +8373,8 @@ FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range get_ra FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent longDotId +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynType get_typeName() diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index 8ce003becdf..fcecd326001 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -8373,6 +8373,8 @@ FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range get_ra FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent longDotId +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynType get_typeName() diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index b5614f8762e..c5d8c5f53ba 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -118,7 +118,7 @@ extern void setCallbridgeSupportTarget(IntPtr newTarget) SynModuleDecl.Let(false, [ SynBinding(returnInfo = Some (SynBindingReturnInfo(typeName = SynType.App(typeName = - SynType.LongIdent(SynLongIdent([unitIdent], [], [Some (IdentTrivia.OriginalNotation "void")]), false))))) ] , _) + SynType.LongIdent(SynLongIdent([unitIdent], [], [Some (IdentTrivia.OriginalNotation "void")])))))) ] , _) ]) ])) -> Assert.AreEqual("unit", unitIdent.idText) @@ -139,7 +139,7 @@ extern int AccessibleChildren(int* x) SynPat.LongIdent(argPats = SynArgPats.Pats [ SynPat.Tuple(_, [ SynPat.Attrib(pat = SynPat.Typed(targetType = SynType.App(typeName = SynType.LongIdent( - SynLongIdent([nativeptrIdent], [], [Some (IdentTrivia.OriginalNotation "*")]), false + SynLongIdent([nativeptrIdent], [], [Some (IdentTrivia.OriginalNotation "*")]) )))) ], _) ])) ], _) @@ -163,7 +163,7 @@ extern int AccessibleChildren(obj& x) SynPat.LongIdent(argPats = SynArgPats.Pats [ SynPat.Tuple(_, [ SynPat.Attrib(pat = SynPat.Typed(targetType = SynType.App(typeName = SynType.LongIdent( - SynLongIdent([byrefIdent], [], [Some (IdentTrivia.OriginalNotation "&")]), false + SynLongIdent([byrefIdent], [], [Some (IdentTrivia.OriginalNotation "&")]) )))) ], _) ])) ], _) @@ -187,7 +187,7 @@ extern int AccessibleChildren(void* x) SynPat.LongIdent(argPats = SynArgPats.Pats [ SynPat.Tuple(_, [ SynPat.Attrib(pat = SynPat.Typed(targetType = SynType.App(typeName = SynType.LongIdent( - SynLongIdent([nativeintIdent], [], [Some (IdentTrivia.OriginalNotation "void*")]), false + SynLongIdent([nativeintIdent], [], [Some (IdentTrivia.OriginalNotation "void*")]) )))) ], _) ])) ], _) diff --git a/tests/service/SyntaxTreeTests/MeasureTests.fs b/tests/service/SyntaxTreeTests/MeasureTests.fs index dd0c975a7a6..f8c9f29271a 100644 --- a/tests/service/SyntaxTreeTests/MeasureTests.fs +++ b/tests/service/SyntaxTreeTests/MeasureTests.fs @@ -50,7 +50,7 @@ let ``SynMeasure.Paren has correct range`` () = let private (|TypeName|_|) t = match t with - | SynType.LongIdent(SynLongIdent([ident], _, _), _) -> Some ident.idText + | SynType.LongIdent(SynLongIdent([ident], _, _)) -> Some ident.idText | _ -> None [] From fc33e47fff2f04890c9f9e6e1624f97d0f42e838 Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 28 Jan 2023 10:04:27 +0100 Subject: [PATCH 04/12] Fix surface area --- ...harp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl | 5 +++++ ...rp.Compiler.Service.SurfaceArea.netstandard20.release.bsl | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index fcecd326001..35c777daaa9 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -8439,6 +8439,7 @@ FSharp.Compiler.Syntax.SynType+Tags: Int32 Fun FSharp.Compiler.Syntax.SynType+Tags: Int32 HashConstraint FSharp.Compiler.Syntax.SynType+Tags: Int32 LongIdent FSharp.Compiler.Syntax.SynType+Tags: Int32 LongIdentApp +FSharp.Compiler.Syntax.SynType+Tags: Int32 LongIdentModule FSharp.Compiler.Syntax.SynType+Tags: Int32 MeasurePower FSharp.Compiler.Syntax.SynType+Tags: Int32 Or FSharp.Compiler.Syntax.SynType+Tags: Int32 Paren @@ -8473,6 +8474,7 @@ FSharp.Compiler.Syntax.SynType: Boolean IsFun FSharp.Compiler.Syntax.SynType: Boolean IsHashConstraint FSharp.Compiler.Syntax.SynType: Boolean IsLongIdent FSharp.Compiler.Syntax.SynType: Boolean IsLongIdentApp +FSharp.Compiler.Syntax.SynType: Boolean IsLongIdentModule FSharp.Compiler.Syntax.SynType: Boolean IsMeasurePower FSharp.Compiler.Syntax.SynType: Boolean IsOr FSharp.Compiler.Syntax.SynType: Boolean IsParen @@ -8491,6 +8493,7 @@ FSharp.Compiler.Syntax.SynType: Boolean get_IsFun() FSharp.Compiler.Syntax.SynType: Boolean get_IsHashConstraint() FSharp.Compiler.Syntax.SynType: Boolean get_IsLongIdent() FSharp.Compiler.Syntax.SynType: Boolean get_IsLongIdentApp() +FSharp.Compiler.Syntax.SynType: Boolean get_IsLongIdentModule() FSharp.Compiler.Syntax.SynType: Boolean get_IsMeasurePower() FSharp.Compiler.Syntax.SynType: Boolean get_IsOr() FSharp.Compiler.Syntax.SynType: Boolean get_IsParen() @@ -8509,6 +8512,7 @@ FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewFun(FSharp.Com FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewHashConstraint(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdent(FSharp.Compiler.Syntax.SynLongIdent) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentApp(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynLongIdent, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynType], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentModule(FSharp.Compiler.Syntax.SynLongIdent) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewMeasurePower(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewOr(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynTypeOrTrivia) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewParen(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) @@ -8527,6 +8531,7 @@ FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+Fun FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+HashConstraint FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+LongIdent FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+LongIdentApp +FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+LongIdentModule FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+MeasurePower FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+Or FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+Paren diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index fcecd326001..35c777daaa9 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -8439,6 +8439,7 @@ FSharp.Compiler.Syntax.SynType+Tags: Int32 Fun FSharp.Compiler.Syntax.SynType+Tags: Int32 HashConstraint FSharp.Compiler.Syntax.SynType+Tags: Int32 LongIdent FSharp.Compiler.Syntax.SynType+Tags: Int32 LongIdentApp +FSharp.Compiler.Syntax.SynType+Tags: Int32 LongIdentModule FSharp.Compiler.Syntax.SynType+Tags: Int32 MeasurePower FSharp.Compiler.Syntax.SynType+Tags: Int32 Or FSharp.Compiler.Syntax.SynType+Tags: Int32 Paren @@ -8473,6 +8474,7 @@ FSharp.Compiler.Syntax.SynType: Boolean IsFun FSharp.Compiler.Syntax.SynType: Boolean IsHashConstraint FSharp.Compiler.Syntax.SynType: Boolean IsLongIdent FSharp.Compiler.Syntax.SynType: Boolean IsLongIdentApp +FSharp.Compiler.Syntax.SynType: Boolean IsLongIdentModule FSharp.Compiler.Syntax.SynType: Boolean IsMeasurePower FSharp.Compiler.Syntax.SynType: Boolean IsOr FSharp.Compiler.Syntax.SynType: Boolean IsParen @@ -8491,6 +8493,7 @@ FSharp.Compiler.Syntax.SynType: Boolean get_IsFun() FSharp.Compiler.Syntax.SynType: Boolean get_IsHashConstraint() FSharp.Compiler.Syntax.SynType: Boolean get_IsLongIdent() FSharp.Compiler.Syntax.SynType: Boolean get_IsLongIdentApp() +FSharp.Compiler.Syntax.SynType: Boolean get_IsLongIdentModule() FSharp.Compiler.Syntax.SynType: Boolean get_IsMeasurePower() FSharp.Compiler.Syntax.SynType: Boolean get_IsOr() FSharp.Compiler.Syntax.SynType: Boolean get_IsParen() @@ -8509,6 +8512,7 @@ FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewFun(FSharp.Com FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewHashConstraint(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdent(FSharp.Compiler.Syntax.SynLongIdent) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentApp(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynLongIdent, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynType], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentModule(FSharp.Compiler.Syntax.SynLongIdent) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewMeasurePower(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewOr(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynTypeOrTrivia) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewParen(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) @@ -8527,6 +8531,7 @@ FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+Fun FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+HashConstraint FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+LongIdent FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+LongIdentApp +FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+LongIdentModule FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+MeasurePower FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+Or FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType+Paren From 3010719f58c30a64fcc16142968dfae89e9907d5 Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 28 Jan 2023 14:21:15 +0100 Subject: [PATCH 05/12] Add tests --- src/Compiler/Checking/NameResolution.fs | 56 ++++++----------- .../FSharp.Compiler.ComponentTests.fsproj | 2 + .../Language/ModuleAsTypeTests.fs | 61 +++++++++++++++++++ .../Language/NameofTests.fs | 13 ++++ 4 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 2fd27f3801c..ca092e1284d 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -2464,51 +2464,29 @@ let rec ResolveLongIdentAsModule sink amap m first fullyQualified (nenv: NameRes | id2 :: rest2 -> ResolveLongIdentAsModule sink amap m false FullyQualified nenv ad id2 rest2 else - let notFoundAux (id: Ident) depth error (tcrefs: TyconRef seq) = - let suggestNames (addToBuffer: string -> unit) = - for tcref in tcrefs do - if IsEntityAccessible amap m ad tcref then - addToBuffer tcref.DisplayName - - UndefinedName(depth, error, id, suggestNames) - - let moduleOrNamespaces = nenv.ModulesAndNamespaces fullyQualified - let namespaceOrModuleNotFound = - lazy - seq { for kv in moduleOrNamespaces do - for modref in kv.Value do - modref } - |> notFoundAux id 0 FSComp.SR.undefinedNameNamespaceOrModule - - // Avoid generating the same error and name suggestion thunk twice It's not clear this is necessary - // since it's just saving an allocation. - let mutable moduleNotFoundErrorCache = None - let moduleNotFound (modref: ModuleOrNamespaceRef) (mty: ModuleOrNamespaceType) (id: Ident) depth = - match moduleNotFoundErrorCache with - | Some (oldId, error) when equals oldId id.idRange -> error - | _ -> - let error = - seq { for kv in mty.ModulesAndNamespacesByDemangledName do - if kv.Value.IsModule then - modref.NestedTyconRef kv.Value - } - |> notFoundAux id depth FSComp.SR.undefinedNameModule - |> raze - moduleNotFoundErrorCache <- Some(id.idRange, error) - error + let notFound (id: Ident) (rest: Ident list) depth = + let message = + // "undefined module" when the last bit is not a known module - `typeof`, `typeof` + if rest.IsEmpty then + FSComp.SR.undefinedNameModule + // "undefined namespace or module" otherwise - `typeof` + else + FSComp.SR.undefinedNameNamespaceOrModule + + UndefinedName (depth, message, id, NoSuggestions) |> Exception let notifyNameResolution (modref: ModuleOrNamespaceRef) m = let item = Item.ModuleOrNamespaces [modref] CallNameResolutionSink sink (m, nenv, item, emptyTyparInst, ItemOccurence.Use, ad) - match moduleOrNamespaces.TryGetValue id.idText with + match (nenv.ModulesAndNamespaces fullyQualified).TryGetValue id.idText with | true, modrefs -> - /// Look through the sub-namespaces and/or modules + // Look through the sub-namespaces and/or modules let rec look depth (modref: ModuleOrNamespaceRef) (lid: Ident list) = let mty = modref.ModuleOrNamespaceType match lid with | [] when modref.IsModule -> success [ (depth, modref, mty) ] - | [] -> moduleNotFound modref mty id depth + | [] -> notFound id rest depth | id :: rest -> match mty.ModulesAndNamespacesByDemangledName.TryGetValue id.idText with | true, res -> @@ -2517,8 +2495,8 @@ let rec ResolveLongIdentAsModule sink amap m first fullyQualified (nenv: NameRes notifyNameResolution subref id.idRange look (depth + 1) subref rest else - moduleNotFound modref mty id depth - | _ -> moduleNotFound modref mty id depth + notFound id rest depth + | _ -> notFound id rest depth modrefs |> List.map (fun modref -> @@ -2526,9 +2504,9 @@ let rec ResolveLongIdentAsModule sink amap m first fullyQualified (nenv: NameRes notifyNameResolution modref id.idRange look 1 modref rest else - raze (namespaceOrModuleNotFound.Force())) + notFound id rest 0) |> List.reduce AddResults - | _ -> raze (namespaceOrModuleNotFound.Force()) + | _ -> notFound id rest 0 // Note - 'rest' is annotated due to a bug currently in Unity (see: https://github.com/dotnet/fsharp/pull/7427) let ResolveLongIdentAsModuleOrNamespaceThen sink atMostOne amap m fullyQualified (nenv: NameResolutionEnv) ad id (rest: Ident list) isOpenDecl f = diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index c244723eb72..d9f0eae3709 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -179,6 +179,7 @@ + @@ -236,6 +237,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs new file mode 100644 index 00000000000..a190d3d23ec --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs @@ -0,0 +1,61 @@ +module FSharp.Compiler.ComponentTests.Language.ModuleAsTypeTests + +open Xunit +open FSharp.Test.Compiler + +[] +let ``Module can be used in typeof in lang preview`` () = + Fsx """ +let actual = typeof.Name +let expected = "LanguagePrimitives" +if actual <> expected then failwith $"Expected '{{expected}}', but got '{{actual}}'" + """ + |> asExe + |> withLangVersionPreview + |> compileAndRun + |> shouldSucceed + +[] +let ``Module can be used as generic type argument in lang preview`` () = + Fsx """ +let actual = ResizeArray().GetType().FullName +let expected = "System.Collections.Generic.List`1[[Microsoft.FSharp.Core.LanguagePrimitives" +if not (actual.StartsWith expected) then failwith $"Expected to start with '{expected}', but got '{actual}'" + """ + |> asExe + |> withLangVersionPreview + |> compileAndRun + |> shouldSucceed + +[] +let ``Namespaces, types, values and non-existent modules cannot be used as modules in typeof in lang preview`` () = + Fsx """ +module rec Ns.A + +module B = + let value = () + +type R = { F: int } + +let _ = typeof +let _ = typeof +let _ = typeof +let _ = typeof +let _ = typeof +let _ = typeof +let _ = typeof +let _ = typeof + """ + |> withLangVersionPreview + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 39, Line 9, Col 23, Line 9, Col 25, "The module 'Ns' is not defined.") + (Error 39, Line 10, Col 23, Line 10, Col 34, "The module 'Nonexistent' is not defined.") + (Error 39, Line 11, Col 23, Line 11, Col 36, "The namespace or module 'NonexistentNs' is not defined.") + (Error 39, Line 12, Col 26, Line 12, Col 37, "The module 'Nonexistent' is not defined.") + (Error 39, Line 13, Col 26, Line 13, Col 39, "The namespace or module 'NonexistentNs' is not defined.") + (Error 39, Line 14, Col 28, Line 14, Col 39, "The module 'Nonexistent' is not defined.") + (Error 39, Line 15, Col 30, Line 15, Col 35, "The module 'value' is not defined.") + (Error 39, Line 16, Col 23, Line 16, Col 24, "The module 'R' is not defined.") + ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NameofTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NameofTests.fs index 27e7ca95bec..594519eb33d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NameofTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NameofTests.fs @@ -129,3 +129,16 @@ if not((getData b) = re2.Data) then |> compileAndRun |> shouldSucceed + [] + let ``nameof works for modules`` () = + let source = """ +let actual = nameof(FSharp.Core.LanguagePrimitives) +let expected = "LanguagePrimitives" +if actual <> expected then failwith $"Expected type to be '{expected}', but got '{actual}'" + """ + Fsx source + |> asExe + |> withLangVersionPreview + |> ignoreWarnings + |> compileAndRun + |> shouldSucceed From b19e561694649a5ac370e8c3ab5e32a3600e1530 Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 28 Jan 2023 15:28:04 +0100 Subject: [PATCH 06/12] Add completions support --- src/Compiler/Service/FSharpCheckerResults.fs | 8 +++++++- src/Compiler/Service/ServiceParsedInputOps.fs | 14 +++++++++++++- src/Compiler/Service/ServiceParsedInputOps.fsi | 3 +++ ...ler.Service.SurfaceArea.netstandard20.debug.bsl | 9 +++++++-- ...r.Service.SurfaceArea.netstandard20.release.bsl | 7 +++++++ .../FSharp.Editor.Tests/CompletionProviderTests.fs | 13 +++++++++++++ 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index c66bb3e5142..8b89e3e708d 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -1329,7 +1329,13 @@ type internal TypeCheckInfo denv, m) - | Some (CompletionContext.OpenDeclaration isOpenType) -> + | Some CompletionContext.ModuleAsType + | Some (CompletionContext.OpenDeclaration _) -> + let isOpenType = + match completionContext with + | Some (CompletionContext.OpenDeclaration true) -> true + | _ -> false + GetDeclaredItems( parseResultsOpt, lineStr, diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index 2ca03bec07f..ddcf70699d2 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -80,6 +80,9 @@ type CompletionContext = /// or a single case union without a bar (type SomeUnion = Abc|) | TypeAbbreviationOrSingleCaseUnion + /// Completing module in generic type application (e.g. typeof) + | ModuleAsType + type ShortIdent = string type ShortIdents = ShortIdent[] @@ -1307,7 +1310,16 @@ module ParsedInput = | SynExpr.Record (None, None, [], _) -> Some(CompletionContext.RecordField RecordContext.Empty) // Unchecked.defaultof - | SynExpr.TypeApp (typeArgsRange = range) when rangeContainsPos range pos -> Some CompletionContext.PatternType + // typeof + | SynExpr.TypeApp (typeArgs = typeArgs; typeArgsRange = range) when rangeContainsPos range pos -> + typeArgs + |> List.tryPick (fun arg -> + match arg with + | SynType.LongIdent lid when rangeContainsPos lid.Range pos -> Some CompletionContext.PatternType + | SynType.LongIdentModule lid when rangeContainsPos lid.Range pos -> Some CompletionContext.ModuleAsType + | _ -> None) + |> Option.orElse (Some CompletionContext.PatternType) + | _ -> defaultTraverse expr member _.VisitRecordField(path, copyOpt, field) = diff --git a/src/Compiler/Service/ServiceParsedInputOps.fsi b/src/Compiler/Service/ServiceParsedInputOps.fsi index f0542957759..27fafe81a4a 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fsi +++ b/src/Compiler/Service/ServiceParsedInputOps.fsi @@ -53,6 +53,9 @@ type public CompletionContext = /// or a single case union without a bar (type SomeUnion = Abc|) | TypeAbbreviationOrSingleCaseUnion + /// Completing module in generic type application (e.g. typeof) + | ModuleAsType + type public ModuleKind = { IsAutoOpen: bool HasModuleSuffix: bool } diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index 35c777daaa9..10310e1763d 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -2497,6 +2497,7 @@ FSharp.Compiler.EditorServices.CompletionContext+RecordField: FSharp.Compiler.Ed FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 AttributeApplication FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 Inherit FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 Invalid +FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 ModuleAsType FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 OpenDeclaration FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 ParameterList FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 PatternType @@ -2510,6 +2511,7 @@ FSharp.Compiler.EditorServices.CompletionContext: Boolean Equals(System.Object, FSharp.Compiler.EditorServices.CompletionContext: Boolean IsAttributeApplication FSharp.Compiler.EditorServices.CompletionContext: Boolean IsInherit FSharp.Compiler.EditorServices.CompletionContext: Boolean IsInvalid +FSharp.Compiler.EditorServices.CompletionContext: Boolean IsModuleAsType FSharp.Compiler.EditorServices.CompletionContext: Boolean IsOpenDeclaration FSharp.Compiler.EditorServices.CompletionContext: Boolean IsParameterList FSharp.Compiler.EditorServices.CompletionContext: Boolean IsPatternType @@ -2520,6 +2522,7 @@ FSharp.Compiler.EditorServices.CompletionContext: Boolean IsUnionCaseFieldsDecla FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsAttributeApplication() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsInherit() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsInvalid() +FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsModuleAsType() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsOpenDeclaration() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsParameterList() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsPatternType() @@ -2529,6 +2532,7 @@ FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsTypeAbbreviation FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsUnionCaseFieldsDeclaration() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext AttributeApplication FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext Invalid +FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext ModuleAsType FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext NewInherit(FSharp.Compiler.EditorServices.InheritanceContext, System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[System.String],Microsoft.FSharp.Core.FSharpOption`1[System.String]]) FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext NewOpenDeclaration(Boolean) FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext NewParameterList(FSharp.Compiler.Text.Position, System.Collections.Generic.HashSet`1[System.String]) @@ -2539,6 +2543,7 @@ FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext UnionCaseFieldsDeclaration FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_AttributeApplication() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_Invalid() +FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_ModuleAsType() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_PatternType() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_RangeOperator() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_TypeAbbreviationOrSingleCaseUnion() @@ -8373,8 +8378,6 @@ FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range get_ra FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent longDotId -FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() -FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynType get_typeName() @@ -8389,6 +8392,8 @@ FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption` FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] get_lessRange() FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] greaterRange FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] lessRange +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst exponent FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst get_exponent() FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynType baseMeasure diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index 35c777daaa9..61114fa8a2d 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -2497,6 +2497,7 @@ FSharp.Compiler.EditorServices.CompletionContext+RecordField: FSharp.Compiler.Ed FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 AttributeApplication FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 Inherit FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 Invalid +FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 ModuleAsType FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 OpenDeclaration FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 ParameterList FSharp.Compiler.EditorServices.CompletionContext+Tags: Int32 PatternType @@ -2510,6 +2511,7 @@ FSharp.Compiler.EditorServices.CompletionContext: Boolean Equals(System.Object, FSharp.Compiler.EditorServices.CompletionContext: Boolean IsAttributeApplication FSharp.Compiler.EditorServices.CompletionContext: Boolean IsInherit FSharp.Compiler.EditorServices.CompletionContext: Boolean IsInvalid +FSharp.Compiler.EditorServices.CompletionContext: Boolean IsModuleAsType FSharp.Compiler.EditorServices.CompletionContext: Boolean IsOpenDeclaration FSharp.Compiler.EditorServices.CompletionContext: Boolean IsParameterList FSharp.Compiler.EditorServices.CompletionContext: Boolean IsPatternType @@ -2520,6 +2522,7 @@ FSharp.Compiler.EditorServices.CompletionContext: Boolean IsUnionCaseFieldsDecla FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsAttributeApplication() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsInherit() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsInvalid() +FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsModuleAsType() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsOpenDeclaration() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsParameterList() FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsPatternType() @@ -2529,6 +2532,7 @@ FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsTypeAbbreviation FSharp.Compiler.EditorServices.CompletionContext: Boolean get_IsUnionCaseFieldsDeclaration() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext AttributeApplication FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext Invalid +FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext ModuleAsType FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext NewInherit(FSharp.Compiler.EditorServices.InheritanceContext, System.Tuple`2[Microsoft.FSharp.Collections.FSharpList`1[System.String],Microsoft.FSharp.Core.FSharpOption`1[System.String]]) FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext NewOpenDeclaration(Boolean) FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext NewParameterList(FSharp.Compiler.Text.Position, System.Collections.Generic.HashSet`1[System.String]) @@ -2539,6 +2543,7 @@ FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext UnionCaseFieldsDeclaration FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_AttributeApplication() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_Invalid() +FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_ModuleAsType() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_PatternType() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_RangeOperator() FSharp.Compiler.EditorServices.CompletionContext: FSharp.Compiler.EditorServices.CompletionContext get_TypeAbbreviationOrSingleCaseUnion() @@ -8389,6 +8394,8 @@ FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption` FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] get_lessRange() FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] greaterRange FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] lessRange +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst exponent FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst get_exponent() FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynType baseMeasure diff --git a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs index 2be760394f9..9856df5fb3e 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs @@ -1218,6 +1218,19 @@ let emptyMap<'keyType, 'lValueType> () = """ VerifyCompletionList(fileContents, ", l", [ "LanguagePrimitives"; "List"; "lValueType" ], [ "let"; "log" ]) + + [] + let ``Completion list in type application of a module only contains modules and namespaces`` () = + let fileContents = + """ +open System + +let emptyMap<'lValueType> () = + Map.empty +""" + + VerifyCompletionList(fileContents, "module L", [ "LanguagePrimitives"; "Linq" ], [ "let"; "log"; "lValueType"; "Lazy" ]) + VerifyCompletionList(fileContents, "] let ``Completion list for interface with static abstract method type invocation contains static property with residue`` () = From 1d152b3f71d3b6983e916f201e76502f3921cea0 Mon Sep 17 00:00:00 2001 From: kerams Date: Mon, 30 Jan 2023 10:32:15 +0100 Subject: [PATCH 07/12] Guard modules in type application with a language feature --- src/Compiler/FSComp.txt | 1 + src/Compiler/Facilities/LanguageFeatures.fs | 3 +++ src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/pars.fsy | 3 ++- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ .../Language/ModuleAsTypeTests.fs | 14 +++++++++++++- 18 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 78e3cfa51ea..6c40bb9d2da 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1562,6 +1562,7 @@ featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members featureWarningWhenInliningMethodImplNoInlineMarkedFunction,"Raises warnings when 'let inline ... =' is used together with [] attribute. Function is not getting inlined." featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals" featureErrorReportingOnStaticClasses,"Error reporting on static classes" +featureModulesInTypeApplication,"Allow modules to be used in type application" 3353,fsiInvalidDirective,"Invalid directive '#%s %s'" 3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index e7654bea422..32b8ef6960e 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -61,6 +61,7 @@ type LanguageFeature = | EscapeDotnetFormattableStrings | ArithmeticInLiterals | ErrorReportingOnStaticClasses + | ModulesInTypeApplication /// LanguageVersion management type LanguageVersion(versionText) = @@ -138,6 +139,7 @@ type LanguageVersion(versionText) = LanguageFeature.EscapeDotnetFormattableStrings, previewVersion LanguageFeature.ArithmeticInLiterals, previewVersion LanguageFeature.ErrorReportingOnStaticClasses, previewVersion + LanguageFeature.ModulesInTypeApplication, previewVersion ] @@ -252,6 +254,7 @@ type LanguageVersion(versionText) = | LanguageFeature.EscapeDotnetFormattableStrings -> FSComp.SR.featureEscapeBracesInFormattableString () | LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals () | LanguageFeature.ErrorReportingOnStaticClasses -> FSComp.SR.featureErrorReportingOnStaticClasses () + | LanguageFeature.ModulesInTypeApplication -> FSComp.SR.featureModulesInTypeApplication () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index d070a8b4e36..30081190569 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -51,6 +51,7 @@ type LanguageFeature = | EscapeDotnetFormattableStrings | ArithmeticInLiterals | ErrorReportingOnStaticClasses + | ModulesInTypeApplication /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index ce98fe208cd..e788434b888 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -5137,7 +5137,8 @@ tupleOrQuotTypeElements: appTypeCon: | moduleKeyword path %prec prec_atomtyp_path - { SynType.LongIdentModule($2) } + { parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.ModulesInTypeApplication (rhs parseState 1) + SynType.LongIdentModule($2) } | path %prec prec_atomtyp_path { SynType.LongIdent($1) } diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 0799d0c64d7..02990b82cbd 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -297,6 +297,11 @@ Zahození shody vzoru není povolené pro případ sjednocení, který nepřijímá žádná data. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 80218ae3305..f29f3015e65 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -297,6 +297,11 @@ Das Verwerfen von Musterübereinstimmungen ist für einen Union-Fall, der keine Daten akzeptiert, nicht zulässig. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 461b2aac239..d23af6947cf 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -297,6 +297,11 @@ No se permite el descarte de coincidencia de patrón para un caso de unión que no tome datos. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 3c969280e96..c7709599a11 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -297,6 +297,11 @@ L’abandon des correspondances de modèle n’est pas autorisé pour un cas d’union qui n’accepte aucune donnée. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 67b3826d9e2..115fedbc9f7 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -297,6 +297,11 @@ L'eliminazione della corrispondenza dei criteri non è consentita per case di unione che non accetta dati. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 24ba5bac58c..75df71a3912 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -297,6 +297,11 @@ データを受け取らない共用体ケースでは、パターン一致の破棄は許可されません。 + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index d2cf0ff04f4..1b12cc06c5d 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -297,6 +297,11 @@ 데이터를 사용하지 않는 공용 구조체 사례에는 패턴 일치 삭제가 허용되지 않습니다. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 7aa10b8c4d3..8cdbb913169 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -297,6 +297,11 @@ Odrzucenie dopasowania wzorca jest niedozwolone w przypadku unii, która nie pobiera żadnych danych. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 9ba6d9c4fa4..5829e9e717e 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -297,6 +297,11 @@ O descarte de correspondência de padrão não é permitido para casos união que não aceitam dados. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index a712a17bea3..5603b300e9b 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -297,6 +297,11 @@ Отмена сопоставления с шаблоном не разрешена для случая объединения, не принимающего данные. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 93445c4a735..60b3404810b 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -297,6 +297,11 @@ Veri almayan birleşim durumu için desen eşleştirme atma kullanılamaz. + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 70470f5b02d..4b8fa0603b5 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -297,6 +297,11 @@ 不允许将模式匹配丢弃用于不采用数据的联合事例。 + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 2099c119ff4..8f455ebe91c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -297,6 +297,11 @@ 不接受資料的聯集案例不允許模式比對捨棄。 + + Allow modules to be used in type application + Allow modules to be used in type application + + nameof nameof diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs index a190d3d23ec..3355a6dd82c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs @@ -15,6 +15,18 @@ if actual <> expected then failwith $"Expected '{{expected}}', but got '{{actual |> compileAndRun |> shouldSucceed +[] +let ``Module cannot be used in typeof in lang version70`` () = + Fsx """ +let actual = typeof + """ + |> withLangVersion70 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 3350, Line 2, Col 21, Line 2, Col 27, "Feature 'Allow modules to be used in type application' is not available in F# 7.0. Please use language version 'PREVIEW' or greater.") + ] + [] let ``Module can be used as generic type argument in lang preview`` () = Fsx """ @@ -47,7 +59,7 @@ let _ = typeof let _ = typeof """ |> withLangVersionPreview - |> compile + |> typecheck |> shouldFail |> withDiagnostics [ (Error 39, Line 9, Col 23, Line 9, Col 25, "The module 'Ns' is not defined.") From 4754ad4ef3002cd48b500ced97720c360b18672f Mon Sep 17 00:00:00 2001 From: kerams Date: Tue, 31 Jan 2023 16:50:11 +0100 Subject: [PATCH 08/12] Include entire range --- src/Compiler/Checking/CheckExpressions.fs | 12 ++++++------ .../Service/ServiceInterfaceStubGenerator.fs | 2 +- src/Compiler/Service/ServiceParsedInputOps.fs | 6 +++--- src/Compiler/SyntaxTree/SyntaxTree.fs | 4 ++-- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 6 ++++-- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index d9aec7052d0..c24f4d832a9 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4298,8 +4298,8 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn | SynType.LongIdent synLongId -> TcLongIdentType kindOpt cenv newOk checkConstraints occ iwsam env tpenv synLongId - | SynType.LongIdentModule synLongId -> - TcLongIdentModule cenv checkConstraints occ env tpenv synLongId + | SynType.LongIdentModule (synLongId, m) -> + TcLongIdentModule cenv checkConstraints occ env tpenv synLongId m | MultiDimensionArrayType (rank, elemTy, m) -> TcElementType cenv newOk checkConstraints occ env tpenv rank elemTy m @@ -4369,18 +4369,18 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref = if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) -and TcLongIdentModule (cenv: cenv) checkConstraints occ (env: TcEnv) tpenv synLongId = +and TcLongIdentModule (cenv: cenv) checkConstraints occ (env: TcEnv) tpenv synLongId mAll = let (SynLongIdent (tc, _, _)) = synLongId - let m = synLongId.Range let id, rest = List.headAndTail tc + let mIdent = synLongId.Range let results = - ResolveLongIdentAsModule cenv.tcSink cenv.amap m true OpenQualified env.NameEnv env.eAccessRights id rest + ResolveLongIdentAsModule cenv.tcSink cenv.amap mIdent true OpenQualified env.NameEnv env.eAccessRights id rest |> ForceRaise match results with | [] -> failwith "unreachable" // handled in ResolveLongIdentAsModule above - | (_, tcref, _) :: _ -> TcTypeApp cenv NoNewTypars checkConstraints occ env tpenv m tcref [] [] + | (_, tcref, _) :: _ -> TcTypeApp cenv NoNewTypars checkConstraints occ env tpenv mAll tcref [] [] and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId = let (SynLongIdent(tc, _, _)) = synLongId diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 054c9a8a766..1faae5935f9 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -116,7 +116,7 @@ type InterfaceData = | TyparStaticReq.None -> Some("'" + s.idText) | TyparStaticReq.HeadType -> Some("^" + s.idText) | SynType.LongIdent (SynLongIdent (xs, _, _)) -> xs |> Seq.map (fun x -> x.idText) |> String.concat "." |> Some - | SynType.LongIdentModule (SynLongIdent (xs, _, _)) -> + | SynType.LongIdentModule (SynLongIdent (xs, _, _), _) -> let ident = xs |> Seq.map (fun x -> x.idText) |> String.concat "." Some(sprintf "module %s" ident) | SynType.App (t, _, ts, _, _, isPostfix, _) -> diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index ddcf70699d2..122962b95d3 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -664,7 +664,7 @@ module ParsedInput = and walkType ty = match ty with | SynType.LongIdent ident - | SynType.LongIdentModule ident -> + | SynType.LongIdentModule (ident, _) -> // we protect it with try..with because System.Exception : rangeOfLidwd may raise // at FSharp.Compiler.Syntax.LongIdentWithDots.get_Range() in D:\j\workspace\release_ci_pa---3f142ccc\src\ast.fs: line 156 try @@ -1316,7 +1316,7 @@ module ParsedInput = |> List.tryPick (fun arg -> match arg with | SynType.LongIdent lid when rangeContainsPos lid.Range pos -> Some CompletionContext.PatternType - | SynType.LongIdentModule lid when rangeContainsPos lid.Range pos -> Some CompletionContext.ModuleAsType + | SynType.LongIdentModule (lid, _) when rangeContainsPos lid.Range pos -> Some CompletionContext.ModuleAsType | _ -> None) |> Option.orElse (Some CompletionContext.PatternType) @@ -1691,7 +1691,7 @@ module ParsedInput = walkType t1 walkType t2 | SynType.LongIdent ident - | SynType.LongIdentModule ident -> addLongIdentWithDots ident + | SynType.LongIdentModule (ident, _) -> addLongIdentWithDots ident | SynType.App (ty, _, types, _, _, _, _) -> walkType ty List.iter walkType types diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index ed7cdab3561..b2e5dc74be1 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -393,7 +393,7 @@ type SynType = | LongIdent of longDotId: SynLongIdent - | LongIdentModule of longDotId: SynLongIdent + | LongIdentModule of longDotId: SynLongIdent * range: range | App of typeName: SynType * @@ -463,7 +463,7 @@ type SynType = | SynType.SignatureParameter (range = m) | SynType.Or (range = m) -> m | SynType.LongIdent lidwd -> lidwd.Range - | SynType.LongIdentModule lidwd -> lidwd.Range + | SynType.LongIdentModule (range = m) -> m [] type SynExpr = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index fde8d07e1be..4534dfebdf5 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -446,7 +446,7 @@ type SynType = | LongIdent of longDotId: SynLongIdent /// F# syntax: typeof - | LongIdentModule of longDotId: SynLongIdent + | LongIdentModule of longDotId: SynLongIdent * range: range /// F# syntax: type or type type or (type, ..., type) type /// isPostfix: indicates a postfix type application e.g. "int list" or "(int, string) dict" diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index e788434b888..48430a70ea9 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -5137,8 +5137,10 @@ tupleOrQuotTypeElements: appTypeCon: | moduleKeyword path %prec prec_atomtyp_path - { parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.ModulesInTypeApplication (rhs parseState 1) - SynType.LongIdentModule($2) } + { let mModule = rhs parseState 1 + parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.ModulesInTypeApplication mModule + let mAll = unionRanges mModule $2.Range + SynType.LongIdentModule($2, mAll) } | path %prec prec_atomtyp_path { SynType.LongIdent($1) } From 73690498d8bcdd6be8d88ea96400d5c1a9e00ea7 Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 4 Feb 2023 12:28:43 +0100 Subject: [PATCH 09/12] Fix test --- .../FSharp.Compiler.ComponentTests.fsproj | 1 - .../Language/ModuleAsTypeTests.fs | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index bad89f8b215..e0c52cdfe2e 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -240,7 +240,6 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs index 3355a6dd82c..3383b90376e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs @@ -3,10 +3,12 @@ open Xunit open FSharp.Test.Compiler -[] -let ``Module can be used in typeof in lang preview`` () = - Fsx """ -let actual = typeof.Name +[] +[] +[] +let ``Module can be used in typeof in lang preview`` (typeofKeyword: string) = + Fsx $""" +let actual = {typeofKeyword}.Name let expected = "LanguagePrimitives" if actual <> expected then failwith $"Expected '{{expected}}', but got '{{actual}}'" """ From e3cd6ab9f526ee3256c81915ea1ae4d406c3d7da Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 4 Feb 2023 13:05:55 +0100 Subject: [PATCH 10/12] Add error when used in annotation --- src/Compiler/Checking/CheckExpressions.fs | 9 ++++++--- src/Compiler/Checking/CheckPatterns.fs | 4 ++-- src/Compiler/Checking/NameResolution.fs | 4 +++- src/Compiler/Checking/NameResolution.fsi | 1 + src/Compiler/FSComp.txt | 1 + src/Compiler/Service/FSharpCheckerResults.fs | 6 +++++- src/Compiler/Service/SemanticClassification.fs | 1 + src/Compiler/SyntaxTree/LexFilter.fs | 4 ++-- src/Compiler/xlf/FSComp.txt.cs.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.de.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.es.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.fr.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.it.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.ja.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.ko.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.pl.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.ru.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.tr.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 8 +++++--- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 8 +++++--- .../Language/ModuleAsTypeTests.fs | 12 ++++++++++++ 22 files changed, 98 insertions(+), 48 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 30efbb45074..06dffcaa76b 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4370,6 +4370,9 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref = warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) and TcLongIdentModule (cenv: cenv) checkConstraints occ (env: TcEnv) tpenv synLongId mAll = + if occ = ItemOccurence.UseInTypeAnnotation then + error(Error(FSComp.SR.tcModuleUsedInTypeAnnotation(), mAll)) + let (SynLongIdent (tc, _, _)) = synLongId let id, rest = List.headAndTail tc let mIdent = synLongId.Range @@ -5738,7 +5741,7 @@ and TcExprMatchLambda (cenv: cenv) overallTy env tpenv (isExnMatch, mArg, clause overallExpr, tpenv and TcExprTypeAnnotated (cenv: cenv) overallTy env tpenv (synBodyExpr, synType, m) = - let tgtTy, tpenv = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv synType + let tgtTy, tpenv = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInTypeAnnotation WarnOnIWSAM.Yes env tpenv synType UnifyOverallType cenv env m overallTy tgtTy let bodyExpr, tpenv = TcExpr cenv (MustConvertTo (false, tgtTy)) env tpenv synBodyExpr let bodyExpr2 = TcAdjustExprForTypeDirectedConversions cenv overallTy tgtTy env m bodyExpr @@ -8008,7 +8011,7 @@ and TcNameOfExpr (cenv: cenv) env tpenv (synArg: SynExpr) = // expr : type" allowed with no subsequent qualifications | SynExpr.Typed (synBodyExpr, synType, _) when delayed.IsEmpty && overallTyOpt.IsNone -> - let tgtTy, _tpenv = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv synType + let tgtTy, _tpenv = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInTypeAnnotation WarnOnIWSAM.Yes env tpenv synType check (Some (MustEqual tgtTy)) resultOpt synBodyExpr delayed | _ -> @@ -11335,7 +11338,7 @@ and AnalyzeRecursiveDecl match pat with | SynPat.FromParseError(innerPat, _) -> analyzeRecursiveDeclPat tpenv innerPat | SynPat.Typed(innerPat, tgtTy, _) -> - let tgtTyR, tpenv = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes envinner tpenv tgtTy + let tgtTyR, tpenv = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInTypeAnnotation WarnOnIWSAM.Yes envinner tpenv tgtTy UnifyTypes cenv envinner mBinding ty tgtTyR analyzeRecursiveDeclPat tpenv innerPat | SynPat.Attrib(_innerPat, _attribs, m) -> diff --git a/src/Compiler/Checking/CheckPatterns.fs b/src/Compiler/Checking/CheckPatterns.fs index 88998544d52..4569d6eead6 100644 --- a/src/Compiler/Checking/CheckPatterns.fs +++ b/src/Compiler/Checking/CheckPatterns.fs @@ -97,7 +97,7 @@ and TcSimplePat optionalArgsOK checkConstraints (cenv: cenv) ty env patEnv p = id.idText, patEnvR | SynSimplePat.Typed (p, cty, m) -> - let ctyR, tpenv = TcTypeAndRecover cenv NewTyparsOK checkConstraints ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv cty + let ctyR, tpenv = TcTypeAndRecover cenv NewTyparsOK checkConstraints ItemOccurence.UseInTypeAnnotation WarnOnIWSAM.Yes env tpenv cty match p with // Optional arguments on members @@ -278,7 +278,7 @@ and TcPat warnOnUpper (cenv: cenv) env valReprInfo vFlags (patEnv: TcPatLinearEn | SynPat.Typed (p, cty, m) -> let (TcPatLinearEnv(tpenv, names, takenNames)) = patEnv - let ctyR, tpenvR = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInType WarnOnIWSAM.Yes env tpenv cty + let ctyR, tpenvR = TcTypeAndRecover cenv NewTyparsOK CheckCxs ItemOccurence.UseInTypeAnnotation WarnOnIWSAM.Yes env tpenv cty UnifyTypes cenv env m ty ctyR let patEnvR = TcPatLinearEnv(tpenvR, names, takenNames) TcPat warnOnUpper cenv env valReprInfo vFlags patEnvR ty p diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 8cbb3d26305..25e7983c9ed 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -1717,8 +1717,10 @@ type ItemOccurence = | Binding /// This is a usage of the item | Use - /// This is a usage of a type name in a type + /// This is a usage of a type name in a type, other than an annotation | UseInType + /// This is a usage of a type name in a type annotation + | UseInTypeAnnotation /// This is a usage of a type name in an attribute | UseInAttribute /// Inside pattern matching diff --git a/src/Compiler/Checking/NameResolution.fsi b/src/Compiler/Checking/NameResolution.fsi index 8db848190aa..ce5d60799aa 100755 --- a/src/Compiler/Checking/NameResolution.fsi +++ b/src/Compiler/Checking/NameResolution.fsi @@ -368,6 +368,7 @@ type internal ItemOccurence = | Binding | Use | UseInType + | UseInTypeAnnotation | UseInAttribute | Pattern | Implemented diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 8e316eb80cd..9a0faa10b0f 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1679,3 +1679,4 @@ featureEscapeBracesInFormattableString,"Escapes curly braces before calling Form 3558,chkExplicitFieldsDeclarationsOnStaticClasses,"If a type uses both [] and [] attributes, it means it is static. Explicit field declarations are not allowed." 3559,typrelNeverRefinedAwayFromTop,"A type has been implicitly inferred as 'obj', which may be unintended. Consider adding explicit type annotations. You can disable this warning by using '#nowarn \"3559\"' or '--nowarn:3559'." 3560,tcCopyAndUpdateRecordChangesAllFields,"This copy-and-update record expression changes all fields of record type '%s'. Consider using the record construction syntax instead." +3561,tcModuleUsedInTypeAnnotation,"Module references are intended to be used in 'typeof'." diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 8b89e3e708d..2e348a54374 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -236,7 +236,11 @@ type FSharpSymbolUse(denv: DisplayEnv, symbol: FSharpSymbol, inst: TyparInstanti member _.IsFromPattern = itemOcc = ItemOccurence.Pattern - member _.IsFromType = itemOcc = ItemOccurence.UseInType + member _.IsFromType = + match itemOcc with + | ItemOccurence.UseInType + | ItemOccurence.UseInTypeAnnotation -> true + | _ -> false member _.IsFromAttribute = itemOcc = ItemOccurence.UseInAttribute diff --git a/src/Compiler/Service/SemanticClassification.fs b/src/Compiler/Service/SemanticClassification.fs index f1fdc92c0bb..76d373405fc 100644 --- a/src/Compiler/Service/SemanticClassification.fs +++ b/src/Compiler/Service/SemanticClassification.fs @@ -148,6 +148,7 @@ module TcResolutionsExtensions = let (|LegitTypeOccurence|_|) occ = match occ with | ItemOccurence.UseInType + | ItemOccurence.UseInTypeAnnotation | ItemOccurence.UseInAttribute | ItemOccurence.Use | ItemOccurence.Binding diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 41e6fe22b6e..7b853a88cac 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1925,8 +1925,8 @@ type LexFilterImpl ( pushCtxt tokenTup (CtxtNamespaceHead (tokenStartPos, token)) returnToken tokenLexbufState token - // module ... ~~~> CtxtModuleHead - | MODULE, _ :: _ when offsideStack |> List.forall (fun x -> match x with CtxtParen (LESS _, _) -> false | _ -> true) -> + // module ... ~~~> CtxtModuleHead, unless we're in a type application + | MODULE, _ :: stack when stack |> List.forall (fun x -> match x with CtxtParen (LESS _, _) -> false | _ -> true) -> insertComingSoonTokens("MODULE", MODULE_COMING_SOON, MODULE_IS_HERE) if debug then dprintf "MODULE: entering CtxtModuleHead, awaiting EQUALS to go to CtxtSeqBlock (%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtModuleHead (tokenStartPos, token, NotLexingModuleAttributes)) diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index aaaf6d24dc1..f6a59fa2a0c 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -387,19 +387,16 @@ reprezentace struktury aktivních vzorů - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Vyvolá upozornění, když se použije „let inline ... =“ společně s atributem [<MethodImpl(MethodImplOptions.NoInlining)>]. Funkce není vkládána. @@ -1010,6 +1007,11 @@ Je třeba inicializovat následující požadované vlastnosti:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later Použití metod s atributem NoEagerConstraintApplicationAttribute vyžaduje /langversion:6.0 nebo novější. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index b500565f15d..238fd036649 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -387,19 +387,16 @@ Strukturdarstellung für aktive Muster - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Löst Warnungen aus, wenn „let inline ... =“ zusammen mit dem Attribut [<MethodImpl(MethodImplOptions.NoInlining)>] verwendet wird. Die Funktion wird nicht inline gesetzt. @@ -1010,6 +1007,11 @@ Die folgenden erforderlichen Eigenschaften müssen initialisiert werden:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later Die Verwendung von Methoden mit "NoEagerConstraintApplicationAttribute" erfordert /langversion:6.0 oder höher. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 519af025254..9edae45db31 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -387,19 +387,16 @@ representación de struct para modelos activos - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Genera advertencias cuando se usa "let inline ... =" junto con el atributo [<MethodImpl(MethodImplOptions.NoInlining)>]. La función no se está insertando. @@ -1010,6 +1007,11 @@ Se deben inicializar las siguientes propiedades necesarias:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later El uso de métodos con "NoEagerConstraintApplicationAttribute" requiere /langversion:6.0 o posteriores diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 44ab82976b3..e3efbf95f0d 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -387,19 +387,16 @@ représentation de structure pour les modèles actifs - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Génère des avertissements lorsque « let inline ... = » est utilisé avec l’attribut [<MethodImpl(MethodImplOptions.NoInlining)>]. La fonction n’est pas inlined. @@ -1010,6 +1007,11 @@ Les propriétés requises suivantes doivent être initialisées :{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later L’utilisation de méthodes avec « NoEagerConstraintApplicationAttribute » requiert/langversion:6.0 ou ultérieur diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 71ff03fb3da..7c53c7b4a52 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -387,19 +387,16 @@ rappresentazione struct per criteri attivi - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Genera avvisi quando 'let inline ... =' viene usato insieme all'attributo [<MethodImpl(MethodImplOptions.NoInlining)>]. La funzione non viene resa inline. @@ -1010,6 +1007,11 @@ È necessario inizializzare le proprietà obbligatorie seguenti:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later L'utilizzo di metodi con 'NoEagerConstraintApplicationAttribute' richiede /langversion: 6.0 o versione successiva diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index ae6653a4d43..290e264702a 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -387,19 +387,16 @@ アクティブなパターンの構造体表現 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 'let inline ... =' が [<MethodImpl(MethodImplOptions.NoInlining)>] 属性と一緒に使用されるときに警告を生成します。関数はインライン化されていません。 @@ -1010,6 +1007,11 @@ The following required properties have to be initalized:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later 'NoEagerConstraintApplicationAttribute' を指定してメソッドを使用するには、/langversion:6.0 以降が必要です diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 9ec1c18f79a..65bf09a500f 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -387,19 +387,16 @@ 활성 패턴에 대한 구조체 표현 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 'let inline ... ='을(를) [<MethodImpl(MethodImplOptions.NoInlining)>] 특성과 함께 사용하는 경우 경고를 발생합니다. 함수가 인라인되지 않습니다. @@ -1010,6 +1007,11 @@ 다음 필수 속성을 초기화해야 합니다. {0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later 'NoEagerConstraintApplicationAttribute'와 함께 메서드를 사용하려면 /langversion:6.0 이상이 필요합니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 72ea1776b1e..5f34a8f9a44 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -387,19 +387,16 @@ reprezentacja struktury aktywnych wzorców - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Zgłasza ostrzeżenia, gdy element „let inline ... =” jest używany razem z atrybutem [<MethodImpl(MethodImplOptions.NoInlining)>]. Funkcja nie jest wstawiana. @@ -1010,6 +1007,11 @@ Następujące wymagane właściwości muszą zostać zainicjowane:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later Używanie metod z atrybutem "NoEagerConstraintApplicationAttribute" wymaga parametru /langversion:6.0 lub nowszego diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 9b9898d7c7a..37f565eda34 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -387,19 +387,16 @@ representação estrutural para padrões ativos - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Gera avisos quando 'let inline ... =' é usado junto com o atributo [<MethodImpl(MethodImplOptions.NoInlining)>]. A função não está sendo embutida. @@ -1010,6 +1007,11 @@ As seguintes propriedades necessárias precisam ser inicializadas:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later Usar métodos com 'NoEagerConstraintApplicationAttribute' requer /langversion:6.0 ou posterior diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index c1124e9bddd..6174d2778b1 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -387,19 +387,16 @@ представление структуры для активных шаблонов - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. Выдает предупреждения, когда используется параметр "let inline ... =" вместе с атрибутом [<MethodImpl(MethodImplOptions.NoInlining)>]. Функция не встраивается. @@ -1010,6 +1007,11 @@ Необходимо инициализировать следующие обязательные свойства:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later Для использования методов с "NoEagerConstraintApplicationAttribute" требуется /langversion:6.0 или более поздняя версия diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index e7c18025b4d..b4fc5de036b 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -387,19 +387,16 @@ etkin desenler için yapı gösterimi - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. [<MethodImpl(MethodImplOptions.NoInlining)>] özniteliği ile birlikte 'let inline ... =' kullanıldığında uyarı verir. İşlev satır içine alınmıyor. @@ -1010,6 +1007,11 @@ Aşağıdaki gerekli özelliklerin başlatılması gerekiyor:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later 'NoEagerConstraintApplicationAttribute' içeren yöntemlerin kullanılması /langversion:6.0 veya üstünü gerektiriyor diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 36700ea3702..4ed19637bcf 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -387,19 +387,16 @@ 活动模式的结构表示形式 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 当 "let inline ... =" 与 [<MethodImpl(MethodImplOptions.NoInlining)>] 属性一起使用时引发警告。函数未内联。 @@ -1010,6 +1007,11 @@ 必须初始化以下必需属性: {0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later 将方法与 “NoEagerConstraintApplicationAttribute” 配合使用需要 /langversion:6.0 或更高版本 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 4c446861011..4e07a69fbbc 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -387,19 +387,16 @@ 現用模式的結構表示法 - Support for try-with in sequence expressions Support for try-with in sequence expressions - Raises warnings when an copy-and-update record expression changes all fields of a record. Raises warnings when an copy-and-update record expression changes all fields of a record. - Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined. 當 'let inline ... =' 與 [<MethodImpl(MethodImplOptions.NoInlining)>] 屬性一起使用時引發警告。函數未內嵌。 @@ -1010,6 +1007,11 @@ The following required properties have to be initalized:{0} + + Module references are intended to be used in 'typeof'. + Module references are intended to be used in 'typeof'. + + Using methods with 'NoEagerConstraintApplicationAttribute' requires /langversion:6.0 or later 使用具有 'NoEagerConstraintApplicationAttribute' 的方法需要 /langversion:6.0 或更新版本 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs index 3383b90376e..ea1643f8c99 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/ModuleAsTypeTests.fs @@ -29,6 +29,18 @@ let actual = typeof (Error 3350, Line 2, Col 21, Line 2, Col 27, "Feature 'Allow modules to be used in type application' is not available in F# 7.0. Please use language version 'PREVIEW' or greater.") ] +[] +let ``Module cannot be used in type annotation in lang preview`` () = + Fsx """ +let actual: module LanguagePrimitives = Unchecked.defaultof<_> + """ + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 3561, Line 2, Col 13, Line 2, Col 38, "Module references are intended to be used in 'typeof'.") + ] + [] let ``Module can be used as generic type argument in lang preview`` () = Fsx """ From fcae98184268f76eaa34ef435f3c45e6f782acad Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 4 Feb 2023 14:48:51 +0100 Subject: [PATCH 11/12] Fix tests --- src/Compiler/Service/ServiceParsedInputOps.fs | 3 ++- ...arp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl | 4 +++- ...p.Compiler.Service.SurfaceArea.netstandard20.release.bsl | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index d404151e6e5..931aa19e29f 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1316,7 +1316,8 @@ module ParsedInput = |> List.tryPick (fun arg -> match arg with | SynType.LongIdent lid when rangeContainsPos lid.Range pos -> Some CompletionContext.PatternType - | SynType.LongIdentModule (lid, _) when rangeContainsPos lid.Range pos -> Some CompletionContext.ModuleAsType + | SynType.LongIdentModule (lid, _) when rangeContainsPos lid.Range pos -> + Some CompletionContext.ModuleAsType | _ -> None) |> Option.orElse (Some CompletionContext.PatternType) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index 2226af824ef..964800ff258 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -8400,6 +8400,8 @@ FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption` FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] lessRange FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst exponent FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst get_exponent() FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynType baseMeasure @@ -8523,7 +8525,7 @@ FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewFun(FSharp.Com FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewHashConstraint(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdent(FSharp.Compiler.Syntax.SynLongIdent) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentApp(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynLongIdent, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynType], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentModule(FSharp.Compiler.Syntax.SynLongIdent) +FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentModule(FSharp.Compiler.Syntax.SynLongIdent, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewMeasurePower(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewOr(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynTypeOrTrivia) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewParen(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index 7114cda0e9b..964800ff258 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -8384,8 +8384,6 @@ FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range get_ra FSharp.Compiler.Syntax.SynType+HashConstraint: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdent: FSharp.Compiler.Syntax.SynLongIdent longDotId -FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() -FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynLongIdent longDotId FSharp.Compiler.Syntax.SynType+LongIdentApp: FSharp.Compiler.Syntax.SynType get_typeName() @@ -8402,6 +8400,8 @@ FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption` FSharp.Compiler.Syntax.SynType+LongIdentApp: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] lessRange FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent get_longDotId() FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Syntax.SynLongIdent longDotId +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynType+LongIdentModule: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst exponent FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynRationalConst get_exponent() FSharp.Compiler.Syntax.SynType+MeasurePower: FSharp.Compiler.Syntax.SynType baseMeasure @@ -8525,7 +8525,7 @@ FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewFun(FSharp.Com FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewHashConstraint(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdent(FSharp.Compiler.Syntax.SynLongIdent) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentApp(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynLongIdent, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynType], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentModule(FSharp.Compiler.Syntax.SynLongIdent) +FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewLongIdentModule(FSharp.Compiler.Syntax.SynLongIdent, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewMeasurePower(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewOr(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynTypeOrTrivia) FSharp.Compiler.Syntax.SynType: FSharp.Compiler.Syntax.SynType NewParen(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Text.Range) From c4d66c9c8249ef52c0ac71f2c97186d666b9c401 Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 4 Feb 2023 16:29:26 +0100 Subject: [PATCH 12/12] Add range correctness assertions --- tests/service/SyntaxTreeTests/SynTypeTests.fs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/service/SyntaxTreeTests/SynTypeTests.fs b/tests/service/SyntaxTreeTests/SynTypeTests.fs index 7f18521a995..ffb2910668c 100644 --- a/tests/service/SyntaxTreeTests/SynTypeTests.fs +++ b/tests/service/SyntaxTreeTests/SynTypeTests.fs @@ -205,3 +205,22 @@ let inline f (x: 'T) = ((^T or int) : (static member A: int) ()) assertRange (2,25) (2, 34) mOrType assertRange (2,24) (2, 35) mParen | _ -> Assert.Fail $"Could not get valid AST, got {parseResults}" + +[] +let ``SynType.LongIdentModule includes the module keyword in its range`` () = + let parseResults = + getParseResults + """ +let t = typeof + """ + + match parseResults with + | ParsedInput.ImplFile (ParsedImplFileInput (contents = [ SynModuleOrNamespace.SynModuleOrNamespace(decls = [ + SynModuleDecl.Let(bindings = [ + SynBinding(expr = + SynExpr.TypeApp(typeArgs = [ SynType.LongIdentModule(synLongIdent, fullRange) ]) + ) + ]) ]) ])) -> + assertRange (2, 15) (2, 40) fullRange + assertRange (2, 22) (2, 40) synLongIdent.Range + | _ -> Assert.Fail $"Could not get valid AST, got {parseResults}"