diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md index 88cabb5af7b..14fdea1517b 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md @@ -17,6 +17,7 @@ * Completion: fix previous namespace considered opened [PR #18609](https://github.com/dotnet/fsharp/pull/18609) * Fix active pattern typechecking regression. ([Issue #18638](https://github.com/dotnet/fsharp/issues/18638), [PR #18642](https://github.com/dotnet/fsharp/pull/18642)) * Fix nullness warnings when casting non-nullable values to `IEquatable` to match C# behavior. ([Issue #18759](https://github.com/dotnet/fsharp/issues/18759)) +* Error on invalid declarations in type definitions.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) * Fix IsByRefLikeAttribute types being incorrectly suppressed in completion lists. Types like `Span` and `ReadOnlySpan` now appear correctly in IntelliSense. * Fix SRTP nullness constraint resolution for types imported from older assemblies. AmbivalentToNull types now use legacy F# nullness rules instead of always satisfying `'T : null` constraints. ([Issue #18390](https://github.com/dotnet/fsharp/issues/18390), [Issue #18344](https://github.com/dotnet/fsharp/issues/18344)) * Fix Show XML doc for enum fields in external metadata ([Issue #17939](https://github.com/dotnet/fsharp/issues/17939#issuecomment-3137410105), [PR #18800](https://github.com/dotnet/fsharp/pull/18800)) diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index b9afee7582e..fcec4b8170e 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -15,5 +15,6 @@ ### Fixed * Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816)) +* Error on invalid declarations in type definitions.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) ### Changed diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 1f2dc3cfb3c..4e3c9f81b45 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1005,6 +1005,11 @@ lexhlpIdentifierReserved,"The identifier '%s' is reserved for future use by F#" lexfltIncorrentIndentationOfIn,"The indentation of this 'in' token is incorrect with respect to the corresponding 'let'" lexfltTokenIsOffsideOfContextStartedEarlier,"Unexpected syntax or possible incorrect indentation: this token is offside of context started at position %s. Try indenting this further.\nTo continue using non-conforming indentation, pass the '--strict-indentation-' flag to the compiler, or set the language version to F# 7." lexfltSeparatorTokensOfPatternMatchMisaligned,"The '|' tokens separating rules of this pattern match are misaligned by one column. Consider realigning your code or using further indentation." +lexfltInvalidNestedTypeDefinition,"Nested type definitions are not allowed. Types must be defined at module or namespace level." +lexfltInvalidNestedModule,"Modules cannot be nested inside types. Define modules at module or namespace level." +lexfltInvalidNestedExceptionDefinition,"Exceptions must be defined at module level, not inside types." +lexfltInvalidNestedOpenDeclaration,"'open' declarations must appear at module level, not inside types." +lexfltInvalidNestedConstruct,"'%s' must be defined at module level, not inside a type." 1123,nrInvalidModuleExprType,"Invalid module/expression/type" 1124,nrTypeInstantiationNeededToDisambiguateTypesWithSameName,"Multiple types exist called '%s', taking different numbers of generic parameters. Provide a type instantiation to disambiguate the type resolution, e.g. '%s'." 1125,nrTypeInstantiationIsMissingAndCouldNotBeInferred,"The instantiation of the generic type '%s' is missing and can't be inferred from the arguments or return type of this member. Consider providing a type instantiation when accessing this type, e.g. '%s'." @@ -1802,6 +1807,7 @@ featureSupportWarnWhenUnitPassedToObjArg,"Warn when unit is passed to a member a featureUseBangBindingValueDiscard,"Allows use! _ = ... in computation expressions" featureBetterAnonymousRecordParsing,"Support for better anonymous record parsing" featureScopedNowarn,"Support for scoped enabling / disabling of warnings by #warn and #nowarn directives, also inside modules" +featureErrorOnInvalidDeclsInTypeDefinitions,"Error when invalid declarations are used in type definitions." featureAllowLetOrUseBangTypeAnnotationWithoutParens,"Allow let! and use! type annotations without requiring parentheses" 3874,lexWarnDirectiveMustBeFirst,"#nowarn/#warnon directives must appear as the first non-whitespace characters on a line" 3875,lexWarnDirectiveMustHaveArgs,"Warn directives must have warning number(s) as argument(s)" diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 9e57e5b96af..4b032db713f 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -102,6 +102,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn + | ErrorOnInvalidDeclsInTypeDefinitions | AllowTypedLetUseAndBang | ReturnFromFinal @@ -240,6 +241,7 @@ type LanguageVersion(versionText) = LanguageFeature.UnmanagedConstraintCsharpInterop, languageVersion100 LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, languageVersion100 LanguageFeature.ReturnFromFinal, languageVersion100 + LanguageFeature.ErrorOnInvalidDeclsInTypeDefinitions, languageVersion100 // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work @@ -410,6 +412,7 @@ type LanguageVersion(versionText) = | LanguageFeature.UseBangBindingValueDiscard -> FSComp.SR.featureUseBangBindingValueDiscard () | LanguageFeature.BetterAnonymousRecordParsing -> FSComp.SR.featureBetterAnonymousRecordParsing () | LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn () + | LanguageFeature.ErrorOnInvalidDeclsInTypeDefinitions -> FSComp.SR.featureErrorOnInvalidDeclsInTypeDefinitions () | LanguageFeature.AllowTypedLetUseAndBang -> FSComp.SR.featureAllowLetOrUseBangTypeAnnotationWithoutParens () | LanguageFeature.ReturnFromFinal -> FSComp.SR.featureReturnFromFinal () diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 2e123eb1593..1217b83baf6 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -93,6 +93,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn + | ErrorOnInvalidDeclsInTypeDefinitions | AllowTypedLetUseAndBang | ReturnFromFinal diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 1fb62e72940..e74f514f812 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1368,6 +1368,98 @@ type LexFilterImpl ( if debug then dprintf "inserting %+A\n" tok returnToken (lexbufStateForInsertedDummyTokens (startPosOfTokenTup tokenTup, tokenTup.LexbufState.EndPos)) tok + // Check if we're inappropriately inside a type definition for constructs that shouldn't be there + // This validates that TYPE, MODULE, EXCEPTION, and OPEN declarations are not nested within type definitions + // The check works as follows: + // 1. Only check if the language feature WarnOnUnexpectedModuleDefinitionsInsideTypes is enabled + // 2. Skip validation inside parentheses (to avoid false positives with inline IL) + // 3. Traverse the context stack looking for a CtxtTypeDefns + // 4. If found, check if the current token is indented INSIDE it (greater column, not equal) + // 5. Verify we're not in a legitimate nested context (members, augmentations, or escaped to module/namespace) + // 6. If all conditions match, issue an error message + // + // Note: We don't check 'let' bindings as they can be valid in classes with constructors + // Note: Constructs at the same column level are NOT nested (e.g., type A = A type B = B on same line) + let checkForInvalidDeclsInTypeDefn keyword = + if lexbuf.SupportsFeature LanguageFeature.ErrorOnInvalidDeclsInTypeDefinitions then + // Skip validation if we're inside a parenthesis context + // This avoids false positives with inline IL: (# "unbox.any !0" type ('T) x : 'T #) + let rec hasParenContext stack = + match stack with + | [] -> false + | CtxtParen _ :: _ -> true + | CtxtSeqBlock _ :: rest + | CtxtVanilla _ :: rest -> hasParenContext rest + | _ -> false + + // Don't validate if we're in a paren context (could be inline IL or other valid syntax) + if not (hasParenContext offsideStack) then + // Find the nearest type definition context and check if we're inappropriately nested + let rec checkNesting stack typeDefnsSeen = + match stack with + | [] -> + // We've traversed the whole stack without finding issues + false + + | CtxtModuleBody _ :: _ + | CtxtNamespaceBody _ :: _ -> + // We've escaped to module/namespace level - constructs here are OK + false + + | CtxtTypeDefns(typePos, _) :: rest -> + // Found a type definition - check if we're inappropriately inside it + // IMPORTANT: Same-line declarations are sequential, not nested + // Example: type A = A type B = B (all on same line, B is not nested in A) + // Only warn if on a DIFFERENT line with GREATER indentation + if tokenStartPos.Line > typePos.Line && tokenStartCol > typePos.Column then + // We're indented inside the type - this might be invalid + // But first check if we're in a valid member/augmentation context + let rec isInMemberContext s = + match s with + | [] -> false + | CtxtMemberHead _ :: _ + | CtxtMemberBody _ :: _ -> true + | CtxtWithAsAugment _ :: _ -> true // Type augmentation with 'with' + | CtxtSeqBlock _ :: tail + | CtxtVanilla _ :: tail -> isInMemberContext tail + | _ -> false + + not (isInMemberContext stack) + else + // Not indented inside this type (same column or less), check deeper in the stack + checkNesting rest true + + | CtxtSeqBlock _ :: rest + | CtxtVanilla _ :: rest + | CtxtParen _ :: rest -> + // Transparent contexts - continue checking + checkNesting rest typeDefnsSeen + + | CtxtMemberHead _ :: _ + | CtxtMemberBody _ :: _ when typeDefnsSeen -> + // We're in a member context after seeing a type - this is OK + false + + | _ :: rest -> + // Other contexts - continue checking + checkNesting rest typeDefnsSeen + + if checkNesting offsideStack false then + let errorMessage = + match keyword with + | "TYPE" -> + FSComp.SR.lexfltInvalidNestedTypeDefinition() + | "MODULE" -> + FSComp.SR.lexfltInvalidNestedModule() + | "EXCEPTION" -> + FSComp.SR.lexfltInvalidNestedExceptionDefinition() + | "OPEN" -> + FSComp.SR.lexfltInvalidNestedOpenDeclaration() + | _ -> + FSComp.SR.lexfltInvalidNestedConstruct(keyword) + + error tokenTup errorMessage + let isSemiSemi = match token with SEMICOLON_SEMICOLON -> true | _ -> false let relaxWhitespace2OffsideRule = // Offside rule for CtxtLetDecl (in types or modules) / CtxtMemberHead / CtxtTypeDefns... (given RelaxWhitespace2) @@ -2019,7 +2111,11 @@ type LexFilterImpl ( returnToken tokenLexbufState token // module ... ~~~> CtxtModuleHead + // Check for inappropriate nesting within type definitions | MODULE, _ :: _ -> + // Check if this module definition is inappropriately nested in a type + checkForInvalidDeclsInTypeDefn "MODULE" + 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 let isNested = match offsideStack with | [ CtxtSeqBlock _ ] -> false | _ -> true @@ -2029,6 +2125,8 @@ type LexFilterImpl ( // exception ... ~~~> CtxtException | EXCEPTION, _ :: _ -> + // Check if this exception definition is inappropriately nested in a type + checkForInvalidDeclsInTypeDefn "EXCEPTION" if debug then dprintf "EXCEPTION: entering CtxtException(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtException tokenStartPos) returnToken tokenLexbufState token @@ -2470,6 +2568,9 @@ type LexFilterImpl ( returnToken tokenLexbufState token | TYPE, _ -> + // Check if this type definition is inappropriately nested in another type + checkForInvalidDeclsInTypeDefn "TYPE" + insertComingSoonTokens("TYPE", TYPE_COMING_SOON, TYPE_IS_HERE) if debug then dprintf "TYPE, pushing CtxtTypeDefns(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtTypeDefns(tokenStartPos, None)) @@ -2490,6 +2591,11 @@ type LexFilterImpl ( | OBLOCKBEGIN, _ -> returnToken tokenLexbufState token + | OPEN, _ :: _ -> + // Check if this open declaration is inappropriately nested in a type + checkForInvalidDeclsInTypeDefn "OPEN" + returnToken tokenLexbufState token + | ODUMMY _, _ -> if debug then dprintf "skipping dummy token as no offside rules apply\n" pool.Return tokenTup diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fsi b/src/Compiler/SyntaxTree/ParseHelpers.fsi index f1b91b1f64f..301e72e0ed7 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fsi +++ b/src/Compiler/SyntaxTree/ParseHelpers.fsi @@ -7,6 +7,7 @@ open FSharp.Compiler.Syntax open FSharp.Compiler.SyntaxTrivia open FSharp.Compiler.Features open FSharp.Compiler.Text +open FSharp.Compiler.UnicodeLexing open FSharp.Compiler.Xml open Internal.Utilities.Text.Lexing open Internal.Utilities.Text.Parsing diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index a8225213eb6..99da176d18e 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -1271,6 +1271,9 @@ moduleDefnsOrExpr: /* A sequence of definitions in a namespace or module */ moduleDefns: + | moduleDefnOrDirective moduleDefnOrDirective + { $1 @ $2 } + | moduleDefnOrDirective moduleDefns { $1 @ $2 } diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 7333400397b..43fadb51613 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -397,6 +397,11 @@ chyba při zastaralém přístupu konstruktoru s atributem RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Vytváření sestav chyb u statických tříd @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Všechny prvky seznamu musí být implicitně převoditelné na typ prvního prvku, což je řazená kolekce členů o délce {0} typu\n {1} \nTento element je řazená kolekce členů o délce {2} typu\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index ea6271cfbcb..19163652970 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -397,6 +397,11 @@ Beim veralteten Zugriff auf das Konstrukt mit dem RequireQualifiedAccess-Attribut wird ein Fehler ausgegeben. + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Fehlerberichterstattung für statische Klassen @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Alle Elemente einer Liste müssen implizit in den Typ des ersten Elements konvertiert werden. Hierbei handelt es sich um ein Tupel der Länge {0} vom Typ\n {1} \nDieses Element ist ein Tupel der Länge {2} vom Typ\n {3}. \n diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 6abcce332e0..b0f3f478be9 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -397,6 +397,11 @@ error en el acceso en desuso de la construcción con el atributo RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Informe de errores en clases estáticas @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Todos los elementos de una lista deben convertirse implícitamente en el tipo del primer elemento, que aquí es una tupla de longitud {0} de tipo\n {1} \nEste elemento es una tupla de longitud {2} de tipo\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 4eb06dccb14..1625dc18b6e 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -397,6 +397,11 @@ donner une erreur sur l’accès déconseillé de la construction avec l’attribut RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Rapport d’erreurs sur les classes statiques @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Tous les éléments d’une liste doivent être implicitement convertibles en type du premier élément, qui est ici un tuple de longueur {0} de type\n {1} \nCet élément est un tuple de longueur {2} de type\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 4e48e1db287..8286e205589 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -397,6 +397,11 @@ errore durante l'accesso deprecato del costrutto con l'attributo RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Segnalazione errori nelle classi statiche @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Tutti gli elementi di un elenco devono essere convertibili in modo implicito nel tipo del primo elemento, che qui è una tupla di lunghezza {0} di tipo\n {1} \nQuesto elemento è una tupla di lunghezza {2} di tipo\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 295256c5cf4..91f36d4b2b0 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -397,6 +397,11 @@ RequireQualifiedAccess 属性を持つコンストラクトの非推奨アクセスでエラーが発生しました + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes 静的クラスに関するエラー報告 @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n リストのすべての要素は、最初の要素の型に暗黙的に変換できる必要があります。これは、型の長さ {0} のタプルです\n {1} \nこの要素は、型の長さ {2} のタプルです\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 7ab04d5a12a..c40e1df22a4 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -397,6 +397,11 @@ RequireQualifiedAccess 특성을 사용하여 사용되지 않는 구문 액세스에 대한 오류 제공 + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes 정적 클래스에 대한 오류 보고 @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n 목록의 모든 요소는 첫 번째 요소의 형식으로 암시적으로 변환할 수 있어야 합니다. 여기서는 형식이 \n {1}이고 길이가 {0}인 튜플입니다. \n이 요소는 형식이 \n {3}이고 길이가 {2}인 튜플입니다. \n diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index b31f4083071..c5d3c30a710 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -397,6 +397,11 @@ wskazywanie błędu w przypadku przestarzałego dostępu do konstrukcji z atrybutem RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Raportowanie błędów dla klas statycznych @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Wszystkie elementy tablicy muszą być niejawnie konwertowalne na typ pierwszego elementu, który w tym miejscu jest krotką o długości {0} typu\n {1} \nTen element jest krotką o długości {2} typu\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 3e544e2f90c..715f6bc778f 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -397,6 +397,11 @@ fornecer erro no acesso preterido do constructo com o atributo RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Relatório de erros em classes estáticas @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Todos os elementos de uma lista devem ser implicitamente conversíveis ao tipo do primeiro elemento, que aqui é uma tupla de comprimento {0} do tipo\n {1} \nEste elemento é uma tupla de comprimento {2} do tipo\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 75f9c8dadc7..01fa5d498bb 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -397,6 +397,11 @@ выдать ошибку при устаревшем доступе к конструкции с атрибутом RequireQualifiedAccess + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Отчеты об ошибках для статических классов @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Все элементы списка должны поддерживать неявное преобразование в тип первого элемента, который здесь является кортежем длиной {0} типа\n {1} \nЭтот элемент является кортежем длиной {2} типа\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 66166fd9023..fbce9ee4662 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -397,6 +397,11 @@ RequireQualifiedAccess özniteliğine sahip yapının kullanım dışı erişiminde hata + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes Statik sınıflarda hata bildirimi @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n Bir listenin tüm öğeleri örtük olarak ilk öğenin türüne dönüştürülebilir olmalıdır. Burada ilk öğe {0} uzunluğunda türü\n {1} \nolan bir demet. Bu öğe ise {2} uzunluğunda türü\n {3} \nolan bir demet. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 50981ab1e98..224b515560d 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -397,6 +397,11 @@ 对具有 RequireQualifiedAccess 属性的构造进行弃用的访问时出错 + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes 有关静态类的错误报告 @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n 列表的所有元素必须可隐式转换为第一个元素的类型,这是一个长度为 {0} 的类型的元组\n {1} \n此元素是长度为 {2} 类型的元组\n {3} \n diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index aa2c95dbd4b..f5129e2f03a 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -397,6 +397,11 @@ 對具有 RequireQualifiedAccess 屬性的建構的已取代存取發出錯誤 + + Error when invalid declarations are used in type definitions. + Error when invalid declarations are used in type definitions. + + Error reporting on static classes 報告靜態類別時發生錯誤 @@ -907,6 +912,31 @@ There is another {0} for this warning already in line {1}. + + '{0}' must be defined at module level, not inside a type. + '{0}' must be defined at module level, not inside a type. + + + + Exceptions must be defined at module level, not inside types. + Exceptions must be defined at module level, not inside types. + + + + Modules cannot be nested inside types. Define modules at module or namespace level. + Modules cannot be nested inside types. Define modules at module or namespace level. + + + + 'open' declarations must appear at module level, not inside types. + 'open' declarations must appear at module level, not inside types. + + + + Nested type definitions are not allowed. Types must be defined at module or namespace level. + Nested type definitions are not allowed. Types must be defined at module or namespace level. + + All elements of a list must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n 清單的所有元素必須以隱含方式轉換成第一個元素的類型,這是類型為\n {1} \n的元組長度 {0}此元素是類型為\n {3} \n的元組長度 {2} diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs index c2246d10722..48104bf42ef 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -234,21 +234,7 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Warning 842, Line 12, Col 6, Line 12, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 15, Col 6, Line 15, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 18, Col 6, Line 18, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 20, Col 10, Line 20, Col 20, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 22, Col 6, Line 22, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 25, Col 6, Line 25, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 28, Col 6, Line 28, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 31, Col 6, Line 31, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 34, Col 6, Line 34, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 37, Col 6, Line 37, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 39, Col 10, Line 39, Col 20, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 41, Col 6, Line 41, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 44, Col 6, Line 44, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 47, Col 6, Line 47, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") - (Warning 842, Line 52, Col 6, Line 52, Col 16, "This attribute cannot be applied to property, field, return value. Valid targets are: method") + (Error 58, Line 50, Col 4, Line 50, Col 8, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") ] // SOURCE=E_AttributeTargetIsMethod04.fs # E_AttributeTargetIsMethod04.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs index 449fb5bd9d3..b8e86960969 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs @@ -60,6 +60,7 @@ module ImportDeclarations = |> verifyCompile |> shouldFail |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 9, "'open' declarations must appear at module level, not inside types.") (Error 10, Line 7, Col 5, Line 7, Col 9, "Unexpected keyword 'open' in member definition") ] @@ -72,6 +73,7 @@ module ImportDeclarations = |> withDiagnostics [ (Error 10, Line 9, Col 5, Line 9, Col 9, "Unexpected keyword 'open' in binding. Expected incomplete structured construct at or before this point or other token.") (Error 10, Line 17, Col 9, Line 17, Col 13, "Unexpected keyword 'open' in binding") + (Error 58, Line 23, Col 9, Line 23, Col 13, "'open' declarations must appear at module level, not inside types.") (Error 10, Line 23, Col 9, Line 23, Col 13, "Unexpected keyword 'open' in expression") (Error 3567, Line 23, Col 9, Line 23, Col 13, "Expecting member body") ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs index f6a70f9c71d..0d08b96bd8f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs @@ -1217,21 +1217,11 @@ type TestType () = static member HiddenMethod() = ()""")) |> asLibrary |> withRealInternalSignature realSig - |> compile - |> verifyILContains [ - if realSig then - ".method public static void PublicMethod() cil managed" - ".method assembly static void InternalMethod() cil managed" - ".method assembly static void PrivateMethod() cil managed" - ".method assembly static void DefaultMethod() cil managed" - ".method assembly static void HiddenMethod() cil managed" - else - ".method public static void PublicMethod() cil managed" - ".method assembly static void InternalMethod() cil managed" - ".method assembly static void PrivateMethod() cil managed" - ".method assembly static void DefaultMethod() cil managed" - ".method assembly static void HiddenMethod() cil managed" - - ] - |> shouldSucceed + |> typecheck + |> withDiagnostics [ + (Error 10, Line 4, Col 12, Line 4, Col 13, "Unexpected symbol ':' in member definition"); + (Error 58, Line 5, Col 9, Line 5, Col 13, "Nested type definitions are not allowed. Types must be defined at module or namespace level."); + (Error 3567, Line 6, Col 23, Line 6, Col 25, "Expecting member body"); + (Error 3567, Line 7, Col 1, Line 7, Col 53, "Expecting member body") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs new file mode 100644 index 00000000000..a9ea57ad5b7 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs @@ -0,0 +1,808 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. +namespace ErrorMessages + +open Xunit +open FSharp.Test.Compiler + +module ErrorOnInvalidDeclsInTypeDefinitions = + module ``Module inside interface`` = + [] + let ``Error when module is inside interface``() = + Fsx """ +module TestModule + +type IFace = + abstract F : int -> int + module M = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``Version10: Error when module is inside interface verbose syntax``() = + Fsx """ +module TestModule + +type IFace = + interface + abstract F : int -> int + module M = + let f () = f () + end + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 546, Line 5, Col 5, Line 5, Col 14, "Unmatched 'class', 'interface' or 'struct'"); + (Error 10, Line 7, Col 9, Line 7, Col 15, "Unexpected keyword 'module' in member definition"); + (Error 10, Line 9, Col 5, Line 9, Col 8, "Incomplete structured construct at or before this point in definition. Expected incomplete structured construct at or before this point or other token.") + ] + + [] + let ``Error when module is inside interface verbose syntax``() = + Fsx """ +module TestModule + +type IFace = + interface + abstract F : int -> int + module M = + let f () = f () + end + """ + |> withLangVersion90 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 546, Line 5, Col 5, Line 5, Col 14, "Unmatched 'class', 'interface' or 'struct'"); + (Error 10, Line 7, Col 9, Line 7, Col 15, "Unexpected keyword 'module' in member definition"); + (Error 10, Line 9, Col 5, Line 9, Col 8, "Incomplete structured construct at or before this point in definition. Expected incomplete structured construct at or before this point or other token.") + ] + + [] + let ``No Error when module is inside interface``() = + Fsx """ +module TestModule + +type IFace = + abstract F : int -> int + module M = + let f () = () + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module inside class`` = + [] + let ``Error when module is inside class``() = + Fsx """ +module TestModule + +type C () = + member _.F () = 3 + module M2 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module is inside class``() = + Fsx """ +module TestModule + +type C () = + member _.F () = 3 + module M2 = + let f () = () + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + + module ``Module inside class with constructor`` = + [] + let ``Error when module is inside class with constructor``() = + Fsx """ +module TestModule + +type MyClass(x: int) = + let mutable value = x + member _.Value = value + module InternalModule = + let helper() = 42 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module is inside class with constructor``() = + Fsx """ +module TestModule + +type MyClass(x: int) = + let mutable value = x + member _.Value = value + module InternalModule = + let helper() = 42 + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module inside union`` = + [] + let ``Error when module is inside discriminated union``() = + Fsx """ +module TestModule + +type U = + | A + | B + module M3 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module is inside discriminated union``() = + Fsx """ +module TestModule + +type U = + | A + | B + module M3 = + let f () = () + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module inside record`` = + [] + let ``Error when module is inside record``() = + Fsx """ +module TestModule + +type R = + { A : int } + module M4 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module is inside record``() = + Fsx """ +module TestModule + +type R = + { A : int } + module M4 = + let f () = () + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module inside struct`` = + [] + let ``Error when module is inside struct``() = + Fsx """ +module TestModule + +[] +type MyStruct = + val X: int + val Y: int + module InvalidModule = + let helper = 10 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module is inside struct``() = + Fsx """ +module TestModule + +[] +type MyStruct = + val X: int + val Y: int + module InvalidModule = + let helper = 10 + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module after delegate`` = + [] + let ``Error when module appears after delegate``() = + Fsx """ +module TestModule + +type MyDelegate = delegate of int * int -> int + module InvalidModule = + let x = 1 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 5, Col 5, Line 5, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module appears after delegate``() = + Fsx """ +module TestModule + +type MyDelegate = delegate of int * int -> int + module InvalidModule = + let x = 1 + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module after type members`` = + [] + let ``Error when module appears after type members``() = + Fsx """ +module TestModule + +type ClassWithMembers() = + member _.Method1() = 1 + member _.Method2() = 2 + member _.Property = 3 + module LateModule = + let x = 4 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module appears after type members``() = + Fsx """ +module TestModule + +type ClassWithMembers() = + member _.Method1() = 1 + member _.Method2() = 2 + member _.Property = 3 + module LateModule = + let x = 4 + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module after static members`` = + [] + let ``Error when module appears after static members``() = + Fsx """ +module TestModule + +type ClassWithStatic() = + static member StaticMethod() = 1 + static member StaticProperty = 2 + module InvalidModule = + let x = 3 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error when module appears after static members``() = + Fsx """ +module TestModule + +type ClassWithStatic() = + static member StaticMethod() = 1 + static member StaticProperty = 2 + module InvalidModule = + let x = 3 + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + module ``Exception inside type`` = + [] + let ``Error when exception is inside type``() = + Fsx """ +module TestModule + +type A = + | A + exception MyException of string + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 14, "Exceptions must be defined at module level, not inside types."); + (Error 10, Line 6, Col 5, Line 6, Col 14, "Unexpected keyword 'exception' in member definition") + ] + + [] + let ``No Error when exception is inside type``() = + Fsx """ +module TestModule + +type A = + | A + exception MyException of string + """ + |> withLangVersion90 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 10, Line 6, Col 5, Line 6, Col 14, "Unexpected keyword 'exception' in member definition") + ] + + module ``Open inside type`` = + [] + let ``Error when open declaration is inside type``() = + Fsx """ +module TestModule + +type A = + | A + open System + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 9, "'open' declarations must appear at module level, not inside types.") + (Error 10, Line 6, Col 5, Line 6, Col 9, "Unexpected keyword 'open' in member definition") + ] + + [] + let ``No Error when open declaration is inside type``() = + Fsx """ +module TestModule + +type A = + | A + open System + """ + |> withLangVersion90 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 10, Line 6, Col 5, Line 6, Col 9, "Unexpected keyword 'open' in member definition") + ] + + module ``Type inside type`` = + [] + let ``Error when type is nested inside another type``() = + Fsx """ +module TestModule + +type OuterType = + | Case1 + | Case2 + type InnerType = int + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + ] + + [] + let ``No Error when type is nested inside another type``() = + Fsx """ +module TestModule + +type OuterType = + | Case1 + | Case2 + type InnerType = int + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Multiple invalid constructs`` = + [] + let ``Error for all invalid nested constructs in single type``() = + Fsx """ +module TestModule + +type MultiTest = + | Case1 + | Case2 + module NestedModule = begin end + type NestedType = int + exception NestedExc of string + open System.Collections + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 8, Col 5, Line 8, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + (Error 58, Line 9, Col 5, Line 9, Col 14, "Exceptions must be defined at module level, not inside types.") + (Error 58, Line 10, Col 5, Line 10, Col 9, "'open' declarations must appear at module level, not inside types.") + ] + + [] + let ``No Error for all invalid nested constructs in single type``() = + Fsx """ +module TestModule + +type MultiTest = + | Case1 + | Case2 + module NestedModule = begin end + type NestedType = int + exception NestedExc of string + open System.Collections + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Multiple modules in single type`` = + [] + let ``Error for each module inside type``() = + Fsx """ +module TestModule + +type B = + | B + module M1 = begin end + module M2 = begin end + module M3 = begin end + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error for each module inside type``() = + Fsx """ +module TestModule + +type B = + | B + module M1 = begin end + module M2 = begin end + module M3 = begin end + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Deeply nested invalid constructs`` = + [] + let ``Error for invalid constructs in deeply nested context``() = + Fsx """ +module OuterModule + +module InnerModule = + module DeeplyNested = + type IndentedType = + | Case1 + | Case2 + type NestedType = int + module NestedModule = + let x = 1 + exception NestedExc of string + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 9, Col 13, Line 9, Col 17, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + (Error 58, Line 10, Col 13, Line 10, Col 19, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 12, Col 13, Line 12, Col 22, "Exceptions must be defined at module level, not inside types.") + ] + + [] + let ``No Error for invalid constructs in deeply nested context``() = + Fsx """ +module OuterModule + +module InnerModule = + module DeeplyNested = + type IndentedType = + | Case1 + | Case2 + type NestedType = int + module NestedModule = + let x = 1 + exception NestedExc of string + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Abstract class with invalid constructs`` = + [] + let ``Error for invalid constructs in abstract class``() = + Fsx """ +module TestModule + +[] +type AbstractBase() = + abstract member Method : unit -> int + module InvalidModule = begin end + type InvalidType = string + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 8, Col 5, Line 8, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + ] + + [] + let ``No Error for invalid constructs in abstract class``() = + Fsx """ +module TestModule + +[] +type AbstractBase() = + abstract member Method : unit -> int + module InvalidModule = begin end + type InvalidType = string + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Type augmentation with invalid constructs`` = + [] + let ``Error for module in type augmentation``() = + Fsx """ +module TestModule + +type Original = | A | B + +type Original with + member _.Extended() = 1 + module ExtensionModule = + let x = 2 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 10, Line 8, Col 5, Line 8, Col 11, "Unexpected keyword 'module' in type definition. Expected incomplete structured construct at or before this point, 'end' or other token.") + (Error 10, Line 10, Col 1, Line 10, Col 13, "Incomplete structured construct at or before this point in implementation file") + ] + + [] + let ``No Error for module in type augmentation``() = + Fsx """ +module TestModule + +type Original = | A | B + +type Original with + member _.Extended() = 1 + module ExtensionModule = + let x = 2 + """ + |> withLangVersion90 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 10, Line 8, Col 5, Line 8, Col 11, "Unexpected keyword 'module' in type definition. Expected incomplete structured construct at or before this point, 'end' or other token."); + (Error 10, Line 10, Col 1, Line 10, Col 13, "Incomplete structured construct at or before this point in implementation file") + ] + + module ``Do binding with invalid constructs`` = + [] + let ``Error for invalid constructs after do binding``() = + Fsx """ +module TestModule + +type TypeWithDo() = + do printfn "Initialized" + type NestedType = int + module NestedModule = begin end + open System + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 6, Col 5, Line 6, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + (Error 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 8, Col 5, Line 8, Col 9, "'open' declarations must appear at module level, not inside types.") + ] + + + [] + let ``No Error for invalid constructs after do binding``() = + Fsx """ +module TestModule + +type TypeWithDo() = + do printfn "Initialized" + type NestedType = int + module NestedModule = begin end + open System + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Inherit with invalid constructs`` = + [] + let ``Error for invalid constructs after inherit``() = + Fsx """ +module TestModule + +type Base() = class end + +type Derived() = + inherit Base() + module InvalidModule = begin end + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Error for invalid constructs after inherit``() = + Fsx """ +module TestModule + +type Base() = class end + +type Derived() = + inherit Base() + module InvalidModule = begin end + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Valid module placement`` = + [] + let ``No Error for modules at correct level``() = + Fsx """ +module TestModule + +type A = A + +module ValidModule1 = begin end +module ValidModule2 = begin end + +type B = B + +module ValidModule3 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldSucceed + + [] + let ``No Error for modules at correct level 2``() = + Fsx """ +module TestModule + +type A = A + +module ValidModule1 = begin end +module ValidModule2 = begin end + +type B = B + +module ValidModule3 = + let f () = () + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + [] + let ``No Error for let bindings inside class``() = + Fsx """ +module TestModule + +type ClassWithLet() = + let helper x = x + 1 + let mutable state = 0 + member _.Method() = helper state + """ + |> withLangVersion10 + |> typecheck + |> shouldSucceed + + [] + let ``No Error for let bindings inside class 2``() = + Fsx """ +module TestModule + +type ClassWithLet() = + let helper x = x + 1 + let mutable state = 0 + member _.Method() = helper state + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + [] + let ``No Error for modules at same indentation as type``() = + Fsx """ +module TestModule + +type A = A +module B = begin end // Same column as type, not nested + """ + |> withLangVersion10 + |> typecheck + |> shouldSucceed + + [] + let ``No Error for modules at same indentation as type 2``() = + Fsx """ +module TestModule + +type A = A +module B = begin end // Same column as type, not nested + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index da13333f878..ba1eedab848 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -221,6 +221,7 @@ + diff --git a/tests/fsharp/typecheck/sigs/neg01.bsl b/tests/fsharp/typecheck/sigs/neg01.bsl index 80b8b22daf3..1ee82bcc91b 100644 --- a/tests/fsharp/typecheck/sigs/neg01.bsl +++ b/tests/fsharp/typecheck/sigs/neg01.bsl @@ -1,6 +1,4 @@ -neg01a.fsi(24,8,25,7): typecheck error FS0913: Types cannot contain nested type definitions +neg01a.fsi(24,15,24,19): parse error FS0058: Nested type definitions are not allowed. Types must be defined at module or namespace level. -neg01a.fs(22,8,23,7): typecheck error FS0913: Types cannot contain nested type definitions - -neg01b.fs(2,13,2,14): typecheck error FS0039: The value, constructor, namespace or type 'X' is not defined. +neg01a.fs(22,15,22,19): parse error FS0058: Nested type definitions are not allowed. Types must be defined at module or namespace level. \ No newline at end of file diff --git a/tests/fsharp/typecheck/sigs/neg01.vsbsl b/tests/fsharp/typecheck/sigs/neg01.vsbsl new file mode 100644 index 00000000000..d4c96cf1d0a --- /dev/null +++ b/tests/fsharp/typecheck/sigs/neg01.vsbsl @@ -0,0 +1,10 @@ + +neg01a.fsi(24,15,24,19): parse error FS0058: Nested type definitions are not allowed. Types must be defined at module or namespace level. + +neg01a.fs(22,15,22,19): parse error FS0058: Nested type definitions are not allowed. Types must be defined at module or namespace level. + +neg01a.fsi(24,8,25,7): typecheck error FS0913: Types cannot contain nested type definitions + +neg01a.fs(22,8,23,7): typecheck error FS0913: Types cannot contain nested type definitions + +neg01b.fs(2,13,2,14): typecheck error FS0039: The value, constructor, namespace or type 'X' is not defined. diff --git a/tests/fsharp/typecheck/sigs/neg17.fs b/tests/fsharp/typecheck/sigs/neg17.fs index df775516b64..36802399832 100644 --- a/tests/fsharp/typecheck/sigs/neg17.fs +++ b/tests/fsharp/typecheck/sigs/neg17.fs @@ -67,7 +67,7 @@ module M = static member Method34() = noErrorPrivateValueLaterInferredToInvolvePrivateUnionType := [DefaultTagOfPrivateType(3)] static member Method35() = noErrorPrivateValueLaterInferredToInvolveInternalUnionType := [DefaultTagOfInternalType(3)] - type Type with + type Type with // Check we can access private things from an in-file augmentation member x.NoError51 = x.PrivateProperty diff --git a/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl b/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl index 091be309d37..b509927045c 100644 --- a/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl +++ b/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl @@ -31,3 +31,5 @@ SigFile { ConditionalDirectives = [] WarnDirectives = [] CodeComments = [] }, set [])) + +(3,11)-(3,15) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs new file mode 100644 index 00000000000..4b8ad8c3b86 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs @@ -0,0 +1,7 @@ +// Testing: Cascading invalid nested constructs +module Module + +type A = + type B = int + module C = () + exception D diff --git a/tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..1526b36c74e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs.bsl @@ -0,0 +1,55 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Cascading Nested Invalid Constructs 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple (None (4,5--4,8), (4,5--4,8)), [], None, (4,5--4,8), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--4,8)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,9--5,10)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (5,13--5,16)), (5,13--5,16)), [], None, (5,9--5,16), + { LeadingKeyword = Type (5,4--5,8) + EqualsRange = Some (5,11--5,12) + WithKeyword = None })], (5,4--5,16)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,8--6,16)), false, + [Expr (Const (Unit, (6,19--6,21)), (6,19--6,21))], false, + (6,8--6,21), { ModuleKeyword = Some (6,8--6,14) + EqualsRange = Some (6,17--6,18) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (D, None), Fields [], PreXmlDocEmpty, None, + (7,22--7,23), { BarRange = None }), None, + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (7,12--7,23)), None, [], (7,12--7,23)), (7,12--7,23))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,23), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,47)] }, set [])) + +(5,4)-(5,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(4,5)-(4,8) parse error A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'. +(6,8)-(6,14) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs new file mode 100644 index 00000000000..df2f7296d49 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs @@ -0,0 +1,8 @@ +// Testing: Keywords in comments should be ignored +module Module + +type MyType = + // This comment mentions module and type + member _.Method() = 1 + (* module MyModule *) + member _.AnotherMethod() = 2 diff --git a/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl new file mode 100644 index 00000000000..90710f91ec7 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl @@ -0,0 +1,79 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Comments With Keywords 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyType], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,11)), + ObjectModel + (Unspecified, + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; Method], [(6,12--6,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (6,19--6,21)), (6,19--6,21))], + None, (6,11--6,21)), None, + Const (Int32 1, (6,24--6,25)), (6,11--6,21), + NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = Some (6,22--6,23) }), (6,4--6,25)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; AnotherMethod], [(8,12--8,13)], + [None; None]), None, None, + Pats + [Paren + (Const (Unit, (8,26--8,28)), (8,26--8,28))], + None, (8,11--8,28)), None, + Const (Int32 2, (8,31--8,32)), (8,11--8,28), + NoneAtInvisible, + { LeadingKeyword = Member (8,4--8,10) + InlineKeyword = None + EqualsRange = Some (8,29--8,30) }), (8,4--8,32))], + (6,4--8,32)), [], None, (4,5--8,32), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,12--4,13) + WithKeyword = None })], (4,0--8,32))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,32), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = + [LineComment (1,0--1,50); LineComment (5,4--5,44); + BlockComment (7,4--7,25)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs new file mode 100644 index 00000000000..993b78b0a0b --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs @@ -0,0 +1,10 @@ +// Testing: Invalid constructs in deeply nested type +module OuterModule + +module InnerModule = + module DeeplyNested = + type IndentedType = + type NestedType = int + module NestedModule = + let x = 1 + exception NestedExc diff --git a/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl new file mode 100644 index 00000000000..10723d4529c --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl @@ -0,0 +1,88 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Deeply Indented Type 01.fs", false, + QualifiedNameOfFile OuterModule, [], + [SynModuleOrNamespace + ([OuterModule], false, NamedModule, + [NestedModule + (SynComponentInfo + ([], None, [], [InnerModule], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (4,0--4,18)), false, + [NestedModule + (SynComponentInfo + ([], None, [], [DeeplyNested], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,4--5,23)), false, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [IndentedType], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,13--6,25)), + Simple (None (6,13--6,27), (6,13--6,27)), [], None, + (6,13--6,27), { LeadingKeyword = Type (6,8--6,12) + EqualsRange = Some (6,26--6,27) + WithKeyword = None })], (6,8--6,27)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [NestedType], + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (7,17--7,27)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (7,30--7,33)), (7,30--7,33)), [], None, + (7,17--7,33), { LeadingKeyword = Type (7,12--7,16) + EqualsRange = Some (7,28--7,29) + WithKeyword = None })], (7,12--7,33)); + NestedModule + (SynComponentInfo + ([], None, [], [NestedModule], + PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,12--8,31)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,16), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (x, None), false, None, (9,20--9,21)), + None, Const (Int32 1, (9,24--9,25)), (9,20--9,21), + Yes (9,16--9,25), + { LeadingKeyword = Let (9,16--9,19) + InlineKeyword = None + EqualsRange = Some (9,22--9,23) })], + (9,16--9,25))], false, (8,12--9,25), + { ModuleKeyword = Some (8,12--8,18) + EqualsRange = Some (8,32--8,33) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (NestedExc, None), Fields [], + PreXmlDocEmpty, None, (10,22--10,31), + { BarRange = None }), None, + PreXmlDoc ((10,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (10,12--10,31)), None, [], (10,12--10,31)), + (10,12--10,31))], false, (5,4--10,31), + { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,24--5,25) })], false, (4,0--10,31), + { ModuleKeyword = Some (4,0--4,6) + EqualsRange = Some (4,19--4,20) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--10,31), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,52)] }, set [])) + +(7,12)-(7,16) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(6,13)-(6,27) parse error A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'. +(8,12)-(8,18) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(10,12)-(10,21) parse error Exceptions must be defined at module level, not inside types. diff --git a/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs new file mode 100644 index 00000000000..fe7a5ade2fb --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs @@ -0,0 +1,7 @@ +// Testing: Double semicolon delimiters with invalid constructs +module Module + +type A = + type B = int;; + module C = ();; + exception D;; diff --git a/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl new file mode 100644 index 00000000000..e2bda14132e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl @@ -0,0 +1,54 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Double Semicolon Delimiters 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple (None (4,5--4,8), (4,5--4,8)), [], None, (4,5--4,8), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--4,8)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,9--5,10)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (5,13--5,16)), (5,13--5,16)), [], None, (5,9--5,16), + { LeadingKeyword = Type (5,4--5,8) + EqualsRange = Some (5,11--5,12) + WithKeyword = None })], (5,4--5,16)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,12)), false, + [Expr (Const (Unit, (6,15--6,17)), (6,15--6,17))], false, + (6,4--6,17), { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,13--6,14) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (D, None), Fields [], PreXmlDocEmpty, None, + (7,14--7,15), { BarRange = None }), None, + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), None, + (7,4--7,15)), None, [], (7,4--7,15)), (7,4--7,15))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,15), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,63)] }, set [])) + +(5,4)-(5,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(4,5)-(4,8) parse error A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'. diff --git a/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs new file mode 100644 index 00000000000..3f47a6778b8 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs @@ -0,0 +1,5 @@ +// Testing: Exception inside type +module Module + +type A = + exception MyException diff --git a/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl new file mode 100644 index 00000000000..887cb099c0c --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl @@ -0,0 +1,34 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Exception Inside Type 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple (None (4,5--4,6), (4,5--4,6)), [], None, (4,5--4,6), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = None + WithKeyword = None })], (4,0--4,6)); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (MyException, None), Fields [], + PreXmlDocEmpty, None, (5,14--5,25), { BarRange = None }), + None, PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,4--5,25)), None, [], (5,4--5,25)), (5,4--5,25))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--5,25), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,33)] }, set [])) + +(5,4)-(5,13) parse error Exceptions must be defined at module level, not inside types. +(5,4)-(5,13) parse error Unexpected keyword 'exception' in type definition +(6,0)-(6,0) parse error Incomplete structured construct at or before this point in implementation file diff --git a/tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs b/tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs new file mode 100644 index 00000000000..cd597bd124a --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs @@ -0,0 +1,4 @@ +// Expected: No warning - parentheses context skips validation +module Module +let inline unbox (x: obj) : 'T = + (# "unbox.any !0" type ('T) x : 'T #) diff --git a/tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs.bsl new file mode 100644 index 00000000000..195ff908d8f --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs.bsl @@ -0,0 +1,63 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Inline IL With Type 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Let + (false, + [SynBinding + (None, Normal, true, false, [], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo + ([[SynArgInfo ([], false, Some x)]], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent ([unbox], [], [None]), None, None, + Pats + [Paren + (Typed + (Named + (SynIdent (x, None), false, None, (3,18--3,19)), + LongIdent (SynLongIdent ([obj], [], [None])), + (3,18--3,24)), (3,17--3,25))], None, (3,11--3,25)), + Some + (SynBindingReturnInfo + (Var (SynTypar (T, None, false), (3,28--3,30)), + (3,28--3,30), [], { ColonRange = Some (3,26--3,27) })), + Typed + (ArbitraryAfterError ("parenExpr2", (4,4--4,26)), + Var (SynTypar (T, None, false), (3,28--3,30)), (4,4--4,26)), + (3,11--3,25), NoneAtLet, { LeadingKeyword = Let (3,0--3,3) + InlineKeyword = Some (3,4--3,10) + EqualsRange = Some (3,31--3,32) })], + (3,0--4,26)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], + Some + (PrefixList + ([SynTyparDecl + ([], SynTypar (T, None, false), [], + { AmpersandRanges = [] })], (4,27--4,31))), [], + [x], + PreXmlDoc ((4,22), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,32--4,33)), + Simple (None (4,32--4,33), (4,32--4,33)), [], None, + (4,32--4,33), { LeadingKeyword = Type (4,22--4,26) + EqualsRange = None + WithKeyword = None })], (4,22--4,33))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--4,33), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,62)] }, set [])) + +(4,22)-(4,26) parse error Incomplete structured construct at or before this point in binding. Expected # or other token. +(4,4)-(4,5) parse error Unmatched '(' +(4,22)-(4,26) parse error Unexpected keyword 'type' in binding. Expected incomplete structured construct at or before this point or other token. +(3,0)-(3,3) parse error Incomplete value or function definition. If this is in an expression, the body of the expression must be indented to the same column as the 'let' keyword. +(4,34)-(4,35) parse error Unexpected symbol ':' in type definition. Expected '=' or other token. diff --git a/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs new file mode 100644 index 00000000000..5a40ba6d234 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs @@ -0,0 +1,6 @@ +// Testing: Keywords in strings should be ignored +module Module + +type MyClass = + let message = "type and module keywords" + member _.GetMessage() = message diff --git a/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl new file mode 100644 index 00000000000..f42d3f23ed7 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl @@ -0,0 +1,69 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Keywords In Strings 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyClass], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,12)), + ObjectModel + (Unspecified, + [LetBindings + ([SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (message, None), false, None, + (5,8--5,15)), None, + Const + (String + ("type and module keywords", Regular, + (5,18--5,44)), (5,18--5,44)), (5,8--5,15), + Yes (5,4--5,44), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,16--5,17) })], false, false, + (5,4--5,44)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; GetMessage], [(6,12--6,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (6,23--6,25)), (6,23--6,25))], + None, (6,11--6,25)), None, Ident message, + (6,11--6,25), NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = Some (6,26--6,27) }), (6,4--6,35))], + (5,4--6,35)), [], None, (4,5--6,35), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,13--4,14) + WithKeyword = None })], (4,0--6,35))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--6,35), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,49)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs new file mode 100644 index 00000000000..a795a3c44a8 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs @@ -0,0 +1,6 @@ +// Testing: Let bindings are valid in classes +module Module + +type MyClass() = + let privateField = 10 + member _.GetValue() = privateField diff --git a/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl new file mode 100644 index 00000000000..b677479348f --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl @@ -0,0 +1,74 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Let Inside Class 01.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyClass], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,12)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,12--4,14)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None }); + LetBindings + ([SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (privateField, None), false, None, + (5,8--5,20)), None, + Const (Int32 10, (5,23--5,25)), (5,8--5,20), + Yes (5,4--5,25), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,21--5,22) })], false, false, + (5,4--5,25)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; GetValue], [(6,12--6,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (6,21--6,23)), (6,21--6,23))], + None, (6,11--6,23)), None, Ident privateField, + (6,11--6,23), NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = Some (6,24--6,25) }), (6,4--6,38))], + (5,4--6,38)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,12--4,14)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None })), (4,5--6,38), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,15--4,16) + WithKeyword = None })], (4,0--6,38))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--6,38), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,45)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs b/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs new file mode 100644 index 00000000000..e524972fe92 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs @@ -0,0 +1,7 @@ +// Expected: Warning for module after do binding +module Module + +type MyClass() = + do printfn "Initializing" + module M = + let helper = 42 diff --git a/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs.bsl new file mode 100644 index 00000000000..fa44a076bea --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs.bsl @@ -0,0 +1,71 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module After Do Binding 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyClass], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,12)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,12--4,14)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None }); + LetBindings + ([SynBinding + (None, Do, false, false, [], PreXmlDocEmpty, + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), Const (Unit, (5,4--5,29)), None, + App + (NonAtomic, false, Ident printfn, + Const + (String + ("Initializing", Regular, (5,15--5,29)), + (5,15--5,29)), (5,7--5,29)), (5,4--5,29), + NoneAtDo, { LeadingKeyword = Do (5,4--5,6) + InlineKeyword = None + EqualsRange = None })], false, false, + (5,4--5,29))], (5,4--5,29)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,12--4,14)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None })), (4,5--5,29), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,15--4,16) + WithKeyword = None })], (4,0--5,29)); + NestedModule + (SynComponentInfo + ([], None, [], [M], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,12)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (helper, None), false, None, (7,12--7,18)), + None, Const (Int32 42, (7,21--7,23)), (7,12--7,18), + Yes (7,8--7,23), { LeadingKeyword = Let (7,8--7,11) + InlineKeyword = None + EqualsRange = Some (7,19--7,20) })], + (7,8--7,23))], false, (6,4--7,23), + { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,13--6,14) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,23), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,48)] }, set [])) + +(6,4)-(6,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs b/tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs new file mode 100644 index 00000000000..ff4bd5c0561 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs @@ -0,0 +1,10 @@ +// Testing: Module after inherit +module Module + +type Base() = class end + +type Derived() = + inherit Base() + + module InvalidModule = + let x = 2 diff --git a/tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs.bsl new file mode 100644 index 00000000000..79d4155fcbd --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs.bsl @@ -0,0 +1,78 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module After Inherit 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [Base], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,9)), + ObjectModel + (Class, + [ImplicitCtor + (None, [], Const (Unit, (4,9--4,11)), None, + PreXmlDoc ((4,9), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,9), { AsKeyword = None })], (4,14--4,23)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,9--4,11)), None, + PreXmlDoc ((4,9), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,9), { AsKeyword = None })), (4,5--4,23), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,12--4,13) + WithKeyword = None })], (4,0--4,23)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [Derived], + PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,5--6,12)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (6,12--6,14)), None, + PreXmlDoc ((6,12), FSharp.Compiler.Xml.XmlDocCollector), + (6,5--6,12), { AsKeyword = None }); + ImplicitInherit + (LongIdent (SynLongIdent ([Base], [], [None])), + Const (Unit, (7,16--7,18)), None, (7,4--7,18), + { InheritKeyword = (7,4--7,11) })], (7,4--7,18)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (6,12--6,14)), None, + PreXmlDoc ((6,12), FSharp.Compiler.Xml.XmlDocCollector), + (6,5--6,12), { AsKeyword = None })), (6,5--7,18), + { LeadingKeyword = Type (6,0--6,4) + EqualsRange = Some (6,15--6,16) + WithKeyword = None })], (6,0--7,18)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (9,4--9,24)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((10,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (10,12--10,13)), + None, Const (Int32 2, (10,16--10,17)), (10,12--10,13), + Yes (10,8--10,17), { LeadingKeyword = Let (10,8--10,11) + InlineKeyword = None + EqualsRange = Some (10,14--10,15) })], + (10,8--10,17))], false, (9,4--10,17), + { ModuleKeyword = Some (9,4--9,10) + EqualsRange = Some (9,25--9,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--10,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,32)] }, set [])) + +(9,4)-(9,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module After Members 01.fs b/tests/service/data/SyntaxTree/Type/Module After Members 01.fs new file mode 100644 index 00000000000..9998e34cdb8 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Members 01.fs @@ -0,0 +1,9 @@ +// Expected: Warning for module after members +module Module + +type ClassWithMembers() = + member _.Method1() = 1 + member _.Method2() = 2 + + module InvalidModule = + let helper = 10 diff --git a/tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl new file mode 100644 index 00000000000..bb9dc70cb4a --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl @@ -0,0 +1,109 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module After Members 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [ClassWithMembers], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,21)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,21--4,23)), None, + PreXmlDoc ((4,21), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,21), { AsKeyword = None }); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; Method1], [(5,12--5,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (5,20--5,22)), (5,20--5,22))], + None, (5,11--5,22)), None, + Const (Int32 1, (5,25--5,26)), (5,11--5,22), + NoneAtInvisible, + { LeadingKeyword = Member (5,4--5,10) + InlineKeyword = None + EqualsRange = Some (5,23--5,24) }), (5,4--5,26)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; Method2], [(6,12--6,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (6,20--6,22)), (6,20--6,22))], + None, (6,11--6,22)), None, + Const (Int32 2, (6,25--6,26)), (6,11--6,22), + NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = Some (6,23--6,24) }), (6,4--6,26))], + (5,4--6,26)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,21--4,23)), None, + PreXmlDoc ((4,21), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,21), { AsKeyword = None })), (4,5--6,26), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,24--4,25) + WithKeyword = None })], (4,0--6,26)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (8,4--8,24)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (helper, None), false, None, (9,12--9,18)), + None, Const (Int32 10, (9,21--9,23)), (9,12--9,18), + Yes (9,8--9,23), { LeadingKeyword = Let (9,8--9,11) + InlineKeyword = None + EqualsRange = Some (9,19--9,20) })], + (9,8--9,23))], false, (8,4--9,23), + { ModuleKeyword = Some (8,4--8,10) + EqualsRange = Some (8,25--8,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--9,23), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,45)] }, set [])) + +(8,4)-(8,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs b/tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs new file mode 100644 index 00000000000..a990fa898db --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs @@ -0,0 +1,8 @@ +// Testing: Module after static members +module Module + +type MyType = + static member StaticMethod() = 42 + + module InvalidModule = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs.bsl new file mode 100644 index 00000000000..9cafebb4709 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs.bsl @@ -0,0 +1,72 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module After Static Members 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyType], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,11)), + ObjectModel + (Unspecified, + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = false + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([StaticMethod], [], [None]), None, + None, + Pats + [Paren + (Const (Unit, (5,30--5,32)), (5,30--5,32))], + None, (5,18--5,32)), None, + Const (Int32 42, (5,35--5,37)), (5,18--5,32), + NoneAtInvisible, + { LeadingKeyword = + StaticMember ((5,4--5,10), (5,11--5,17)) + InlineKeyword = None + EqualsRange = Some (5,33--5,34) }), (5,4--5,37))], + (5,4--5,37)), [], None, (4,5--5,37), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,12--4,13) + WithKeyword = None })], (4,0--5,37)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,24)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (8,12--8,13)), + None, Const (Int32 1, (8,16--8,17)), (8,12--8,13), + Yes (8,8--8,17), { LeadingKeyword = Let (8,8--8,11) + InlineKeyword = None + EqualsRange = Some (8,14--8,15) })], + (8,8--8,17))], false, (7,4--8,17), + { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,25--7,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,39)] }, set [])) + +(7,4)-(7,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs new file mode 100644 index 00000000000..13c274c3da3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs @@ -0,0 +1,10 @@ +// Testing: Module and exception interleaved with members +module Module + +type Interleaved = + member _.X = 1 + module M1 = + let y = 2 + member _.Y = 2 + exception E1 + member _.Z = 3 diff --git a/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs.bsl new file mode 100644 index 00000000000..807b6497ad1 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs.bsl @@ -0,0 +1,71 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module And Exception Interleaved With Members 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [Interleaved], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,16)), + ObjectModel + (Unspecified, + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; X], [(5,12--5,13)], [None; None]), None, + None, Pats [], None, (5,11--5,14)), None, + Const (Int32 1, (5,17--5,18)), (5,11--5,14), + NoneAtInvisible, + { LeadingKeyword = Member (5,4--5,10) + InlineKeyword = None + EqualsRange = Some (5,15--5,16) }), (5,4--5,18))], + (5,4--5,18)), [], None, (4,5--5,18), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,17--4,18) + WithKeyword = None })], (4,0--5,18)); + NestedModule + (SynComponentInfo + ([], None, [], [M1], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,13)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (y, None), false, None, (7,12--7,13)), + None, Const (Int32 2, (7,16--7,17)), (7,12--7,13), + Yes (7,8--7,17), { LeadingKeyword = Let (7,8--7,11) + InlineKeyword = None + EqualsRange = Some (7,14--7,15) })], + (7,8--7,17))], false, (6,4--7,17), + { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,14--6,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,57)] }, set [])) + +(6,4)-(6,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(8,4)-(8,10) parse error Unexpected keyword 'member' in definition. Expected incomplete structured construct at or before this point or other token. +(9,4)-(9,13) parse error Exceptions must be defined at module level, not inside types. diff --git a/tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs b/tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs new file mode 100644 index 00000000000..bc6ed0b60a0 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs @@ -0,0 +1,13 @@ +// Testing: Invalid constructs after do binding +module Module + +type ClassWithDo() = + do + printfn "init" + + type InternalType = int + + module InternalModule = + let x = 1 + + open System.Collections diff --git a/tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs.bsl new file mode 100644 index 00000000000..bb3cb97c749 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs.bsl @@ -0,0 +1,90 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module And Type After Do Binding 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [ClassWithDo], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,16)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,16--4,18)), None, + PreXmlDoc ((4,16), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,16), { AsKeyword = None }); + LetBindings + ([SynBinding + (None, Do, false, false, [], PreXmlDocEmpty, + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), Const (Unit, (5,4--6,22)), None, + App + (NonAtomic, false, Ident printfn, + Const + (String ("init", Regular, (6,16--6,22)), + (6,16--6,22)), (6,8--6,22)), (5,4--6,22), + NoneAtDo, { LeadingKeyword = Do (5,4--5,6) + InlineKeyword = None + EqualsRange = None })], false, false, + (5,4--6,22))], (5,4--6,22)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,16--4,18)), None, + PreXmlDoc ((4,16), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,16), { AsKeyword = None })), (4,5--6,22), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,19--4,20) + WithKeyword = None })], (4,0--6,22)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [InternalType], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,9--8,21)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (8,24--8,27)), (8,24--8,27)), [], None, (8,9--8,27), + { LeadingKeyword = Type (8,4--8,8) + EqualsRange = Some (8,22--8,23) + WithKeyword = None })], (8,4--8,27)); + NestedModule + (SynComponentInfo + ([], None, [], [InternalModule], + PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (10,4--10,25)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((11,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (11,12--11,13)), + None, Const (Int32 1, (11,16--11,17)), (11,12--11,13), + Yes (11,8--11,17), { LeadingKeyword = Let (11,8--11,11) + InlineKeyword = None + EqualsRange = Some (11,14--11,15) })], + (11,8--11,17))], false, (10,4--11,17), + { ModuleKeyword = Some (10,4--10,10) + EqualsRange = Some (10,26--10,27) }); + Open + (ModuleOrNamespace + (SynLongIdent + ([System; Collections], [(13,15--13,16)], [None; None]), + (13,9--13,27)), (13,4--13,27))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--13,27), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,47)] }, set [])) + +(8,4)-(8,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(10,4)-(10,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(13,4)-(13,8) parse error 'open' declarations must appear at module level, not inside types. diff --git a/tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs b/tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs new file mode 100644 index 00000000000..0ecbc807474 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs @@ -0,0 +1,8 @@ +// Testing: Module and type declarations inside a type +module Module + +type MyType = + module InvalidModule = + let helper = 10 + + type InvalidType = string diff --git a/tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs.bsl new file mode 100644 index 00000000000..e111610ed72 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs.bsl @@ -0,0 +1,59 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module And Type Inside Type 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyType], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,11)), + Simple (None (4,5--4,13), (4,5--4,13)), [], None, (4,5--4,13), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,12--4,13) + WithKeyword = None })], (4,0--4,13)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,24)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (helper, None), false, None, (6,12--6,18)), + None, Const (Int32 10, (6,21--6,23)), (6,12--6,18), + Yes (6,8--6,23), { LeadingKeyword = Let (6,8--6,11) + InlineKeyword = None + EqualsRange = Some (6,19--6,20) })], + (6,8--6,23))], false, (5,4--6,23), + { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,25--5,26) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [InvalidType], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,9--8,20)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([string], [], [None])), + (8,23--8,29)), (8,23--8,29)), [], None, (8,9--8,29), + { LeadingKeyword = Type (8,4--8,8) + EqualsRange = Some (8,21--8,22) + WithKeyword = None })], (8,4--8,29))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,54)] }, set [])) + +(5,4)-(5,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(4,5)-(4,13) parse error A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'. +(8,4)-(8,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs b/tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs new file mode 100644 index 00000000000..67fbec5f1d3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs @@ -0,0 +1,8 @@ +// Expected: No warning - module at correct indentation level +module Module + +type SimpleType = + | A of int + | B of string +module ValidModule = + let x = 42 diff --git a/tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs.bsl new file mode 100644 index 00000000000..7f34575084d --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs.bsl @@ -0,0 +1,69 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module At Module Level 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [SimpleType], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,15)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((5,11), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,11--5,14), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,14), { BarRange = Some (5,4--5,5) }); + SynUnionCase + ([], SynIdent (B, None), + Fields + [SynField + ([], false, None, + LongIdent + (SynLongIdent ([string], [], [None])), false, + PreXmlDoc ((6,11), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,11--6,17), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,17), { BarRange = Some (6,4--6,5) })], + (5,4--6,17)), (5,4--6,17)), [], None, (4,5--6,17), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,16--4,17) + WithKeyword = None })], (4,0--6,17)); + NestedModule + (SynComponentInfo + ([], None, [], [ValidModule], + PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,0--7,18)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (8,8--8,9)), None, + Const (Int32 42, (8,12--8,14)), (8,8--8,9), + Yes (8,4--8,14), { LeadingKeyword = Let (8,4--8,7) + InlineKeyword = None + EqualsRange = Some (8,10--8,11) })], + (8,4--8,14))], false, (7,0--8,14), + { ModuleKeyword = Some (7,0--7,6) + EqualsRange = Some (7,19--7,20) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,14), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,61)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs b/tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs new file mode 100644 index 00000000000..b49d1ca2516 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs @@ -0,0 +1,8 @@ +// Expected: No warning - same indentation level +module Module + +type A = + | A of int +type B = B +module C = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs.bsl new file mode 100644 index 00000000000..9a0f25f37fd --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs.bsl @@ -0,0 +1,69 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module At Type Column 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((5,11), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,11--5,14), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,14), { BarRange = Some (5,4--5,5) })], + (5,4--5,14)), (5,4--5,14)), [], None, (4,5--5,14), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--5,14)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,5--6,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([B], [], [None])), + (6,9--6,10)), (6,9--6,10)), [], None, (6,5--6,10), + { LeadingKeyword = Type (6,0--6,4) + EqualsRange = Some (6,7--6,8) + WithKeyword = None })], (6,0--6,10)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,0--7,8)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (8,8--8,9)), None, + Const (Int32 1, (8,12--8,13)), (8,8--8,9), Yes (8,4--8,13), + { LeadingKeyword = Let (8,4--8,7) + InlineKeyword = None + EqualsRange = Some (8,10--8,11) })], (8,4--8,13))], + false, (7,0--8,13), { ModuleKeyword = Some (7,0--7,6) + EqualsRange = Some (7,9--7,10) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,13), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,48)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs b/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs new file mode 100644 index 00000000000..4b6afa24953 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs @@ -0,0 +1,10 @@ +// Testing: Module between constructors +module Module + +type MyClass(x: int) = + new() = MyClass(0) + + module InvalidModule = + let x = 1 + + new(s: string) = MyClass(1) diff --git a/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs.bsl new file mode 100644 index 00000000000..5034df6344b --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs.bsl @@ -0,0 +1,96 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Between Constructors 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyClass], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,12)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], + Paren + (Typed + (Named + (SynIdent (x, None), false, None, (4,13--4,14)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,13--4,19)), (4,12--4,20)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None }); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = false + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Constructor }, + SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([new], [], [None]), None, + Some (SynValTyparDecls (None, false)), + Pats + [Paren (Const (Unit, (5,7--5,9)), (5,7--5,9))], + None, (5,4--5,7)), None, + App + (Atomic, false, Ident MyClass, + Paren + (Const (Int32 0, (5,20--5,21)), (5,19--5,20), + Some (5,21--5,22), (5,19--5,22)), (5,12--5,22)), + (5,4--5,9), NoneAtInvisible, + { LeadingKeyword = New (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,10--5,11) }), (5,4--5,22))], + (5,4--5,22)), [], + Some + (ImplicitCtor + (None, [], + Paren + (Typed + (Named + (SynIdent (x, None), false, None, (4,13--4,14)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,13--4,19)), (4,12--4,20)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None })), (4,5--5,22), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,21--4,22) + WithKeyword = None })], (4,0--5,22)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,24)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (8,12--8,13)), + None, Const (Int32 1, (8,16--8,17)), (8,12--8,13), + Yes (8,8--8,17), { LeadingKeyword = Let (8,8--8,11) + InlineKeyword = None + EqualsRange = Some (8,14--8,15) })], + (8,8--8,17))], false, (7,4--8,17), + { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,25--7,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,39)] }, set [])) + +(7,4)-(7,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(10,4)-(10,7) parse error Unexpected keyword 'new' in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs new file mode 100644 index 00000000000..234136d2e6b --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs @@ -0,0 +1,7 @@ +// Expected: Warning for module inside class +module Module + +type C () = + member _.F () = 3 + module M2 = + let f () = () diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl new file mode 100644 index 00000000000..61191bc287b --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl @@ -0,0 +1,84 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Class 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,7--4,9)), None, + PreXmlDoc ((4,7), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,6), { AsKeyword = None }); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; F], [(5,12--5,13)], [None; None]), None, + None, + Pats + [Paren + (Const (Unit, (5,15--5,17)), (5,15--5,17))], + None, (5,11--5,17)), None, + Const (Int32 3, (5,20--5,21)), (5,11--5,17), + NoneAtInvisible, + { LeadingKeyword = Member (5,4--5,10) + InlineKeyword = None + EqualsRange = Some (5,18--5,19) }), (5,4--5,21))], + (5,4--5,21)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,7--4,9)), None, + PreXmlDoc ((4,7), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,6), { AsKeyword = None })), (4,5--5,21), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,10--4,11) + WithKeyword = None })], (4,0--5,21)); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,13)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (7,14--7,16)), (7,14--7,16))], + None, (7,12--7,16)), None, Const (Unit, (7,19--7,21)), + (7,12--7,16), NoneAtLet, + { LeadingKeyword = Let (7,8--7,11) + InlineKeyword = None + EqualsRange = Some (7,17--7,18) })], (7,8--7,21))], + false, (6,4--7,21), { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,14--6,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,21), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,44)] }, set [])) + +(6,4)-(6,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs new file mode 100644 index 00000000000..2253f9c1b59 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs @@ -0,0 +1,6 @@ +// Testing: Module inside class with constructor +module Module + +type MyClass(x: int) = + module InternalModule = + let helper = 42 diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs.bsl new file mode 100644 index 00000000000..b343a4bfd88 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs.bsl @@ -0,0 +1,67 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Class With Constructor 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyClass], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,12)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], + Paren + (Typed + (Named + (SynIdent (x, None), false, None, (4,13--4,14)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,13--4,19)), (4,12--4,20)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None })], (4,5--4,22)), [], + Some + (ImplicitCtor + (None, [], + Paren + (Typed + (Named + (SynIdent (x, None), false, None, (4,13--4,14)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,13--4,19)), (4,12--4,20)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None })), (4,5--4,22), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,21--4,22) + WithKeyword = None })], (4,0--4,22)); + NestedModule + (SynComponentInfo + ([], None, [], [InternalModule], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,25)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (helper, None), false, None, (6,12--6,18)), + None, Const (Int32 42, (6,21--6,23)), (6,12--6,18), + Yes (6,8--6,23), { LeadingKeyword = Let (6,8--6,11) + InlineKeyword = None + EqualsRange = Some (6,19--6,20) })], + (6,8--6,23))], false, (5,4--6,23), + { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,26--5,27) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--6,23), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,48)] }, set [])) + +(5,4)-(5,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(4,5)-(4,13) parse error A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs new file mode 100644 index 00000000000..1f8d6e77712 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs @@ -0,0 +1,6 @@ +// Expected: Warning for module after delegate +module Module + +type MyDelegate = delegate of int * int -> int + module InvalidModule = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl new file mode 100644 index 00000000000..02ce751defb --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl @@ -0,0 +1,93 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Delegate 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyDelegate], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,15)), + ObjectModel + (Delegate + (Fun + (Tuple + (false, + [Type + (LongIdent (SynLongIdent ([int], [], [None]))); + Star (4,34--4,35); + Type + (LongIdent (SynLongIdent ([int], [], [None])))], + (4,30--4,39)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,30--4,46), { ArrowRange = (4,40--4,42) }), + SynValInfo + ([[SynArgInfo ([], false, None); + SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None))), + [AbstractSlot + (SynValSig + ([], SynIdent (Invoke, None), + SynValTyparDecls (None, true), + Fun + (Tuple + (false, + [Type + (LongIdent + (SynLongIdent ([int], [], [None]))); + Star (4,34--4,35); + Type + (LongIdent + (SynLongIdent ([int], [], [None])))], + (4,30--4,39)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,30--4,46), { ArrowRange = (4,40--4,42) }), + SynValInfo + ([[SynArgInfo ([], false, None); + SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None)), false, false, + PreXmlDocEmpty, Single None, None, (4,18--4,46), + { LeadingKeyword = Synthetic + InlineKeyword = None + WithKeyword = None + EqualsRange = None }), + { IsInstance = true + IsDispatchSlot = true + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, (4,18--4,46), + { GetSetKeywords = None })], (4,18--4,46)), [], None, + (4,5--4,46), { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,16--4,17) + WithKeyword = None })], (4,0--4,46)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,24)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (6,12--6,13)), + None, Const (Int32 1, (6,16--6,17)), (6,12--6,13), + Yes (6,8--6,17), { LeadingKeyword = Let (6,8--6,11) + InlineKeyword = None + EqualsRange = Some (6,14--6,15) })], + (6,8--6,17))], false, (5,4--6,17), + { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,25--5,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--6,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,46)] }, set [])) + +(5,4)-(5,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs new file mode 100644 index 00000000000..a4898ae9e5a --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs @@ -0,0 +1,7 @@ +// Expected: Warning for module inside interface +module Module + +type IFace = + abstract F : int -> int + module M = + let f () = () diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl new file mode 100644 index 00000000000..4894de15039 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl @@ -0,0 +1,71 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Interface 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [IFace], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,10)), + ObjectModel + (Unspecified, + [AbstractSlot + (SynValSig + ([], SynIdent (F, None), + SynValTyparDecls (None, true), + Fun + (LongIdent (SynLongIdent ([int], [], [None])), + LongIdent (SynLongIdent ([int], [], [None])), + (5,17--5,27), { ArrowRange = (5,21--5,23) }), + SynValInfo + ([[SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None)), false, false, + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + Single None, None, (5,4--5,27), + { LeadingKeyword = Abstract (5,4--5,12) + InlineKeyword = None + WithKeyword = None + EqualsRange = None }), + { IsInstance = true + IsDispatchSlot = true + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, (5,4--5,27), + { GetSetKeywords = None })], (5,4--5,27)), [], None, + (4,5--5,27), { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,11--4,12) + WithKeyword = None })], (4,0--5,27)); + NestedModule + (SynComponentInfo + ([], None, [], [M], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,12)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (7,14--7,16)), (7,14--7,16))], + None, (7,12--7,16)), None, Const (Unit, (7,19--7,21)), + (7,12--7,16), NoneAtLet, + { LeadingKeyword = Let (7,8--7,11) + InlineKeyword = None + EqualsRange = Some (7,17--7,18) })], (7,8--7,21))], + false, (6,4--7,21), { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,13--6,14) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,21), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,48)] }, set [])) + +(6,4)-(6,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs new file mode 100644 index 00000000000..6a8edb2f309 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs @@ -0,0 +1,9 @@ +// Expected: Warning for module inside interface...end block +module Module + +type IFace = + interface + abstract F : int -> int + module M = + let f () = f () + end diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs.bsl new file mode 100644 index 00000000000..8bcf248f981 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs.bsl @@ -0,0 +1,50 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Interface End 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [IFace], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,10)), + ObjectModel + (Interface, + [AbstractSlot + (SynValSig + ([], SynIdent (F, None), + SynValTyparDecls (None, true), + Fun + (LongIdent (SynLongIdent ([int], [], [None])), + LongIdent (SynLongIdent ([int], [], [None])), + (6,21--6,31), { ArrowRange = (6,25--6,27) }), + SynValInfo + ([[SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None)), false, false, + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + Single None, None, (6,8--6,31), + { LeadingKeyword = Abstract (6,8--6,16) + InlineKeyword = None + WithKeyword = None + EqualsRange = None }), + { IsInstance = true + IsDispatchSlot = true + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, (6,8--6,31), + { GetSetKeywords = None })], (5,4--6,31)), [], None, + (4,5--6,31), { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,11--4,12) + WithKeyword = None })], (4,0--6,31))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--6,31), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,60)] }, set [])) + +(5,4)-(5,13) parse error Unmatched 'class', 'interface' or 'struct' +(7,8)-(7,14) parse error Unexpected keyword 'module' in member definition +(9,4)-(9,7) parse error Incomplete structured construct at or before this point in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs new file mode 100644 index 00000000000..8f808473055 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs @@ -0,0 +1,9 @@ +// Expected: Warning for module inside nested type +module Level1 + +module Level2 = + module Level3 = + type MyType = + | A + module InvalidModule = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs.bsl new file mode 100644 index 00000000000..fa6bc697236 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs.bsl @@ -0,0 +1,69 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Nested Type 01.fs", false, + QualifiedNameOfFile Level1, [], + [SynModuleOrNamespace + ([Level1], false, NamedModule, + [NestedModule + (SynComponentInfo + ([], None, [], [Level2], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (4,0--4,13)), false, + [NestedModule + (SynComponentInfo + ([], None, [], [Level3], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,4--5,17)), false, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyType], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,13--6,19)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (7,14--7,15), + { BarRange = Some (7,12--7,13) })], + (7,12--7,15)), (7,12--7,15)), [], None, + (6,13--7,15), { LeadingKeyword = Type (6,8--6,12) + EqualsRange = Some (6,20--6,21) + WithKeyword = None })], (6,8--7,15)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,12--8,32)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,16), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (x, None), false, None, (9,20--9,21)), + None, Const (Int32 1, (9,24--9,25)), (9,20--9,21), + Yes (9,16--9,25), + { LeadingKeyword = Let (9,16--9,19) + InlineKeyword = None + EqualsRange = Some (9,22--9,23) })], + (9,16--9,25))], false, (8,12--9,25), + { ModuleKeyword = Some (8,12--8,18) + EqualsRange = Some (8,33--8,34) })], false, (5,4--9,25), + { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,18--5,19) })], false, (4,0--9,25), + { ModuleKeyword = Some (4,0--4,6) + EqualsRange = Some (4,14--4,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--9,25), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,50)] }, set [])) + +(8,12)-(8,18) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs new file mode 100644 index 00000000000..a394f64859f --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs @@ -0,0 +1,7 @@ +// Expected: Warning for module inside record +module Module + +type R = + { A : int } + module M4 = + let f () = () diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl new file mode 100644 index 00000000000..51daf2093d3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl @@ -0,0 +1,55 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Record 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [R], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Record + (None, + [SynField + ([], false, Some A, + LongIdent (SynLongIdent ([int], [], [None])), false, + PreXmlDoc ((5,6), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,13), { LeadingKeyword = None + MutableKeyword = None })], + (5,4--5,15)), (5,4--5,15)), [], None, (4,5--5,15), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--5,15)); + NestedModule + (SynComponentInfo + ([], None, [], [M4], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,13)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (7,14--7,16)), (7,14--7,16))], + None, (7,12--7,16)), None, Const (Unit, (7,19--7,21)), + (7,12--7,16), NoneAtLet, + { LeadingKeyword = Let (7,8--7,11) + InlineKeyword = None + EqualsRange = Some (7,17--7,18) })], (7,8--7,21))], + false, (6,4--7,21), { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,14--6,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,21), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,45)] }, set [])) + +(6,4)-(6,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs new file mode 100644 index 00000000000..0eff7380d47 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs @@ -0,0 +1,8 @@ +// Testing: Module inside struct +module Module + +type MyStruct = + struct + module InvalidModule = + let helper = 10 + end diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl new file mode 100644 index 00000000000..38b44cf5f9f --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl @@ -0,0 +1,25 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Struct 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyStruct], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,13)), + ObjectModel (Struct, [], (5,4--5,10)), [], None, (4,5--5,10), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,14--4,15) + WithKeyword = None })], (4,0--5,10))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--5,10), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,32)] }, set [])) + +(5,4)-(5,10) parse error Unmatched 'class', 'interface' or 'struct' +(6,8)-(6,14) parse error Unexpected keyword 'module' in member definition +(8,4)-(8,7) parse error Incomplete structured construct at or before this point in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs new file mode 100644 index 00000000000..313317e35b6 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs @@ -0,0 +1,7 @@ +// Expected: Warning for module in type augmentation +module Module + +type A = + | A + with + module M = begin end diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs.bsl new file mode 100644 index 00000000000..8cd1248d8de --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs.bsl @@ -0,0 +1,32 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type With Augmentation 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,7), { BarRange = Some (5,4--5,5) })], + (5,4--5,7)), (5,4--5,7)), [], None, (4,5--5,7), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = Some (6,4--6,8) })], (4,0--5,7))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--5,7), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,52)] }, set [])) + +(7,8)-(7,14) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(7,8)-(7,14) parse error Unexpected keyword 'module' in type definition. Expected incomplete structured construct at or before this point, 'end' or other token. +(8,0)-(8,0) parse error Incomplete structured construct at or before this point in implementation file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs new file mode 100644 index 00000000000..7c1abaa090c --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs @@ -0,0 +1,8 @@ +// Expected: Warning for module inside union +module Module + +type U = + | A + | B + module M3 = + let f () = () diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl new file mode 100644 index 00000000000..c49a40c24b3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl @@ -0,0 +1,57 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Union 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [U], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,7), { BarRange = Some (5,4--5,5) }); + SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], + (5,4--6,7)), (5,4--6,7)), [], None, (4,5--6,7), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--6,7)); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,13)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (8,14--8,16)), (8,14--8,16))], + None, (8,12--8,16)), None, Const (Unit, (8,19--8,21)), + (8,12--8,16), NoneAtLet, + { LeadingKeyword = Let (8,8--8,11) + InlineKeyword = None + EqualsRange = Some (8,17--8,18) })], (8,8--8,21))], + false, (7,4--8,21), { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,14--7,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,21), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,44)] }, set [])) + +(7,4)-(7,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs b/tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs new file mode 100644 index 00000000000..84a6612add3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs @@ -0,0 +1,8 @@ +// Expected: No warning - module at valid position +module Module + +type A = + | CaseA of int + | CaseB of string +module ValidModule = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs.bsl new file mode 100644 index 00000000000..7471af68c2f --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs.bsl @@ -0,0 +1,68 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Less Indented 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (CaseA, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((5,15), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,15--5,18), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,18), { BarRange = Some (5,4--5,5) }); + SynUnionCase + ([], SynIdent (CaseB, None), + Fields + [SynField + ([], false, None, + LongIdent + (SynLongIdent ([string], [], [None])), false, + PreXmlDoc ((6,15), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,15--6,21), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,21), { BarRange = Some (6,4--6,5) })], + (5,4--6,21)), (5,4--6,21)), [], None, (4,5--6,21), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--6,21)); + NestedModule + (SynComponentInfo + ([], None, [], [ValidModule], + PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,0--7,18)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (8,8--8,9)), None, + Const (Int32 1, (8,12--8,13)), (8,8--8,9), Yes (8,4--8,13), + { LeadingKeyword = Let (8,4--8,7) + InlineKeyword = None + EqualsRange = Some (8,10--8,11) })], (8,4--8,13))], + false, (7,0--8,13), { ModuleKeyword = Some (7,0--7,6) + EqualsRange = Some (7,19--7,20) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,13), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,50)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs b/tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs new file mode 100644 index 00000000000..7ff2c635103 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs @@ -0,0 +1,12 @@ +// Expected: No warning - module not nested +module Module + +type A = + | CaseA of int + | CaseB of string + +module B = + let x = 42 + +type C = + { Field: int } diff --git a/tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs.bsl new file mode 100644 index 00000000000..9b9908dbd51 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs.bsl @@ -0,0 +1,88 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Same Indentation 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (CaseA, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((5,15), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,15--5,18), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,18), { BarRange = Some (5,4--5,5) }); + SynUnionCase + ([], SynIdent (CaseB, None), + Fields + [SynField + ([], false, None, + LongIdent + (SynLongIdent ([string], [], [None])), false, + PreXmlDoc ((6,15), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,15--6,21), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,21), { BarRange = Some (6,4--6,5) })], + (5,4--6,21)), (5,4--6,21)), [], None, (4,5--6,21), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--6,21)); + NestedModule + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((8,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (8,0--8,8)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (9,8--9,9)), None, + Const (Int32 42, (9,12--9,14)), (9,8--9,9), + Yes (9,4--9,14), { LeadingKeyword = Let (9,4--9,7) + InlineKeyword = None + EqualsRange = Some (9,10--9,11) })], + (9,4--9,14))], false, (8,0--9,14), + { ModuleKeyword = Some (8,0--8,6) + EqualsRange = Some (8,9--8,10) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((11,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (11,5--11,6)), + Simple + (Record + (None, + [SynField + ([], false, Some Field, + LongIdent (SynLongIdent ([int], [], [None])), false, + PreXmlDoc ((12,6), FSharp.Compiler.Xml.XmlDocCollector), + None, (12,6--12,16), { LeadingKeyword = None + MutableKeyword = None })], + (12,4--12,18)), (12,4--12,18)), [], None, (11,5--12,18), + { LeadingKeyword = Type (11,0--11,4) + EqualsRange = Some (11,7--11,8) + WithKeyword = None })], (11,0--12,18))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--12,18), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,43)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs b/tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs new file mode 100644 index 00000000000..fa8640c4fa0 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs @@ -0,0 +1,7 @@ +// Expected: Depends on verbose syntax rules +module Module + +type TypeA = + | A;; + module ModuleAfterDelimiter = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs.bsl new file mode 100644 index 00000000000..f3af1f613ca --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs.bsl @@ -0,0 +1,49 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module With Semicolon Delimiter 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [TypeA], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,10)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,7), { BarRange = Some (5,4--5,5) })], + (5,4--5,7)), (5,4--5,7)), [], None, (4,5--5,7), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,11--4,12) + WithKeyword = None })], (4,0--5,7)); + NestedModule + (SynComponentInfo + ([], None, [], [ModuleAfterDelimiter], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,31)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (7,12--7,13)), + None, Const (Int32 1, (7,16--7,17)), (7,12--7,13), + Yes (7,8--7,17), { LeadingKeyword = Let (7,8--7,11) + InlineKeyword = None + EqualsRange = Some (7,14--7,15) })], + (7,8--7,17))], false, (6,4--7,17), + { ModuleKeyword = Some (6,4--6,10) + EqualsRange = Some (6,32--6,33) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,44)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs b/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs new file mode 100644 index 00000000000..fe683ce7045 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs @@ -0,0 +1,10 @@ +// Expected: Multiple warnings for module, type, exception, and open +module Module + +type MultiTest = + | Case1 + | Case2 + module NestedModule = begin end + type NestedType = int + exception NestedExc of string + open System.Collections diff --git a/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs.bsl new file mode 100644 index 00000000000..c2c35d68f89 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs.bsl @@ -0,0 +1,79 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Multiple Invalid Constructs In Type 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MultiTest], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,14)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (Case1, None), Fields [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,11), { BarRange = Some (5,4--5,5) }); + SynUnionCase + ([], SynIdent (Case2, None), Fields [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,11), { BarRange = Some (6,4--6,5) })], + (5,4--6,11)), (5,4--6,11)), [], None, (4,5--6,11), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,15--4,16) + WithKeyword = None })], (4,0--6,11)); + NestedModule + (SynComponentInfo + ([], None, [], [NestedModule], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,23)), false, [], false, (7,4--7,35), + { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,24--7,25) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [NestedType], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,9--8,19)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (8,22--8,25)), (8,22--8,25)), [], None, (8,9--8,25), + { LeadingKeyword = Type (8,4--8,8) + EqualsRange = Some (8,20--8,21) + WithKeyword = None })], (8,4--8,25)); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (NestedExc, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([string], [], [None])), + false, + PreXmlDoc ((9,27), FSharp.Compiler.Xml.XmlDocCollector), + None, (9,27--9,33), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDocEmpty, None, (9,14--9,33), { BarRange = None }), + None, PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (9,4--9,33)), None, [], (9,4--9,33)), (9,4--9,33)); + Open + (ModuleOrNamespace + (SynLongIdent + ([System; Collections], [(10,15--10,16)], [None; None]), + (10,9--10,27)), (10,4--10,27))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--10,27), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,68)] }, set [])) + +(7,4)-(7,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(8,4)-(8,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(9,4)-(9,13) parse error Exceptions must be defined at module level, not inside types. +(10,4)-(10,8) parse error 'open' declarations must appear at module level, not inside types. diff --git a/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs new file mode 100644 index 00000000000..f9ad5ba9673 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs @@ -0,0 +1,9 @@ +// Testing: Module inside type at deep nesting level +module Root + +module Level1 = + module Level2 = + module Level3 = + type TypeWithInvalidModule = + module InvalidModule = + let x = 1 diff --git a/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl new file mode 100644 index 00000000000..14fa4838071 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl @@ -0,0 +1,71 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Nested Module Hierarchy 01.fs", false, + QualifiedNameOfFile Root, [], + [SynModuleOrNamespace + ([Root], false, NamedModule, + [NestedModule + (SynComponentInfo + ([], None, [], [Level1], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (4,0--4,13)), false, + [NestedModule + (SynComponentInfo + ([], None, [], [Level2], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,4--5,17)), false, + [NestedModule + (SynComponentInfo + ([], None, [], [Level3], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,8--6,21)), false, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [TypeWithInvalidModule], + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (7,17--7,38)), + Simple (None (7,17--7,40), (7,17--7,40)), [], None, + (7,17--7,40), { LeadingKeyword = Type (7,12--7,16) + EqualsRange = Some (7,39--7,40) + WithKeyword = None })], + (7,12--7,40)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((8,16), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,16--8,36)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,20), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo + ([], SynArgInfo ([], false, None)), None), + Named + (SynIdent (x, None), false, None, + (9,24--9,25)), None, + Const (Int32 1, (9,28--9,29)), (9,24--9,25), + Yes (9,20--9,29), + { LeadingKeyword = Let (9,20--9,23) + InlineKeyword = None + EqualsRange = Some (9,26--9,27) })], + (9,20--9,29))], false, (8,16--9,29), + { ModuleKeyword = Some (8,16--8,22) + EqualsRange = Some (8,37--8,38) })], false, + (6,8--9,29), { ModuleKeyword = Some (6,8--6,14) + EqualsRange = Some (6,22--6,23) })], false, + (5,4--9,29), { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,18--5,19) })], false, + (4,0--9,29), { ModuleKeyword = Some (4,0--4,6) + EqualsRange = Some (4,14--4,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--9,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,52)] }, set [])) + +(8,16)-(8,22) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(7,17)-(7,40) parse error A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'. diff --git a/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl b/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl index 536c4cc9e54..b494146b3bb 100644 --- a/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl @@ -32,3 +32,5 @@ ImplFile { ConditionalDirectives = [] WarnDirectives = [] CodeComments = [] }, set [])) + +(3,11)-(3,15) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs b/tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs new file mode 100644 index 00000000000..f8c3782c251 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs @@ -0,0 +1,4 @@ +// Expected: No warnings - valid in verbose syntax +module Module + +type A = A;;type B = A;;module C = ();;exception D;;module E = C;;let f () = ();;open System;;module G = module H = E;; diff --git a/tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs.bsl b/tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs.bsl new file mode 100644 index 00000000000..6d4170c7795 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs.bsl @@ -0,0 +1,82 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/One Line With Semicolons 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (4,9--4,10)), (4,9--4,10)), [], None, (4,5--4,10), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--4,10)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,17--4,18)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (4,21--4,22)), (4,21--4,22)), [], None, (4,17--4,22), + { LeadingKeyword = Type (4,12--4,16) + EqualsRange = Some (4,19--4,20) + WithKeyword = None })], (4,12--4,22)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((4,24), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (4,24--4,32)), false, + [Expr (Const (Unit, (4,35--4,37)), (4,35--4,37))], false, + (4,24--4,37), { ModuleKeyword = Some (4,24--4,30) + EqualsRange = Some (4,33--4,34) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (D, None), Fields [], PreXmlDocEmpty, None, + (4,49--4,50), { BarRange = None }), None, + PreXmlDoc ((4,39), FSharp.Compiler.Xml.XmlDocCollector), + None, (4,39--4,50)), None, [], (4,39--4,50)), (4,39--4,50)); + ModuleAbbrev (E, [C], (4,52--4,64)); + Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((4,66), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (4,72--4,74)), (4,72--4,74))], + None, (4,70--4,74)), None, Const (Unit, (4,77--4,79)), + (4,70--4,74), NoneAtLet, { LeadingKeyword = Let (4,66--4,69) + InlineKeyword = None + EqualsRange = Some (4,75--4,76) })], + (4,66--4,79)); + Open + (ModuleOrNamespace + (SynLongIdent ([System], [], [None]), (4,86--4,92)), + (4,81--4,92)); + NestedModule + (SynComponentInfo + ([], None, [], [G], + PreXmlDoc ((4,94), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (4,94--4,102)), false, + [ModuleAbbrev (H, [E], (4,105--4,117))], false, (4,94--4,117), + { ModuleKeyword = Some (4,94--4,100) + EqualsRange = Some (4,103--4,104) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--4,117), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,50)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs b/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs new file mode 100644 index 00000000000..60c5a5618f7 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs @@ -0,0 +1,6 @@ +// Expected: Warning for open inside type +module Module + +type A = + | A + open System diff --git a/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl new file mode 100644 index 00000000000..84f5af755cd --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl @@ -0,0 +1,13 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Open Inside Type 01.fs", false, + QualifiedNameOfFile Open Inside Type 01, [], + [SynModuleOrNamespace + ([Open Inside Type 01], false, AnonModule, [], PreXmlDocEmpty, [], None, + (7,0--7,0), { LeadingKeyword = None })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,41)] }, set [])) + +(6,4)-(6,8) parse error 'open' declarations must appear at module level, not inside types. +(6,4)-(6,8) parse error Unexpected keyword 'open' in member definition diff --git a/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs new file mode 100644 index 00000000000..f3f576f3e71 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs @@ -0,0 +1,4 @@ +// Expected: No warning - all declarations at same indentation level +module Module + +type A = A type B = A module C = type CC = int diff --git a/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl new file mode 100644 index 00000000000..81c58ccf689 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl @@ -0,0 +1,57 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Same Line Declarations 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (4,9--4,10)), (4,9--4,10)), [], None, (4,5--4,10), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--4,10)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,16--4,17)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (4,20--4,21)), (4,20--4,21)), [], None, (4,16--4,21), + { LeadingKeyword = Type (4,11--4,15) + EqualsRange = Some (4,18--4,19) + WithKeyword = None })], (4,11--4,21)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((4,22), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (4,22--4,30)), false, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [CC], + PreXmlDoc ((4,33), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,38--4,40)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (4,43--4,46)), (4,43--4,46)), [], None, (4,38--4,46), + { LeadingKeyword = Type (4,33--4,37) + EqualsRange = Some (4,41--4,42) + WithKeyword = None })], (4,33--4,46))], false, + (4,22--4,46), { ModuleKeyword = Some (4,22--4,28) + EqualsRange = Some (4,31--4,32) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--4,46), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,68)] }, set [])) diff --git a/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs b/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs new file mode 100644 index 00000000000..bdfc1d67396 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs @@ -0,0 +1,7 @@ +// Expected: Warning for type inside type +module Module + +type A = + | A + type NestedType = + | B of int diff --git a/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs.bsl new file mode 100644 index 00000000000..2890c48d450 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs.bsl @@ -0,0 +1,54 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Type Inside Type 01.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,7), { BarRange = Some (5,4--5,5) })], + (5,4--5,7)), (5,4--5,7)), [], None, (4,5--5,7), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,7--4,8) + WithKeyword = None })], (4,0--5,7)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [NestedType], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,9--6,19)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (B, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((7,15), FSharp.Compiler.Xml.XmlDocCollector), + None, (7,15--7,18), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), + None, (7,10--7,18), { BarRange = Some (7,8--7,9) })], + (7,8--7,18)), (7,8--7,18)), [], None, (6,9--7,18), + { LeadingKeyword = Type (6,4--6,8) + EqualsRange = Some (6,20--6,21) + WithKeyword = None })], (6,4--7,18))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,18), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,41)] }, set [])) + +(6,4)-(6,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Union 08.fs b/tests/service/data/SyntaxTree/Type/Union 08.fs new file mode 100644 index 00000000000..98f400d4d77 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Union 08.fs @@ -0,0 +1,10 @@ +module Module + +type A = + | A + +module ThisIsFine = + let f () = () + +type B = + | B \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Union 08.fs.bsl b/tests/service/data/SyntaxTree/Type/Union 08.fs.bsl new file mode 100644 index 00000000000..f018775dd8a --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Union 08.fs.bsl @@ -0,0 +1,67 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Union 08.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [A], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (4,6--4,7), { BarRange = Some (4,4--4,5) })], + (4,4--4,7)), (4,4--4,7)), [], None, (3,5--4,7), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--4,7)); + NestedModule + (SynComponentInfo + ([], None, [], [ThisIsFine], + PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,0--6,17)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (7,10--7,12)), (7,10--7,12))], + None, (7,8--7,12)), None, Const (Unit, (7,15--7,17)), + (7,8--7,12), NoneAtLet, + { LeadingKeyword = Let (7,4--7,7) + InlineKeyword = None + EqualsRange = Some (7,13--7,14) })], (7,4--7,17))], + false, (6,0--7,17), { ModuleKeyword = Some (6,0--6,6) + EqualsRange = Some (6,18--6,19) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((9,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (9,5--9,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (10,6--10,7), { BarRange = Some (10,4--10,5) })], + (10,4--10,7)), (10,4--10,7)), [], None, (9,5--10,7), + { LeadingKeyword = Type (9,0--9,4) + EqualsRange = Some (9,7--9,8) + WithKeyword = None })], (9,0--10,7))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--10,7), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set []))