From 1799aaf29034f01357684c7716b6eed8fc76468a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 23 Apr 2025 15:27:24 +0100 Subject: [PATCH 01/36] make attribute targets mismatches a warning and not an error. --- .../Checking/Expressions/CheckExpressions.fs | 2 +- .../AttributeUsage/AttributeUsage.fs | 215 +++++++++--------- .../CustomAttributes/Basic/Basic.fs | 7 +- .../EntryPoint/EntryPoint.fs | 2 +- .../LetBindings/Basic/Basic.fs | 4 +- .../ErrorMessages/TailCallAttribute.fs | 32 +-- 6 files changed, 125 insertions(+), 137 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 5f390038e35..e2d21975311 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -11367,7 +11367,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn if (directedTgts = AttributeTargets.Assembly || directedTgts = AttributeTargets.Module) then error(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElementUseDo(), mAttr)) else - error(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElement(), mAttr)) + warning(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElement(), mAttr)) match ResolveObjectConstructor cenv.nameResolver env.DisplayEnv mAttr ad ty with | Exception _ when canFail = TcCanFail.IgnoreAllErrors || canFail = TcCanFail.IgnoreMemberResoutionError -> [ ], true 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 c7c2cf72eca..f027745b73e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -104,10 +104,10 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 21, Col 21, Line 21, Col 22, "This attribute is not valid for use on this language element") - (Error 842, Line 24, Col 21, Line 24, Col 29, "This attribute is not valid for use on this language element") - (Error 842, Line 27, Col 7, Line 27, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 18, Col 7, Line 18, Col 8, "This attribute is not valid for use on this language element") + (Warning 842, Line 21, Col 21, Line 21, Col 22, "This attribute is not valid for use on this language element") + (Warning 842, Line 24, Col 21, Line 24, Col 29, "This attribute is not valid for use on this language element") + (Warning 842, Line 27, Col 7, Line 27, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 18, Col 7, Line 18, Col 8, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargets02.fs # E_AttributeTargets02.fs @@ -117,9 +117,10 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 14, Col 7, Line 14, Col 34, "This attribute is not valid for use on this language element") - (Error 842, Line 24, Col 7, Line 24, Col 36, "This attribute is not valid for use on this language element") - (Error 842, Line 29, Col 15, Line 29, Col 47, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 7, Line 14, Col 34, "This attribute is not valid for use on this language element") + (Warning 842, Line 24, Col 7, Line 24, Col 36, "This attribute is not valid for use on this language element") + (Warning 842, Line 29, Col 15, Line 29, Col 47, "This attribute is not valid for use on this language element") + (Error 3172, Line 28, Col 14, Line 28, Col 17, "A property's getter and setter must have the same type. Property 'Foo' has getter of type 'int' but setter of type 'obj'.") ] // SOURCE=E_AttributeTargetIsField01.fs # E_AttributeTargetIsField01.fs @@ -140,23 +141,23 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 9, Col 3, Line 9, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 12, Col 3, Line 12, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 15, Col 3, Line 15, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 18, Col 3, Line 18, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 21, Col 3, Line 21, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 24, Col 3, Line 24, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 27, Col 3, Line 27, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 30, Col 3, Line 30, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 33, Col 3, Line 33, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 36, Col 3, Line 36, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 39, Col 3, Line 39, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 42, Col 3, Line 42, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 45, Col 3, Line 45, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 49, Col 3, Line 49, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 56, Col 3, Line 56, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 64, Col 3, Line 64, Col 12, "This attribute is not valid for use on this language element") - (Error 842, Line 66, Col 7, Line 66, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 9, Col 3, Line 9, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 12, Col 3, Line 12, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 3, Line 15, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 18, Col 3, Line 18, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 21, Col 3, Line 21, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 24, Col 3, Line 24, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 27, Col 3, Line 27, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 30, Col 3, Line 30, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 33, Col 3, Line 33, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 36, Col 3, Line 36, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 39, Col 3, Line 39, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 42, Col 3, Line 42, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 45, Col 3, Line 45, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 49, Col 3, Line 49, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 56, Col 3, Line 56, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 64, Col 3, Line 64, Col 12, "This attribute is not valid for use on this language element") + (Warning 842, Line 66, Col 7, Line 66, Col 16, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsField02.fs # E_AttributeTargetIsField02.fs @@ -194,17 +195,17 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 9, Col 3, Line 9, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 12, Col 3, Line 12, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 15, Col 3, Line 15, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 18, Col 3, Line 18, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 21, Col 3, Line 21, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 24, Col 3, Line 24, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 26, Col 7, Line 26, Col 17, "This attribute is not valid for use on this language element") - (Error 842, Line 28, Col 3, Line 28, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 31, Col 3, Line 31, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 34, Col 3, Line 34, Col 13, "This attribute is not valid for use on this language element") - (Error 842, Line 39, Col 3, Line 39, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 9, Col 3, Line 9, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 12, Col 3, Line 12, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 3, Line 15, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 18, Col 3, Line 18, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 21, Col 3, Line 21, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 24, Col 3, Line 24, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 26, Col 7, Line 26, Col 17, "This attribute is not valid for use on this language element") + (Warning 842, Line 28, Col 3, Line 28, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 31, Col 3, Line 31, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 34, Col 3, Line 34, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 39, Col 3, Line 39, Col 13, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsMethod03.fs # E_AttributeTargetIsMethod03.fs @@ -225,21 +226,21 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 12, Col 6, Line 12, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 15, Col 6, Line 15, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 18, Col 6, Line 18, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 20, Col 10, Line 20, Col 20, "This attribute is not valid for use on this language element") - (Error 842, Line 22, Col 6, Line 22, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 25, Col 6, Line 25, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 28, Col 6, Line 28, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 31, Col 6, Line 31, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 34, Col 6, Line 34, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 37, Col 6, Line 37, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 39, Col 10, Line 39, Col 20, "This attribute is not valid for use on this language element") - (Error 842, Line 41, Col 6, Line 41, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 44, Col 6, Line 44, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 47, Col 6, Line 47, Col 16, "This attribute is not valid for use on this language element") - (Error 842, Line 52, Col 6, Line 52, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 12, Col 6, Line 12, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 6, Line 15, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 18, Col 6, Line 18, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 20, Col 10, Line 20, Col 20, "This attribute is not valid for use on this language element") + (Warning 842, Line 22, Col 6, Line 22, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 25, Col 6, Line 25, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 28, Col 6, Line 28, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 31, Col 6, Line 31, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 34, Col 6, Line 34, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 37, Col 6, Line 37, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 39, Col 10, Line 39, Col 20, "This attribute is not valid for use on this language element") + (Warning 842, Line 41, Col 6, Line 41, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 44, Col 6, Line 44, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 47, Col 6, Line 47, Col 16, "This attribute is not valid for use on this language element") + (Warning 842, Line 52, Col 6, Line 52, Col 16, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsMethod04.fs # E_AttributeTargetIsMethod04.fs @@ -250,8 +251,8 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 10, Col 3, Line 10, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 13, Col 3, Line 13, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 10, Col 3, Line 10, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 13, Col 3, Line 13, Col 15, "This attribute is not valid for use on this language element") ] // SOURCE=E_ConditionalAttribute.fs SCFLAGS="--test:ErrorRanges" # E_ConditionalAttribute.fs @@ -293,7 +294,7 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 12, Col 3, Line 12, Col 6, "This attribute is not valid for use on this language element") + (Warning 842, Line 12, Col 3, Line 12, Col 6, "This attribute is not valid for use on this language element") ] // SOURCE=AttributeTargetIsStruct.fs # AttributeTargetIsStruct.fs @@ -342,18 +343,18 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 13, Col 3, Line 13, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 19, Col 3, Line 19, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 22, Col 11, Line 22, Col 22, "This attribute is not valid for use on this language element") - (Error 842, Line 25, Col 3, Line 25, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 34, Col 3, Line 34, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 35, Col 3, Line 35, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 40, Col 3, Line 40, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 41, Col 3, Line 41, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 49, Col 3, Line 49, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 50, Col 3, Line 50, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 53, Col 3, Line 53, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 54, Col 3, Line 54, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 13, Col 3, Line 13, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 19, Col 3, Line 19, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 22, Col 11, Line 22, Col 22, "This attribute is not valid for use on this language element") + (Warning 842, Line 25, Col 3, Line 25, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 34, Col 3, Line 34, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 35, Col 3, Line 35, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 40, Col 3, Line 40, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 41, Col 3, Line 41, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 49, Col 3, Line 49, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 50, Col 3, Line 50, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 53, Col 3, Line 53, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 54, Col 3, Line 54, Col 18, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsClass.fs # E_AttributeTargetIsClass.fs @@ -372,9 +373,9 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 13, Col 3, Line 13, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 22, Col 10, Line 22, Col 22, "This attribute is not valid for use on this language element") + (Warning 842, Line 13, Col 3, Line 13, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 22, Col 10, Line 22, Col 22, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsClass01.fs # E_AttributeTargetIsClass01.fs @@ -393,8 +394,8 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 7, Col 3, Line 7, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 10, Col 10, Line 10, Col 25, "This attribute is not valid for use on this language element") + (Warning 842, Line 7, Col 3, Line 7, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 10, Col 10, Line 10, Col 25, "This attribute is not valid for use on this language element") ] // SOURCE=MarshalAsAttribute.fs # MarshalAsAttribute.fs @@ -480,7 +481,7 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 14, Col 5, Line 14, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 5, Line 14, Col 15, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsField03.fs # E_AttributeTargetIsField03.fs @@ -491,8 +492,8 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 14, Col 5, Line 14, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 15, Col 5, Line 15, Col 25, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 5, Line 14, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 5, Line 15, Col 25, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsProperty01.fs # E_AttributeTargetIsField03.fs @@ -511,8 +512,8 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 14, Col 5, Line 14, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 15, Col 5, Line 15, Col 25, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 5, Line 14, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 5, Line 15, Col 25, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsCtor01.fs # E_AttributeTargetIsCtor01.fs @@ -531,10 +532,10 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 9, Col 15, Line 9, Col 27, "This attribute is not valid for use on this language element") - (Error 842, Line 11, Col 16, Line 11, Col 28, "This attribute is not valid for use on this language element") - (Error 842, Line 14, Col 15, Line 14, Col 27, "This attribute is not valid for use on this language element") - (Error 842, Line 17, Col 16, Line 17, Col 28, "This attribute is not valid for use on this language element") + (Warning 842, Line 9, Col 15, Line 9, Col 27, "This attribute is not valid for use on this language element") + (Warning 842, Line 11, Col 16, Line 11, Col 28, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 15, Line 14, Col 27, "This attribute is not valid for use on this language element") + (Warning 842, Line 17, Col 16, Line 17, Col 28, "This attribute is not valid for use on this language element") ] // SOURCE=AttributeTargetsIsEnum01.fs # AttributeTargetsIsEnum01.fs @@ -568,10 +569,10 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 20, Col 3, Line 20, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 21, Col 3, Line 21, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 22, Col 3, Line 22, Col 17, "This attribute is not valid for use on this language element") + (Warning 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 20, Col 3, Line 20, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 21, Col 3, Line 21, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 22, Col 3, Line 22, Col 17, "This attribute is not valid for use on this language element") ] // SOURCE=AttributeTargetsIsDelegate01.fs # AttributeTargetsIsDelegate01.fs @@ -605,10 +606,10 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 19, Col 3, Line 19, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 20, Col 3, Line 20, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 21, Col 3, Line 21, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 22, Col 3, Line 22, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 19, Col 3, Line 19, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 20, Col 3, Line 20, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 21, Col 3, Line 21, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 22, Col 3, Line 22, Col 13, "This attribute is not valid for use on this language element") ] [] @@ -654,10 +655,10 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 11, Col 3, Line 11, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 14, Col 3, Line 14, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 18, Col 3, Line 18, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 11, Col 3, Line 11, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 3, Line 14, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 18, Col 3, Line 18, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") ] // SOURCE= E_AttributeTargetIsClass02.fs # E_AttributeTargetIsClass02.fs @@ -676,18 +677,18 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 15, Col 3, Line 15, Col 18, "This attribute is not valid for use on this language element"); - (Error 842, Line 16, Col 3, Line 16, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 20, Col 3, Line 20, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 21, Col 3, Line 21, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 26, Col 3, Line 26, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 27, Col 3, Line 27, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 34, Col 3, Line 34, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 35, Col 3, Line 35, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 43, Col 3, Line 43, Col 18, "This attribute is not valid for use on this language element") - (Error 842, Line 44, Col 3, Line 44, Col 15, "This attribute is not valid for use on this language element") - (Error 842, Line 47, Col 3, Line 47, Col 14, "This attribute is not valid for use on this language element") - (Error 842, Line 48, Col 3, Line 48, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 3, Line 15, Col 18, "This attribute is not valid for use on this language element"); + (Warning 842, Line 16, Col 3, Line 16, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 20, Col 3, Line 20, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 21, Col 3, Line 21, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 26, Col 3, Line 26, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 27, Col 3, Line 27, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 34, Col 3, Line 34, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 35, Col 3, Line 35, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 43, Col 3, Line 43, Col 18, "This attribute is not valid for use on this language element") + (Warning 842, Line 44, Col 3, Line 44, Col 15, "This attribute is not valid for use on this language element") + (Warning 842, Line 47, Col 3, Line 47, Col 14, "This attribute is not valid for use on this language element") + (Warning 842, Line 48, Col 3, Line 48, Col 18, "This attribute is not valid for use on this language element") ] // SOURCE= CLIMutableAttribute01.fs # CLIMutableAttribute01.fs @@ -756,8 +757,8 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) = (Error 934, Line 33, Col 10, Line 33, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute") (Error 934, Line 36, Col 10, Line 36, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute") (Error 934, Line 39, Col 10, Line 39, Col 13, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute") - (Error 842, Line 41, Col 7, Line 41, Col 23, "This attribute is not valid for use on this language element") - (Error 842, Line 44, Col 7, Line 44, Col 23, "This attribute is not valid for use on this language element") + (Warning 842, Line 41, Col 7, Line 41, Col 23, "This attribute is not valid for use on this language element") + (Warning 842, Line 44, Col 7, Line 44, Col 23, "This attribute is not valid for use on this language element") (Error 935, Line 54, Col 10, Line 54, Col 11, "Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal") ] @@ -775,8 +776,8 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) = (Error 934, Line 33, Col 10, Line 33, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute") (Error 934, Line 36, Col 10, Line 36, Col 11, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute") (Error 934, Line 39, Col 10, Line 39, Col 13, "Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute") - (Error 842, Line 41, Col 7, Line 41, Col 23, "This attribute is not valid for use on this language element") - (Error 842, Line 44, Col 7, Line 44, Col 23, "This attribute is not valid for use on this language element") + (Warning 842, Line 41, Col 7, Line 41, Col 23, "This attribute is not valid for use on this language element") + (Warning 842, Line 44, Col 7, Line 44, Col 23, "This attribute is not valid for use on this language element") (Error 935, Line 54, Col 10, Line 54, Col 11, "Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal") ] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs index 1e3c99dc8a5..44ee388af9d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/Basic/Basic.fs @@ -61,7 +61,7 @@ module CustomAttributes_Basic = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 15, Col 7, Line 15, Col 17, "This attribute is not valid for use on this language element") + (Warning 842, Line 15, Col 7, Line 15, Col 17, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeApplication04.fs SCFLAGS="--test:ErrorRanges" # E_AttributeApplication04.fs @@ -71,7 +71,7 @@ module CustomAttributes_Basic = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 14, Col 3, Line 14, Col 13, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 3, Line 14, Col 13, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeApplication05.fs SCFLAGS="--test:ErrorRanges" # E_AttributeApplication05.fs @@ -81,7 +81,8 @@ module CustomAttributes_Basic = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 842, Line 8, Col 7, Line 8, Col 8, "This attribute is not valid for use on this language element") + (Warning 842, Line 8, Col 7, Line 8, Col 8, "This attribute is not valid for use on this language element") + (Error 824, Line 8, Col 7, Line 8, Col 8, "Attributes are not permitted on 'let' bindings in expressions") (Warning 20, Line 8, Col 1, Line 8, Col 31, "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") ] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/EntryPoint/EntryPoint.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/EntryPoint/EntryPoint.fs index ce51bcf6c14..38b84fb6498 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/EntryPoint/EntryPoint.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/EntryPoint/EntryPoint.fs @@ -75,7 +75,7 @@ module EntryPoint = |> compile |> shouldFail |> withDiagnostics [ - (Error 842, Line 9, Col 3, Line 9, Col 13, """This attribute is not valid for use on this language element""") + (Warning 842, Line 9, Col 3, Line 9, Col 13, """This attribute is not valid for use on this language element""") ] // SOURCE=E_twoattributesonsamefunction001.fs SCFLAGS="--test:ErrorRanges" # E_twoattributesonsamefunction001.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/LetBindings/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/LetBindings/Basic/Basic.fs index c0a19c9ad3e..b59d28cbdd2 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/LetBindings/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/LetBindings/Basic/Basic.fs @@ -53,9 +53,9 @@ module LetBindings_Basic = |> shouldFail |> withDiagnostics [ (Error 683, Line 14, Col 6, Line 14, Col 27, "Attributes are not allowed within patterns") - (Error 842, Line 14, Col 8, Line 14, Col 25, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 8, Line 14, Col 25, "This attribute is not valid for use on this language element") (Error 683, Line 14, Col 42, Line 14, Col 63, "Attributes are not allowed within patterns") - (Error 842, Line 14, Col 44, Line 14, Col 61, "This attribute is not valid for use on this language element") + (Warning 842, Line 14, Col 44, Line 14, Col 61, "This attribute is not valid for use on this language element") ] // SOURCE=E_ErrorsForInlineValue.fs SCFLAGS="--test:ErrorRanges" # E_ErrorsForInlineValue.fs diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs index 1b68505ab1e..81ce04fc05a 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs @@ -245,7 +245,7 @@ namespace N [] let ``Warn successfully for invalid tailcalls in type methods`` () = - """ + FSharp """ namespace N module M = @@ -261,29 +261,12 @@ namespace N printfn "M2 called" this.M1() + 2 // should warn """ - |> FSharp |> withLangVersion80 |> compile |> shouldFail - |> withResults [ - { Error = Warning 3569 - Range = { StartLine = 10 - StartColumn = 17 - EndLine = 10 - EndColumn = 26 } - Message = - "The member or function 'M2' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } - { Error = Warning 3569 - Range = { StartLine = 15 - StartColumn = 17 - EndLine = 15 - EndColumn = 26 } - Message = -#if Debug - "The member or function 'M2' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } -#else - "The member or function 'M1' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } -#endif + |> withDiagnostics [ + (Warning 3569, Line 10, Col 17, Line 10, Col 26, "The member or function 'M2' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way."); + (Warning 3569, Line 15, Col 17, Line 15, Col 26, "The member or function 'M1' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way.") ] [] @@ -1481,7 +1464,10 @@ namespace N |> withLangVersionPreview |> compile |> shouldFail - |> withSingleDiagnostic (Error 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") + |> withDiagnostics [ + (Warning 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") + (Warning 3861, Line 7, Col 13, Line 7, Col 18, "The TailCall attribute should only be applied to recursive functions.") + ] [] let ``Error about attribute on recursive let-bound value`` () = @@ -1497,7 +1483,7 @@ namespace N |> withLangVersionPreview |> compile |> shouldFail - |> withSingleDiagnostic (Error 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") + |> withSingleDiagnostic (Warning 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") [] let ``Warn about self-defined attribute`` () = // is the analysis available for users of older FSharp.Core versions From 55507e9e7e98e640678932f96a25cb3bacc82904 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 23 Apr 2025 15:39:04 +0100 Subject: [PATCH 02/36] release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md index 16f5721e22a..05e15a667dd 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md @@ -48,6 +48,7 @@ * Warning for "useless null handling" works with piped syntax constructs now ([PR #18331](https://github.com/dotnet/fsharp/pull/18331)) * Make indent in generated overridden member code depend on the context, not fix to 4. ([PR #18341](https://github.com/dotnet/fsharp/pull/18341)) * Adjust caller info attribute error message range ([PR #18388](https://github.com/dotnet/fsharp/pull/18388)) +* Make attribute targets mismatch a warning and not an error ([PR #18492](https://github.com/dotnet/fsharp/pull/18492)) ### Breaking Changes * Struct unions with overlapping fields now generate mappings needed for reading via reflection ([Issue #18121](https://github.com/dotnet/fsharp/issues/17797), [PR #18274](https://github.com/dotnet/fsharp/pull/17877)) From 17380183feebe6a1cf30a8f678965b6cd689de82 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 23 Apr 2025 16:19:59 +0100 Subject: [PATCH 03/36] update tests --- .../PatternMatchCompilationTests.fs | 1 + .../Language/StructActivePatternTests.fs | 2 +- tests/fsharp/typecheck/sigs/neg16.bsl | 4 +- tests/fsharp/typecheck/sigs/neg20.bsl | 46 +++++++++---------- tests/fsharp/typecheck/sigs/neg32.bsl | 2 +- .../fsharp/typecheck/sigs/version50/neg20.bsl | 46 +++++++++---------- .../UnitsOfMeasure/WithOOP/E_GenericUOM01.fs | 2 +- 7 files changed, 52 insertions(+), 51 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs b/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs index 1b6d54d3577..cf870698077 100644 --- a/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs @@ -41,6 +41,7 @@ match () with dumpDiagnostics checkResults |> shouldEqual [ "(3,2--3,25): Attributes are not allowed within patterns" "(3,4--3,23): This attribute is not valid for use on this language element" + "(3,17--3,22): This is not a valid constant expression or custom attribute value" ] diff --git a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs index aac654f549c..4c2451142fa 100644 --- a/tests/fsharp/Compiler/Language/StructActivePatternTests.fs +++ b/tests/fsharp/Compiler/Language/StructActivePatternTests.fs @@ -176,7 +176,7 @@ let (|Foo|_|) x = ValueNone [] let (|Foo|_|) x = ValueNone """ - [|(FSharpDiagnosticSeverity.Error, 842, (2, 3, 2, 9), + [|(FSharpDiagnosticSeverity.Warning, 842, (2, 3, 2, 9), "This attribute is not valid for use on this language element"); (FSharpDiagnosticSeverity.Error, 3350, (3, 6, 3, 13), "Feature 'Boolean-returning and return-type-directed partial active patterns' is not available in F# 8.0. Please use language version 9.0 or greater.")|] diff --git a/tests/fsharp/typecheck/sigs/neg16.bsl b/tests/fsharp/typecheck/sigs/neg16.bsl index 4c2300470f7..448ca9127be 100644 --- a/tests/fsharp/typecheck/sigs/neg16.bsl +++ b/tests/fsharp/typecheck/sigs/neg16.bsl @@ -13,9 +13,9 @@ neg16.fs(44,10,44,11): typecheck error FS0934: Records, union, abbreviations and neg16.fs(47,10,47,13): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute -neg16.fs(49,7,49,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg16.fs(49,7,49,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg16.fs(52,7,52,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg16.fs(52,7,52,23): typecheck warning FS0842: This attribute is not valid for use on this language element neg16.fs(59,8,59,17): typecheck error FS0001: This expression was expected to have type 'Choice<'a,'b>' diff --git a/tests/fsharp/typecheck/sigs/neg20.bsl b/tests/fsharp/typecheck/sigs/neg20.bsl index 5229dcaacf6..28fa11b53f7 100644 --- a/tests/fsharp/typecheck/sigs/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/neg20.bsl @@ -213,53 +213,53 @@ neg20.fs(190,34,190,39): typecheck error FS0001: This expression was expected to but here has type 'objnull' -neg20.fs(195,5,195,10): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(195,5,195,10): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(198,5,198,11): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(198,5,198,11): typecheck warning FS0842: This attribute is not valid for use on this language element neg20.fs(202,7,202,9): typecheck error FS0825: The 'DefaultValue' attribute may only be used on 'val' declarations -neg20.fs(204,5,204,14): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(204,5,204,14): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(207,5,207,11): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(207,5,207,11): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(210,5,210,12): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(210,5,210,12): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(213,5,213,33): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(213,5,213,33): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(216,5,216,12): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(216,5,216,12): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(219,5,219,15): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(219,5,219,15): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(222,5,222,31): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(222,5,222,31): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(225,5,225,22): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(225,5,225,22): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(228,5,228,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(228,5,228,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(231,5,231,21): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(231,5,231,21): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(234,5,234,34): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(234,5,234,34): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(237,5,237,34): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(237,5,237,34): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(240,5,240,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(240,5,240,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(243,5,243,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(243,5,243,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(249,9,249,27): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(249,9,249,27): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(255,5,255,28): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(255,5,255,28): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(258,5,258,38): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(258,5,258,38): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(261,5,261,17): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(261,5,261,17): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(265,5,265,24): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(265,5,265,24): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(268,5,268,27): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(268,5,268,27): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(271,5,271,15): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(271,5,271,15): typecheck warning FS0842: This attribute is not valid for use on this language element neg20.fs(278,14,278,95): typecheck error FS0507: No accessible member or object constructor named 'ProcessStartInfo' takes 0 arguments. Note the call to this member also provides 2 named arguments. diff --git a/tests/fsharp/typecheck/sigs/neg32.bsl b/tests/fsharp/typecheck/sigs/neg32.bsl index 87fbc723312..376138c1858 100644 --- a/tests/fsharp/typecheck/sigs/neg32.bsl +++ b/tests/fsharp/typecheck/sigs/neg32.bsl @@ -1,5 +1,5 @@ -neg32.fs(17,11,17,56): typecheck error FS0842: This attribute is not valid for use on this language element +neg32.fs(17,11,17,56): typecheck warning FS0842: This attribute is not valid for use on this language element neg32.fs(24,15,24,16): typecheck error FS0043: The member or object constructor 'TryParse' does not take 1 argument(s). An overload was found taking 2 arguments. diff --git a/tests/fsharp/typecheck/sigs/version50/neg20.bsl b/tests/fsharp/typecheck/sigs/version50/neg20.bsl index 394f7777b2a..f85f1d5d14f 100644 --- a/tests/fsharp/typecheck/sigs/version50/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/version50/neg20.bsl @@ -261,53 +261,53 @@ neg20.fs(190,34,190,39): typecheck error FS0001: This expression was expected to but here has type 'objnull' -neg20.fs(195,5,195,10): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(195,5,195,10): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(198,5,198,11): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(198,5,198,11): typecheck warning FS0842: This attribute is not valid for use on this language element neg20.fs(202,7,202,9): typecheck error FS0825: The 'DefaultValue' attribute may only be used on 'val' declarations -neg20.fs(204,5,204,14): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(204,5,204,14): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(207,5,207,11): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(207,5,207,11): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(210,5,210,12): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(210,5,210,12): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(213,5,213,33): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(213,5,213,33): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(216,5,216,12): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(216,5,216,12): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(219,5,219,15): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(219,5,219,15): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(222,5,222,31): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(222,5,222,31): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(225,5,225,22): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(225,5,225,22): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(228,5,228,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(228,5,228,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(231,5,231,21): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(231,5,231,21): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(234,5,234,34): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(234,5,234,34): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(237,5,237,34): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(237,5,237,34): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(240,5,240,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(240,5,240,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(243,5,243,23): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(243,5,243,23): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(249,9,249,27): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(249,9,249,27): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(255,5,255,28): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(255,5,255,28): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(258,5,258,38): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(258,5,258,38): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(261,5,261,17): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(261,5,261,17): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(265,5,265,24): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(265,5,265,24): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(268,5,268,27): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(268,5,268,27): typecheck warning FS0842: This attribute is not valid for use on this language element -neg20.fs(271,5,271,15): typecheck error FS0842: This attribute is not valid for use on this language element +neg20.fs(271,5,271,15): typecheck warning FS0842: This attribute is not valid for use on this language element neg20.fs(278,14,278,95): typecheck error FS0507: No accessible member or object constructor named 'ProcessStartInfo' takes 0 arguments. Note the call to this member also provides 2 named arguments. diff --git a/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/WithOOP/E_GenericUOM01.fs b/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/WithOOP/E_GenericUOM01.fs index 369697935e3..0f27193b5a7 100644 --- a/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/WithOOP/E_GenericUOM01.fs +++ b/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/WithOOP/E_GenericUOM01.fs @@ -1,7 +1,7 @@ // #Regression #Conformance #UnitsOfMeasure #ObjectOrientedTypes // Verify error when putting invalid attributes on type arguments // (We should only allow [].) -//This attribute is not valid for use on this language element +//This attribute is not valid for use on this language element open System From 6f2b7064781a2c33c254f17ffac1a31a8cd3f41e Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Tue, 29 Apr 2025 09:43:56 +0100 Subject: [PATCH 04/36] update baselines --- tests/fsharp/typecheck/sigs/neg16.bsl | 4 +- tests/fsharp/typecheck/sigs/neg20.bsl | 48 ++++++++++--------- tests/fsharp/typecheck/sigs/neg32.bsl | 4 +- .../fsharp/typecheck/sigs/version50/neg20.bsl | 48 ++++++++++--------- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/tests/fsharp/typecheck/sigs/neg16.bsl b/tests/fsharp/typecheck/sigs/neg16.bsl index 448ca9127be..4c2300470f7 100644 --- a/tests/fsharp/typecheck/sigs/neg16.bsl +++ b/tests/fsharp/typecheck/sigs/neg16.bsl @@ -13,9 +13,9 @@ neg16.fs(44,10,44,11): typecheck error FS0934: Records, union, abbreviations and neg16.fs(47,10,47,13): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute -neg16.fs(49,7,49,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg16.fs(49,7,49,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg16.fs(52,7,52,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg16.fs(52,7,52,23): typecheck error FS0842: This attribute is not valid for use on this language element neg16.fs(59,8,59,17): typecheck error FS0001: This expression was expected to have type 'Choice<'a,'b>' diff --git a/tests/fsharp/typecheck/sigs/neg20.bsl b/tests/fsharp/typecheck/sigs/neg20.bsl index 28fa11b53f7..2ff8515a78a 100644 --- a/tests/fsharp/typecheck/sigs/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/neg20.bsl @@ -213,53 +213,53 @@ neg20.fs(190,34,190,39): typecheck error FS0001: This expression was expected to but here has type 'objnull' -neg20.fs(195,5,195,10): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(195,5,195,10): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(198,5,198,11): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(198,5,198,11): typecheck error FS0842: This attribute is not valid for use on this language element neg20.fs(202,7,202,9): typecheck error FS0825: The 'DefaultValue' attribute may only be used on 'val' declarations -neg20.fs(204,5,204,14): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(204,5,204,14): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(207,5,207,11): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(207,5,207,11): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(210,5,210,12): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(210,5,210,12): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(213,5,213,33): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(213,5,213,33): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(216,5,216,12): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(216,5,216,12): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(219,5,219,15): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(219,5,219,15): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(222,5,222,31): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(222,5,222,31): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(225,5,225,22): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(225,5,225,22): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(228,5,228,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(228,5,228,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(231,5,231,21): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(231,5,231,21): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(234,5,234,34): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(234,5,234,34): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(237,5,237,34): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(237,5,237,34): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(240,5,240,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(240,5,240,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(243,5,243,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(243,5,243,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(249,9,249,27): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(249,9,249,27): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(255,5,255,28): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(255,5,255,28): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(258,5,258,38): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(258,5,258,38): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(261,5,261,17): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(261,5,261,17): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(265,5,265,24): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(265,5,265,24): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(268,5,268,27): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(268,5,268,27): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(271,5,271,15): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(271,5,271,15): typecheck error FS0842: This attribute is not valid for use on this language element neg20.fs(278,14,278,95): typecheck error FS0507: No accessible member or object constructor named 'ProcessStartInfo' takes 0 arguments. Note the call to this member also provides 2 named arguments. @@ -294,6 +294,7 @@ neg20.fs(335,11,335,24): typecheck error FS0041: A unique overload for method 'S Known type of argument: 'a0 Candidates: + - System.String(value: System.ReadOnlySpan) : System.String - System.String(value: char array) : System.String - System.String(value: nativeptr) : System.String - System.String(value: nativeptr) : System.String @@ -303,6 +304,7 @@ neg20.fs(336,11,336,22): typecheck error FS0041: A unique overload for method 'G Known type of argument: 'a0 Candidates: + - System.Guid(b: System.ReadOnlySpan) : System.Guid - System.Guid(b: byte array) : System.Guid - System.Guid(g: string) : System.Guid diff --git a/tests/fsharp/typecheck/sigs/neg32.bsl b/tests/fsharp/typecheck/sigs/neg32.bsl index 376138c1858..7649c0719b5 100644 --- a/tests/fsharp/typecheck/sigs/neg32.bsl +++ b/tests/fsharp/typecheck/sigs/neg32.bsl @@ -1,7 +1,7 @@ -neg32.fs(17,11,17,56): typecheck warning FS0842: This attribute is not valid for use on this language element +neg32.fs(17,11,17,56): typecheck error FS0842: This attribute is not valid for use on this language element -neg32.fs(24,15,24,16): typecheck error FS0043: The member or object constructor 'TryParse' does not take 1 argument(s). An overload was found taking 2 arguments. +neg32.fs(24,15,24,16): typecheck error FS0043: The member or object constructor 'TryParse' does not take 1 argument(s). An overload was found taking 4 arguments. neg32.fs(43,17,43,19): typecheck error FS0039: The type parameter 'T is not defined. diff --git a/tests/fsharp/typecheck/sigs/version50/neg20.bsl b/tests/fsharp/typecheck/sigs/version50/neg20.bsl index f85f1d5d14f..d5de8268fab 100644 --- a/tests/fsharp/typecheck/sigs/version50/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/version50/neg20.bsl @@ -261,53 +261,53 @@ neg20.fs(190,34,190,39): typecheck error FS0001: This expression was expected to but here has type 'objnull' -neg20.fs(195,5,195,10): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(195,5,195,10): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(198,5,198,11): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(198,5,198,11): typecheck error FS0842: This attribute is not valid for use on this language element neg20.fs(202,7,202,9): typecheck error FS0825: The 'DefaultValue' attribute may only be used on 'val' declarations -neg20.fs(204,5,204,14): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(204,5,204,14): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(207,5,207,11): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(207,5,207,11): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(210,5,210,12): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(210,5,210,12): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(213,5,213,33): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(213,5,213,33): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(216,5,216,12): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(216,5,216,12): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(219,5,219,15): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(219,5,219,15): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(222,5,222,31): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(222,5,222,31): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(225,5,225,22): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(225,5,225,22): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(228,5,228,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(228,5,228,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(231,5,231,21): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(231,5,231,21): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(234,5,234,34): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(234,5,234,34): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(237,5,237,34): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(237,5,237,34): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(240,5,240,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(240,5,240,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(243,5,243,23): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(243,5,243,23): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(249,9,249,27): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(249,9,249,27): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(255,5,255,28): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(255,5,255,28): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(258,5,258,38): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(258,5,258,38): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(261,5,261,17): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(261,5,261,17): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(265,5,265,24): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(265,5,265,24): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(268,5,268,27): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(268,5,268,27): typecheck error FS0842: This attribute is not valid for use on this language element -neg20.fs(271,5,271,15): typecheck warning FS0842: This attribute is not valid for use on this language element +neg20.fs(271,5,271,15): typecheck error FS0842: This attribute is not valid for use on this language element neg20.fs(278,14,278,95): typecheck error FS0507: No accessible member or object constructor named 'ProcessStartInfo' takes 0 arguments. Note the call to this member also provides 2 named arguments. @@ -342,6 +342,7 @@ neg20.fs(335,11,335,24): typecheck error FS0041: A unique overload for method 'S Known type of argument: 'a0 Candidates: + - System.String(value: System.ReadOnlySpan) : System.String - System.String(value: char array) : System.String - System.String(value: nativeptr) : System.String - System.String(value: nativeptr) : System.String @@ -351,6 +352,7 @@ neg20.fs(336,11,336,22): typecheck error FS0041: A unique overload for method 'G Known type of argument: 'a0 Candidates: + - System.Guid(b: System.ReadOnlySpan) : System.Guid - System.Guid(b: byte array) : System.Guid - System.Guid(g: string) : System.Guid From 75d8f5ef637741991df6c15ae75d202b8412dd65 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Tue, 29 Apr 2025 19:33:38 +0100 Subject: [PATCH 05/36] Update baselines --- tests/fsharp/typecheck/sigs/neg20.bsl | 2 -- tests/fsharp/typecheck/sigs/neg32.bsl | 2 +- tests/fsharp/typecheck/sigs/version50/neg20.bsl | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/fsharp/typecheck/sigs/neg20.bsl b/tests/fsharp/typecheck/sigs/neg20.bsl index 2ff8515a78a..5229dcaacf6 100644 --- a/tests/fsharp/typecheck/sigs/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/neg20.bsl @@ -294,7 +294,6 @@ neg20.fs(335,11,335,24): typecheck error FS0041: A unique overload for method 'S Known type of argument: 'a0 Candidates: - - System.String(value: System.ReadOnlySpan) : System.String - System.String(value: char array) : System.String - System.String(value: nativeptr) : System.String - System.String(value: nativeptr) : System.String @@ -304,7 +303,6 @@ neg20.fs(336,11,336,22): typecheck error FS0041: A unique overload for method 'G Known type of argument: 'a0 Candidates: - - System.Guid(b: System.ReadOnlySpan) : System.Guid - System.Guid(b: byte array) : System.Guid - System.Guid(g: string) : System.Guid diff --git a/tests/fsharp/typecheck/sigs/neg32.bsl b/tests/fsharp/typecheck/sigs/neg32.bsl index 7649c0719b5..87fbc723312 100644 --- a/tests/fsharp/typecheck/sigs/neg32.bsl +++ b/tests/fsharp/typecheck/sigs/neg32.bsl @@ -1,7 +1,7 @@ neg32.fs(17,11,17,56): typecheck error FS0842: This attribute is not valid for use on this language element -neg32.fs(24,15,24,16): typecheck error FS0043: The member or object constructor 'TryParse' does not take 1 argument(s). An overload was found taking 4 arguments. +neg32.fs(24,15,24,16): typecheck error FS0043: The member or object constructor 'TryParse' does not take 1 argument(s). An overload was found taking 2 arguments. neg32.fs(43,17,43,19): typecheck error FS0039: The type parameter 'T is not defined. diff --git a/tests/fsharp/typecheck/sigs/version50/neg20.bsl b/tests/fsharp/typecheck/sigs/version50/neg20.bsl index d5de8268fab..394f7777b2a 100644 --- a/tests/fsharp/typecheck/sigs/version50/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/version50/neg20.bsl @@ -342,7 +342,6 @@ neg20.fs(335,11,335,24): typecheck error FS0041: A unique overload for method 'S Known type of argument: 'a0 Candidates: - - System.String(value: System.ReadOnlySpan) : System.String - System.String(value: char array) : System.String - System.String(value: nativeptr) : System.String - System.String(value: nativeptr) : System.String @@ -352,7 +351,6 @@ neg20.fs(336,11,336,22): typecheck error FS0041: A unique overload for method 'G Known type of argument: 'a0 Candidates: - - System.Guid(b: System.ReadOnlySpan) : System.Guid - System.Guid(b: byte array) : System.Guid - System.Guid(g: string) : System.Guid From 4248f2a9225b2533cb4137d1e1b4311ce9e3cad1 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 30 Apr 2025 21:58:10 +0100 Subject: [PATCH 06/36] Move attribute form logic to an AP --- .../Checking/Expressions/CheckExpressions.fs | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index e2d21975311..567e1da0310 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -3187,6 +3187,24 @@ let BuildRecdFieldSet g m objExpr (rfinfo: RecdFieldInfo) argExpr = let wrap, objExpr, _readonly, _writeonly = mkExprAddrOfExpr g boxity false DefinitelyMutates objExpr None m wrap (mkRecdFieldSetViaExprAddr (objExpr, rfinfo.RecdFieldRef, rfinfo.TypeInst, argExpr, m) ) +// This is used to check the target of an attribute with the form of +// Long Form: [] +// Short Form: [] +let (|LongFormAttrTarget|UnrecognizedLongAttrTarget|ShortFormAttributeTarget|) (targetIndicator: Ident option) = + match targetIndicator with + | Some id when id.idText = "assembly" -> LongFormAttrTarget AttributeTargets.Assembly + | Some id when id.idText = "module" -> LongFormAttrTarget AttributeTargets.Module + | Some id when id.idText = "return" -> LongFormAttrTarget AttributeTargets.ReturnValue + | Some id when id.idText = "field" -> LongFormAttrTarget AttributeTargets.Field + | Some id when id.idText = "property" -> LongFormAttrTarget AttributeTargets.Property + | Some id when id.idText = "method" -> LongFormAttrTarget AttributeTargets.Method + | Some id when id.idText = "param" -> LongFormAttrTarget AttributeTargets.Parameter + | Some id when id.idText = "type" -> LongFormAttrTarget AttributeTargets.TyconDecl + | Some id when id.idText = "constructor" -> LongFormAttrTarget AttributeTargets.Constructor + | Some id when id.idText = "event" -> LongFormAttrTarget AttributeTargets.Event + | Some id -> UnrecognizedLongAttrTarget id + | None -> ShortFormAttributeTarget + //------------------------------------------------------------------------- // Helpers dealing with named and optional args at callsites //------------------------------------------------------------------------- @@ -11344,27 +11362,18 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn (validOnDefault, inheritedDefault) | _ -> (validOnDefault, inheritedDefault) - let possibleTgts = enum validOn &&& attrTgt - let directedTgts = + let attributeTargets = enum validOn &&& attrTgt + let directedTargets = match targetIndicator with - | Some id when id.idText = "assembly" -> AttributeTargets.Assembly - | Some id when id.idText = "module" -> AttributeTargets.Module - | Some id when id.idText = "return" -> AttributeTargets.ReturnValue - | Some id when id.idText = "field" -> AttributeTargets.Field - | Some id when id.idText = "property" -> AttributeTargets.Property - | Some id when id.idText = "method" -> AttributeTargets.Method - | Some id when id.idText = "param" -> AttributeTargets.Parameter - | Some id when id.idText = "type" -> AttributeTargets.TyconDecl - | Some id when id.idText = "constructor" -> AttributeTargets.Constructor - | Some id when id.idText = "event" -> AttributeTargets.Event - | Some id -> - errorR(Error(FSComp.SR.tcUnrecognizedAttributeTarget(), id.idRange)) - possibleTgts - // mask explicit targets - | _ -> possibleTgts &&& ~~~ attrEx - let constrainedTgts = possibleTgts &&& directedTgts - if constrainedTgts = enum 0 then - if (directedTgts = AttributeTargets.Assembly || directedTgts = AttributeTargets.Module) then + | LongFormAttrTarget attrTarget -> attrTarget + | UnrecognizedLongAttrTarget attrTarget -> + errorR(Error(FSComp.SR.tcUnrecognizedAttributeTarget(), attrTarget.idRange)) + attributeTargets + | ShortFormAttributeTarget -> attributeTargets &&& ~~~ attrEx + + let constrainedTargets = attributeTargets &&& directedTargets + if constrainedTargets = enum 0 then + if (directedTargets = AttributeTargets.Assembly || directedTargets = AttributeTargets.Module) then error(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElementUseDo(), mAttr)) else warning(Error(FSComp.SR.tcAttributeIsNotValidForLanguageElement(), mAttr)) @@ -11428,11 +11437,11 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn if isStruct then error (Error(FSComp.SR.tcCustomAttributeMustBeReferenceType(), m)) if args.Length <> ilMethRef.ArgTypes.Length then error (Error(FSComp.SR.tcCustomAttributeArgumentMismatch(), m)) let args = args |> List.map mkAttribExpr - Attrib(tcref, ILAttrib ilMethRef, args, namedAttribArgMap, isAppliedToGetterOrSetter, Some constrainedTgts, m) + Attrib(tcref, ILAttrib ilMethRef, args, namedAttribArgMap, isAppliedToGetterOrSetter, Some constrainedTargets, m) | Expr.App (InnerExprPat(ExprValWithPossibleTypeInst(vref, _, _, _)), _, _, args, _) -> let args = args |> List.collect (function Expr.Const (Const.Unit, _, _) -> [] | expr -> tryDestRefTupleExpr expr) |> List.map mkAttribExpr - Attrib(tcref, FSAttrib vref, args, namedAttribArgMap, isAppliedToGetterOrSetter, Some constrainedTgts, mAttr) + Attrib(tcref, FSAttrib vref, args, namedAttribArgMap, isAppliedToGetterOrSetter, Some constrainedTargets, mAttr) | _ -> error (Error(FSComp.SR.tcCustomAttributeMustInvokeConstructor(), mAttr)) @@ -11440,7 +11449,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn | _ -> error(Error(FSComp.SR.tcAttributeExpressionsMustBeConstructorCalls(), mAttr)) - [ (constrainedTgts, attrib) ], false + [ (constrainedTargets, attrib) ], false and TcAttributesWithPossibleTargetsEx canFail (cenv: cenv) env attrTgt attrEx synAttribs = From 8f0683d9b3d20ec7c3f254d33cc0883ae9e5021a Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Sun, 3 Aug 2025 21:13:07 +0200 Subject: [PATCH 07/36] Check if the module appears to be incorrectly nested based on indentation --- src/Compiler/pars.fsy | 9 ++ .../Type/Module Inside Type Defn 01.fs | 6 ++ .../Type/Module Inside Type Defn 01.fs.bsl | 71 ++++++++++++++++ .../Type/Module Inside Type Defn 02.fs | 6 ++ .../Type/Module Inside Type Defn 02.fs.bsl | 84 +++++++++++++++++++ .../Type/Module Inside Type Defn 03.fs | 7 ++ .../Type/Module Inside Type Defn 03.fs.bsl | 57 +++++++++++++ .../Type/Module Inside Type Defn 04.fs | 6 ++ .../Type/Module Inside Type Defn 04.fs.bsl | 55 ++++++++++++ .../Type/Module Inside Type Defn 05.fs | 8 ++ .../Type/Module Inside Type Defn 05.fs.bsl | 50 +++++++++++ 11 files changed, 359 insertions(+) create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 8b0dfa4ae8c..1c1e7fe64e4 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -1271,6 +1271,15 @@ moduleDefnsOrExpr: /* A sequence of definitions in a namespace or module */ moduleDefns: + | moduleDefnOrDirective moduleDefnOrDirective + { match $1, $2 with + | [SynModuleDecl.Types(_, mType)], [SynModuleDecl.NestedModule(_, _, _, _, mModule, { ModuleKeyword = Some m })] -> + // Check if the module appears to be incorrectly nested based on indentation + if mModule.StartColumn > mType.StartColumn then + errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), m)) + $1 @ $2 + | _ -> $1 @ $2 } + | moduleDefnOrDirective moduleDefns { $1 @ $2 } diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs new file mode 100644 index 00000000000..29bf10b74e5 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs @@ -0,0 +1,6 @@ +module Module + +type IFace = + abstract F : int -> int + module M = + let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl new file mode 100644 index 00000000000..f3b0ed6f21e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl @@ -0,0 +1,71 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [IFace], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,10)), + ObjectModel + (Unspecified, + [AbstractSlot + (SynValSig + ([], SynIdent (F, None), + SynValTyparDecls (None, true), + Fun + (LongIdent (SynLongIdent ([int], [], [None])), + LongIdent (SynLongIdent ([int], [], [None])), + (4,17--4,27), { ArrowRange = (4,21--4,23) }), + SynValInfo + ([[SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None)), false, false, + PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector), + Single None, None, (4,4--4,27), + { LeadingKeyword = Abstract (4,4--4,12) + InlineKeyword = None + WithKeyword = None + EqualsRange = None }), + { IsInstance = true + IsDispatchSlot = true + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, (4,4--4,27), + { GetSetKeywords = None })], (4,4--4,27)), [], None, + (3,5--4,27), { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,11--3,12) + WithKeyword = None })], (3,0--4,27)); + NestedModule + (SynComponentInfo + ([], None, [], [M], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,12)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (6,14--6,16)), (6,14--6,16))], + None, (6,12--6,16)), None, Const (Unit, (6,19--6,21)), + (6,12--6,16), NoneAtLet, + { LeadingKeyword = Let (6,8--6,11) + InlineKeyword = None + EqualsRange = Some (6,17--6,18) })], (6,8--6,21))], + false, (5,4--6,21), { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,13--5,14) })], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(5,4)-(5,10) parse error Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs new file mode 100644 index 00000000000..d063e1a1aff --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs @@ -0,0 +1,6 @@ +module Module + +type C () = + member _.F () = 3 + module M2 = + let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl new file mode 100644 index 00000000000..0b347e237da --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl @@ -0,0 +1,84 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 02.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,6)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (3,7--3,9)), None, + PreXmlDoc ((3,7), FSharp.Compiler.Xml.XmlDocCollector), + (3,5--3,6), { AsKeyword = None }); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((4,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], [(4,12--4,13)], [None; None]), None, + None, + Pats + [Paren + (Const (Unit, (4,15--4,17)), (4,15--4,17))], + None, (4,11--4,17)), None, + Const (Int32 3, (4,20--4,21)), (4,11--4,17), + NoneAtInvisible, + { LeadingKeyword = Member (4,4--4,10) + InlineKeyword = None + EqualsRange = Some (4,18--4,19) }), (4,4--4,21))], + (4,4--4,21)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (3,7--3,9)), None, + PreXmlDoc ((3,7), FSharp.Compiler.Xml.XmlDocCollector), + (3,5--3,6), { AsKeyword = None })), (3,5--4,21), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,10--3,11) + WithKeyword = None })], (3,0--4,21)); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,13)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (6,14--6,16)), (6,14--6,16))], + None, (6,12--6,16)), None, Const (Unit, (6,19--6,21)), + (6,12--6,16), NoneAtLet, + { LeadingKeyword = Let (6,8--6,11) + InlineKeyword = None + EqualsRange = Some (6,17--6,18) })], (6,8--6,21))], + false, (5,4--6,21), { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,14--5,15) })], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(5,4)-(5,10) parse error Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs new file mode 100644 index 00000000000..3e63110f83a --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs @@ -0,0 +1,7 @@ +module Module + +type U = + | A + | B + module M3 = + let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl new file mode 100644 index 00000000000..922fa8b0fd6 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl @@ -0,0 +1,57 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 03.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [U], + 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) }); + SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (5,6--5,7), { BarRange = Some (5,4--5,5) })], + (4,4--5,7)), (4,4--5,7)), [], None, (3,5--5,7), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--5,7)); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + 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 ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--7,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(6,4)-(6,10) parse error Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs new file mode 100644 index 00000000000..aa286f18512 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs @@ -0,0 +1,6 @@ +module Module + +type R = + { A : int } + module M4 = + let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl new file mode 100644 index 00000000000..8e51bf20dc1 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl @@ -0,0 +1,55 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 04.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [R], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,6)), + Simple + (Record + (None, + [SynField + ([], false, Some A, + LongIdent (SynLongIdent ([int], [], [None])), false, + PreXmlDoc ((4,6), FSharp.Compiler.Xml.XmlDocCollector), + None, (4,6--4,13), { LeadingKeyword = None + MutableKeyword = None })], + (4,4--4,15)), (4,4--4,15)), [], None, (3,5--4,15), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--4,15)); + NestedModule + (SynComponentInfo + ([], None, [], [M4], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,13)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (6,14--6,16)), (6,14--6,16))], + None, (6,12--6,16)), None, Const (Unit, (6,19--6,21)), + (6,12--6,16), NoneAtLet, + { LeadingKeyword = Let (6,8--6,11) + InlineKeyword = None + EqualsRange = Some (6,17--6,18) })], (6,8--6,21))], + false, (5,4--6,21), { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,14--5,15) })], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(5,4)-(5,10) parse error Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs new file mode 100644 index 00000000000..4c2b52f49a1 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs @@ -0,0 +1,8 @@ +module Module + +type IFace = + interface + abstract F : int -> int + module M = + let f () = f () + end \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl new file mode 100644 index 00000000000..084728abb29 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl @@ -0,0 +1,50 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 05.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [IFace], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,10)), + ObjectModel + (Interface, + [AbstractSlot + (SynValSig + ([], SynIdent (F, None), + SynValTyparDecls (None, true), + Fun + (LongIdent (SynLongIdent ([int], [], [None])), + LongIdent (SynLongIdent ([int], [], [None])), + (5,21--5,31), { ArrowRange = (5,25--5,27) }), + SynValInfo + ([[SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None)), false, false, + PreXmlDoc ((5,8), FSharp.Compiler.Xml.XmlDocCollector), + Single None, None, (5,8--5,31), + { LeadingKeyword = Abstract (5,8--5,16) + InlineKeyword = None + WithKeyword = None + EqualsRange = None }), + { IsInstance = true + IsDispatchSlot = true + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, (5,8--5,31), + { GetSetKeywords = None })], (4,4--5,31)), [], None, + (3,5--5,31), { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,11--3,12) + WithKeyword = None })], (3,0--5,31))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--5,31), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(4,4)-(4,13) 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. From 569b382f258f9d12551c3cac6e2e0f8b6d3d0d6f Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Sun, 3 Aug 2025 22:12:33 +0200 Subject: [PATCH 08/36] one more test --- .../service/data/SyntaxTree/Type/Union 08.fs | 10 +++ .../data/SyntaxTree/Type/Union 08.fs.bsl | 67 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/service/data/SyntaxTree/Type/Union 08.fs create mode 100644 tests/service/data/SyntaxTree/Type/Union 08.fs.bsl 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 [])) From 89ec72abf75000166e5bd68b036895e74f79a168 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Sun, 3 Aug 2025 22:15:31 +0200 Subject: [PATCH 09/36] release notes --- docs/release-notes/.FSharp.Compiler.Service/10.0.100.md | 1 + 1 file changed, 1 insertion(+) 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 70920a02872..ad89dadfb45 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md @@ -15,6 +15,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)) +* Fix: Check if the module appears to be incorrectly nested based on indentation.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) ### Changed * Use `errorR` instead of `error` in `CheckDeclarations.fs` when possible. ([PR #18645](https://github.com/dotnet/fsharp/pull/18645)) From a252caf3b0d857edab11ced555714c7309887842 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 09:48:51 +0200 Subject: [PATCH 10/36] Move check to ParseHelpers.fs --- src/Compiler/SyntaxTree/ParseHelpers.fs | 21 ++++ src/Compiler/SyntaxTree/ParseHelpers.fsi | 5 + src/Compiler/pars.fsy | 12 +-- .../Type/Module Inside Type Defn 01.fs.bsl | 2 +- .../Type/Module Inside Type Defn 02.fs.bsl | 2 +- .../Type/Module Inside Type Defn 03.fs.bsl | 2 +- .../Type/Module Inside Type Defn 04.fs.bsl | 2 +- .../Type/Module Inside Type Defn 06.fs | 11 ++ .../Type/Module Inside Type Defn 06.fs.bsl | 79 ++++++++++++++ .../Type/Module Inside Type Defn 07.fs | 15 +++ .../Type/Module Inside Type Defn 07.fs.bsl | 100 ++++++++++++++++++ .../Type/Module Inside Type Defn 08.fs | 16 +++ .../Type/Module Inside Type Defn 08.fs.bsl | 65 ++++++++++++ 13 files changed, 320 insertions(+), 12 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index 35b8a3d46db..8fe83cd5080 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1065,6 +1065,27 @@ let leadingKeywordIsAbstract = | SynLeadingKeyword.StaticAbstractMember _ -> true | _ -> false +let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2: SynModuleDecl list) (lexBuf: Lexbuf) = + match moduleDecls1, moduleDecls2 with + | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> + let mLastSynDefn = + defns + |> List.choose (function + | SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range) + |> List.tryLast + |> Option.defaultValue range0 + + for defn in rest do + match defn with + | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> + lexBuf.CheckLanguageFeatureAndRecover LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes mKeyword + + if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then + if mKeyword.StartColumn > mLastSynDefn.StartColumn then + warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword)) + | _ -> () + | _ -> () + /// Unified helper for creating let/let!/use/use! expressions /// Creates either SynExpr.LetOrUse or SynExpr.LetOrUseBang based on isBang parameter /// Handles all four cases: 'let', 'let!', 'use', and 'use!' diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fsi b/src/Compiler/SyntaxTree/ParseHelpers.fsi index 03e9e37f274..4846ee9b3fa 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 @@ -270,3 +271,7 @@ val mkSynField: SynField val leadingKeywordIsAbstract: SynLeadingKeyword -> bool + +/// Check for invalid declarations inside type definitions +val checkInvalidDeclsInTypeDefn: + moduleDecls1: SynModuleDecl list -> moduleDecls2: SynModuleDecl list -> lexBuf: Lexbuf -> unit diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 1c1e7fe64e4..4cdbe40fc3e 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -1272,16 +1272,12 @@ moduleDefnsOrExpr: /* A sequence of definitions in a namespace or module */ moduleDefns: | moduleDefnOrDirective moduleDefnOrDirective - { match $1, $2 with - | [SynModuleDecl.Types(_, mType)], [SynModuleDecl.NestedModule(_, _, _, _, mModule, { ModuleKeyword = Some m })] -> - // Check if the module appears to be incorrectly nested based on indentation - if mModule.StartColumn > mType.StartColumn then - errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), m)) - $1 @ $2 - | _ -> $1 @ $2 } + { checkInvalidDeclsInTypeDefn $1 $2 parseState.LexBuffer + $1 @ $2 } | moduleDefnOrDirective moduleDefns - { $1 @ $2 } + { checkInvalidDeclsInTypeDefn $1 $2 parseState.LexBuffer + $1 @ $2 } | moduleDefnOrDirective topSeparators moduleDefnsOrExpr { $1 @ $3 } diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl index f3b0ed6f21e..3b4119781ae 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl @@ -68,4 +68,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(5,4)-(5,10) parse error Invalid declaration syntax +(5,4)-(5,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl index 0b347e237da..bda7d32fe20 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl @@ -81,4 +81,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(5,4)-(5,10) parse error Invalid declaration syntax +(5,4)-(5,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl index 922fa8b0fd6..85227371b4a 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl @@ -54,4 +54,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(6,4)-(6,10) parse error Invalid declaration syntax +(6,4)-(6,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl index 8e51bf20dc1..2503cdeecfb 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl @@ -52,4 +52,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(5,4)-(5,10) parse error Invalid declaration syntax +(5,4)-(5,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs new file mode 100644 index 00000000000..4706f19608e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs @@ -0,0 +1,11 @@ +module Module + +type A = A + +type B = + | B + module M1 = begin end + module M2 = begin end + module M3 = begin end + +type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl new file mode 100644 index 00000000000..ec4349c70c6 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl @@ -0,0 +1,79 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 06.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 + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--3,10)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,5--5,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], + (6,4--6,7)), (6,4--6,7)), [], None, (5,5--6,7), + { LeadingKeyword = Type (5,0--5,4) + EqualsRange = Some (5,7--5,8) + WithKeyword = None })], (5,0--6,7)); + NestedModule + (SynComponentInfo + ([], None, [], [M1], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,13)), false, [], false, (7,4--7,25), + { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,14--7,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (8,4--8,13)), false, [], false, (8,4--8,25), + { ModuleKeyword = Some (8,4--8,10) + EqualsRange = Some (8,14--8,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (9,4--9,13)), false, [], false, (9,4--9,25), + { ModuleKeyword = Some (9,4--9,10) + EqualsRange = Some (9,14--9,15) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((11,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (11,5--11,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([C], [], [None])), + (11,9--11,10)), (11,9--11,10)), [], None, (11,5--11,10), + { LeadingKeyword = Type (11,0--11,4) + EqualsRange = Some (11,7--11,8) + WithKeyword = None })], (11,0--11,10))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--11,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(7,4)-(7,10) parse warning Invalid declaration syntax +(8,4)-(8,10) parse warning Invalid declaration syntax +(9,4)-(9,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs new file mode 100644 index 00000000000..dd101d44c44 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs @@ -0,0 +1,15 @@ +module Module + +type A = A + +module M1 = begin end +module M2 = begin end +module M3 = begin end + +type B = + | B + module M4 = begin end + module M5 = begin end + module M6 = begin end + +type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl new file mode 100644 index 00000000000..d4b2954a1b8 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl @@ -0,0 +1,100 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 07.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 + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--3,10)); + NestedModule + (SynComponentInfo + ([], None, [], [M1], + PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,0--5,9)), false, [], false, (5,0--5,21), + { ModuleKeyword = Some (5,0--5,6) + EqualsRange = Some (5,10--5,11) }); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,0--6,9)), false, [], false, (6,0--6,21), + { ModuleKeyword = Some (6,0--6,6) + EqualsRange = Some (6,10--6,11) }); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,0--7,9)), false, [], false, (7,0--7,21), + { ModuleKeyword = Some (7,0--7,6) + EqualsRange = Some (7,10--7,11) }); + 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)); + NestedModule + (SynComponentInfo + ([], None, [], [M4], + PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (11,4--11,13)), false, [], false, (11,4--11,25), + { ModuleKeyword = Some (11,4--11,10) + EqualsRange = Some (11,14--11,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M5], + PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (12,4--12,13)), false, [], false, (12,4--12,25), + { ModuleKeyword = Some (12,4--12,10) + EqualsRange = Some (12,14--12,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M6], + PreXmlDoc ((13,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (13,4--13,13)), false, [], false, (13,4--13,25), + { ModuleKeyword = Some (13,4--13,10) + EqualsRange = Some (13,14--13,15) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((15,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (15,5--15,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([C], [], [None])), + (15,9--15,10)), (15,9--15,10)), [], None, (15,5--15,10), + { LeadingKeyword = Type (15,0--15,4) + EqualsRange = Some (15,7--15,8) + WithKeyword = None })], (15,0--15,10))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--15,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(11,4)-(11,10) parse warning Invalid declaration syntax +(12,4)-(12,10) parse warning Invalid declaration syntax +(13,4)-(13,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs new file mode 100644 index 00000000000..b28f2d2585d --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs @@ -0,0 +1,16 @@ +module Module + +type A = A + +module M1 = begin end +module M2 = begin end +module M3 = begin end + +type B = + | B + with + module M4 = begin end + module M5 = begin end + module M6 = begin end + +type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl new file mode 100644 index 00000000000..4b786d93011 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl @@ -0,0 +1,65 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 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 + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--3,10)); + NestedModule + (SynComponentInfo + ([], None, [], [M1], + PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,0--5,9)), false, [], false, (5,0--5,21), + { ModuleKeyword = Some (5,0--5,6) + EqualsRange = Some (5,10--5,11) }); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,0--6,9)), false, [], false, (6,0--6,21), + { ModuleKeyword = Some (6,0--6,6) + EqualsRange = Some (6,10--6,11) }); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,0--7,9)), false, [], false, (7,0--7,21), + { ModuleKeyword = Some (7,0--7,6) + EqualsRange = Some (7,10--7,11) }); + 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 = Some (11,4--11,8) })], (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 [])) + +(12,8)-(12,14) parse error Unexpected keyword 'module' in type definition. Expected incomplete structured construct at or before this point, 'end' or other token. +(13,8)-(13,14) parse error Unexpected keyword 'module' in implementation file From fdc5dee2a2ea841fa9ebe9ac25e3fa97bb5d7e9c Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 09:49:25 +0200 Subject: [PATCH 11/36] Add LanguageFeature --- src/Compiler/FSComp.txt | 1 + src/Compiler/Facilities/LanguageFeatures.fs | 3 +++ src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ 16 files changed, 70 insertions(+) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 6a243373521..fe95e2f96ad 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1802,6 +1802,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" +featureWarnOnUnexpectedModuleDefinitionsInsideTypes,"Warn when a module definition is encountered inside a type definition" 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 a3a9a3855aa..b591f75a4e7 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -102,6 +102,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn + | WarnOnUnexpectedModuleDefinitionsInsideTypes | AllowTypedLetUseAndBang /// LanguageVersion management @@ -238,6 +239,7 @@ type LanguageVersion(versionText) = LanguageFeature.AllowTypedLetUseAndBang, languageVersion100 LanguageFeature.UnmanagedConstraintCsharpInterop, languageVersion100 LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, languageVersion100 + LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, languageVersion100 // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work @@ -408,6 +410,7 @@ type LanguageVersion(versionText) = | LanguageFeature.UseBangBindingValueDiscard -> FSComp.SR.featureUseBangBindingValueDiscard () | LanguageFeature.BetterAnonymousRecordParsing -> FSComp.SR.featureBetterAnonymousRecordParsing () | LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn () + | LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes -> FSComp.SR.featureWarnOnUnexpectedModuleDefinitionsInsideTypes () | LanguageFeature.AllowTypedLetUseAndBang -> FSComp.SR.featureAllowLetOrUseBangTypeAnnotationWithoutParens () /// Get a version string associated with the given feature. diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index f034979a6d3..760671040f2 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -93,6 +93,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn + | WarnOnUnexpectedModuleDefinitionsInsideTypes | AllowTypedLetUseAndBang /// LanguageVersion management diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 1b8318e124e..dd042bc7cfd 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Metoda getter a setter indexované vlastnosti musí mít stejný typ. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index b1045b18823..25e1948f81b 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Getter und Setter für indizierte Eigenschaften müssen denselben Typ aufweisen. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index c76e6d0bcac..6be7f78693b 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type El captador y el establecedor de propiedades indexadas deben tener el mismo tipo. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index aa49f56b951..8acc217c1dd 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Les propriétés indexées getter et setter doivent avoir le même type diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 89dacdf42ac..b4c66c94146 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Il getter e il setter delle proprietà indicizzate devono avere lo stesso tipo diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 42955cb462b..26f9c60c080 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type インデックス付きプロパティのゲッターとセッターの型は同じである必要があります diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 56628072e04..c828cb43f79 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type 인덱싱된 속성 getter와 setter의 형식이 같아야 합니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 4cee71af6e0..e5465320487 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Metoda pobierająca i metoda ustawiająca właściwości indeksowanych muszą mieć taki sam typ. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 44685a5bf83..9f6246c3937 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type As propriedades indexadas getter e setter devem ter o mesmo tipo diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index c9056c01054..b06e463aa74 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Методы получения и установки индексированных свойств должны иметь один и тот же тип. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index e39ae57407c..3a96bc1be4e 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type Dizini oluşturulmuş özelliklerin alıcısı ve ayarlayıcısı aynı türde olmalıdır diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 08d5772f30d..1e773035c96 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type 索引属性 getter 和 setter 必须具有相同的类型 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 4e6690ce1fe..ce60d71f124 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -682,6 +682,11 @@ Use type conversion cache during compilation + + Warn when a module definition is encountered inside a type definition + Warn when a module definition is encountered inside a type definition + + Indexed properties getter and setter must have the same type 索引屬性 getter 和 setter 必須具有相同的類型 From 72385a6336c072164b029f43af1edeb0c6580c32 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 10:03:28 +0200 Subject: [PATCH 12/36] release notes --- docs/release-notes/.FSharp.Compiler.Service/10.0.100.md | 2 +- docs/release-notes/.Language/preview.md | 1 + src/Compiler/Facilities/LanguageFeatures.fs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) 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 06c21b0b747..aceead5f6f1 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md @@ -16,7 +16,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)) -* Fix: Check if the module appears to be incorrectly nested based on indentation.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) +* Warn when a module definition is encountered inside a type definition.([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. ### Changed diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index 7b9b498baaf..c6f6ff6187b 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -14,5 +14,6 @@ ### Fixed * Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816)) +* Warn when a module definition is encountered inside a type definition.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) ### Changed diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index b591f75a4e7..bdf4132c332 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -239,10 +239,10 @@ type LanguageVersion(versionText) = LanguageFeature.AllowTypedLetUseAndBang, languageVersion100 LanguageFeature.UnmanagedConstraintCsharpInterop, languageVersion100 LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, languageVersion100 - LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, languageVersion100 // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work + LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, languageVersion100 ] static let defaultLanguageVersion = LanguageVersion("default") From 4b01e49239917ae289ddd4fe12000a4fe1c099ac Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 10:27:20 +0200 Subject: [PATCH 13/36] update checkInvalidDeclsInTypeDefn --- src/Compiler/SyntaxTree/ParseHelpers.fs | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index 8fe83cd5080..d225b72d78e 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1065,23 +1065,35 @@ let leadingKeywordIsAbstract = | SynLeadingKeyword.StaticAbstractMember _ -> true | _ -> false +let (|NestedModuleAt|_|) = + function + | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> Some mKeyword + | _ -> None + +let (|TypesFollowedByModules|_|) = + function + | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> Some(defns, rest) + | _ -> None + +let getLastTypeColumn (defns: SynTypeDefn list) = + defns + |> List.choose (function + | SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range) + |> List.tryLast + |> Option.defaultValue range0 + let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2: SynModuleDecl list) (lexBuf: Lexbuf) = match moduleDecls1, moduleDecls2 with - | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> - let mLastSynDefn = - defns - |> List.choose (function - | SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range) - |> List.tryLast - |> Option.defaultValue range0 + | TypesFollowedByModules(defns, rest) -> + let lastTypeColumn = getLastTypeColumn defns for defn in rest do match defn with - | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> + | NestedModuleAt mKeyword -> lexBuf.CheckLanguageFeatureAndRecover LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes mKeyword if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then - if mKeyword.StartColumn > mLastSynDefn.StartColumn then + if mKeyword.StartColumn > lastTypeColumn.StartColumn then warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword)) | _ -> () | _ -> () From 6a0e2832a88e7902e414fb83a1e03fb860482ab1 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 11:13:13 +0200 Subject: [PATCH 14/36] more tests --- src/Compiler/Facilities/LanguageFeatures.fs | 2 +- src/Compiler/SyntaxTree/ParseHelpers.fs | 10 +- .../WarnOnUnexpectedModuleDefinitions.fs | 119 ++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 1 + 4 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index bdf4132c332..b64d54320b1 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -242,7 +242,7 @@ type LanguageVersion(versionText) = // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work - LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, languageVersion100 + LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index d225b72d78e..7c9619842d3 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1065,15 +1065,17 @@ let leadingKeywordIsAbstract = | SynLeadingKeyword.StaticAbstractMember _ -> true | _ -> false +[] let (|NestedModuleAt|_|) = function - | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> Some mKeyword - | _ -> None + | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> ValueSome mKeyword + | _ -> ValueNone +[] let (|TypesFollowedByModules|_|) = function - | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> Some(defns, rest) - | _ -> None + | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> ValueSome(defns, rest) + | _ -> ValueNone let getLastTypeColumn (defns: SynTypeDefn list) = defns diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs new file mode 100644 index 00000000000..33c2442f97b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs @@ -0,0 +1,119 @@ +// 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 ``Module definition is encountered inside a type definition`` = + + [] + let ``Warn when a module definition is encountered inside a type definition``() = + Fsx """ +type IFace = + abstract F : int -> int + module M = + let f () = () + +type C () = + member _.F () = 3 + module M2 = + let f () = () + +type U = + | A + | B + module M3 = + let f () = () + +type R = + { A : int } + module M4 = + let f () = () + +type A = A + +module M1 = begin end +module M2 = begin end +module M3 = begin end + +type B = + | B + module M4 = begin end + module M5 = begin end + module M6 = begin end + +module ThisIsFine = + let f () = () + +type C = C + """ + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 554, Line 31, Col 5, Line 31, Col 11, "Invalid declaration syntax") + (Warning 554, Line 32, Col 5, Line 32, Col 11, "Invalid declaration syntax") + (Warning 554, Line 33, Col 5, Line 33, Col 11, "Invalid declaration syntax") + (Warning 554, Line 20, Col 5, Line 20, Col 11, "Invalid declaration syntax") + (Warning 554, Line 15, Col 5, Line 15, Col 11, "Invalid declaration syntax") + (Warning 554, Line 9, Col 5, Line 9, Col 11, "Invalid declaration syntax"); + (Warning 554, Line 4, Col 5, Line 4, Col 11, "Invalid declaration syntax") + ] + + [] + let ``Don't warn when a module definition is encountered inside a type definition``() = + Fsx """ +type IFace = + abstract F : int -> int + module M = + let f () = () + +type C () = + member _.F () = 3 + module M2 = + let f () = () + +type U = + | A + | B + module M3 = + let f () = () + +type R = + { A : int } + module M4 = + let f () = () + +type A = A + +module M1 = begin end +module M2 = begin end +module M3 = begin end + +type B = + | B + module M4 = begin end + module M5 = begin end + module M6 = begin end + +module ThisIsFine = + let f () = () + +type C = C + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 3350, Line 31, Col 5, Line 31, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 32, Col 5, Line 32, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 33, Col 5, Line 33, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 35, Col 1, Line 35, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 20, Col 5, Line 20, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 25, Col 1, Line 25, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 26, Col 1, Line 26, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 27, Col 1, Line 27, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 15, Col 5, Line 15, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 9, Col 5, Line 9, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + (Error 3350, Line 4, Col 5, Line 4, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 9618f9cbcee..40a517abe0b 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -221,6 +221,7 @@ + From e2a941ae6fc117f708e01695a720ebf907eb3b94 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 14:27:13 +0200 Subject: [PATCH 15/36] more tests --- .../Type/Module Inside Type Defn 09.fs | 14 ++ .../Type/Module Inside Type Defn 09.fs.bsl | 148 ++++++++++++ .../Type/Module Inside Type Defn 10.fs | 17 ++ .../Type/Module Inside Type Defn 10.fs.bsl | 211 ++++++++++++++++++ .../Type/Module Inside Type Defn 11.fs | 11 + .../Type/Module Inside Type Defn 11.fs.bsl | 123 ++++++++++ 6 files changed, 524 insertions(+) create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs new file mode 100644 index 00000000000..064e08df649 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs @@ -0,0 +1,14 @@ +module Module + +type A = A + +type B = + | B + member this.M1 = 1 + member this.M2 = 2 + member this.M3 = 3 + module M1 = begin end + module M2 = begin end + module M3 = begin end + +type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl new file mode 100644 index 00000000000..1cfe90cc1b9 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl @@ -0,0 +1,148 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 09.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 + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--3,10)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,5--5,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], + (6,4--6,7)), (6,4--6,7)), + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,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 + ([this; M1], [(7,15--7,16)], [None; None]), None, + None, Pats [], None, (7,11--7,18)), None, + Const (Int32 1, (7,21--7,22)), (7,11--7,18), + NoneAtInvisible, { LeadingKeyword = Member (7,4--7,10) + InlineKeyword = None + EqualsRange = Some (7,19--7,20) }), + (7,4--7,22)); + 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 + ([this; M2], [(8,15--8,16)], [None; None]), None, + None, Pats [], None, (8,11--8,18)), None, + Const (Int32 2, (8,21--8,22)), (8,11--8,18), + NoneAtInvisible, { LeadingKeyword = Member (8,4--8,10) + InlineKeyword = None + EqualsRange = Some (8,19--8,20) }), + (8,4--8,22)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,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 + ([this; M3], [(9,15--9,16)], [None; None]), None, + None, Pats [], None, (9,11--9,18)), None, + Const (Int32 3, (9,21--9,22)), (9,11--9,18), + NoneAtInvisible, { LeadingKeyword = Member (9,4--9,10) + InlineKeyword = None + EqualsRange = Some (9,19--9,20) }), + (9,4--9,22))], None, (5,5--9,22), + { LeadingKeyword = Type (5,0--5,4) + EqualsRange = Some (5,7--5,8) + WithKeyword = None })], (5,0--9,22)); + NestedModule + (SynComponentInfo + ([], None, [], [M1], + PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (10,4--10,13)), false, [], false, (10,4--10,25), + { ModuleKeyword = Some (10,4--10,10) + EqualsRange = Some (10,14--10,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (11,4--11,13)), false, [], false, (11,4--11,25), + { ModuleKeyword = Some (11,4--11,10) + EqualsRange = Some (11,14--11,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (12,4--12,13)), false, [], false, (12,4--12,25), + { ModuleKeyword = Some (12,4--12,10) + EqualsRange = Some (12,14--12,15) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((14,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (14,5--14,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([C], [], [None])), + (14,9--14,10)), (14,9--14,10)), [], None, (14,5--14,10), + { LeadingKeyword = Type (14,0--14,4) + EqualsRange = Some (14,7--14,8) + WithKeyword = None })], (14,0--14,10))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--14,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(10,4)-(10,10) parse warning Invalid declaration syntax +(11,4)-(11,10) parse warning Invalid declaration syntax +(12,4)-(12,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs new file mode 100644 index 00000000000..989dc7dade3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs @@ -0,0 +1,17 @@ +module Module + +type A = A + +type B = + | B + member this.M1 = 1 + member this.M2 = 2 + member this.M3 = 3 + module M1 = begin end + module M2 = begin end + module M3 = begin end + type M4() = class end + type M5() = class end + type M6() = class end + +type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl new file mode 100644 index 00000000000..2b7791c10b2 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl @@ -0,0 +1,211 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 10.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 + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), + { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--3,10)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [B], + PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,5--5,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], + (6,4--6,7)), (6,4--6,7)), + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,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 + ([this; M1], [(7,15--7,16)], [None; None]), None, + None, Pats [], None, (7,11--7,18)), None, + Const (Int32 1, (7,21--7,22)), (7,11--7,18), + NoneAtInvisible, { LeadingKeyword = Member (7,4--7,10) + InlineKeyword = None + EqualsRange = Some (7,19--7,20) }), + (7,4--7,22)); + 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 + ([this; M2], [(8,15--8,16)], [None; None]), None, + None, Pats [], None, (8,11--8,18)), None, + Const (Int32 2, (8,21--8,22)), (8,11--8,18), + NoneAtInvisible, { LeadingKeyword = Member (8,4--8,10) + InlineKeyword = None + EqualsRange = Some (8,19--8,20) }), + (8,4--8,22)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,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 + ([this; M3], [(9,15--9,16)], [None; None]), None, + None, Pats [], None, (9,11--9,18)), None, + Const (Int32 3, (9,21--9,22)), (9,11--9,18), + NoneAtInvisible, { LeadingKeyword = Member (9,4--9,10) + InlineKeyword = None + EqualsRange = Some (9,19--9,20) }), + (9,4--9,22))], None, (5,5--9,22), + { LeadingKeyword = Type (5,0--5,4) + EqualsRange = Some (5,7--5,8) + WithKeyword = None })], (5,0--9,22)); + NestedModule + (SynComponentInfo + ([], None, [], [M1], + PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (10,4--10,13)), false, [], false, (10,4--10,25), + { ModuleKeyword = Some (10,4--10,10) + EqualsRange = Some (10,14--10,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M2], + PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (11,4--11,13)), false, [], false, (11,4--11,25), + { ModuleKeyword = Some (11,4--11,10) + EqualsRange = Some (11,14--11,15) }); + NestedModule + (SynComponentInfo + ([], None, [], [M3], + PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (12,4--12,13)), false, [], false, (12,4--12,25), + { ModuleKeyword = Some (12,4--12,10) + EqualsRange = Some (12,14--12,15) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [M4], + PreXmlDoc ((13,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (13,9--13,11)), + ObjectModel + (Class, + [ImplicitCtor + (None, [], Const (Unit, (13,11--13,13)), None, + PreXmlDoc ((13,11), FSharp.Compiler.Xml.XmlDocCollector), + (13,9--13,11), { AsKeyword = None })], (13,16--13,25)), + [], + Some + (ImplicitCtor + (None, [], Const (Unit, (13,11--13,13)), None, + PreXmlDoc ((13,11), FSharp.Compiler.Xml.XmlDocCollector), + (13,9--13,11), { AsKeyword = None })), (13,9--13,25), + { LeadingKeyword = Type (13,4--13,8) + EqualsRange = Some (13,14--13,15) + WithKeyword = None })], (13,4--13,25)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [M5], + PreXmlDoc ((14,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (14,9--14,11)), + ObjectModel + (Class, + [ImplicitCtor + (None, [], Const (Unit, (14,11--14,13)), None, + PreXmlDoc ((14,11), FSharp.Compiler.Xml.XmlDocCollector), + (14,9--14,11), { AsKeyword = None })], (14,16--14,25)), + [], + Some + (ImplicitCtor + (None, [], Const (Unit, (14,11--14,13)), None, + PreXmlDoc ((14,11), FSharp.Compiler.Xml.XmlDocCollector), + (14,9--14,11), { AsKeyword = None })), (14,9--14,25), + { LeadingKeyword = Type (14,4--14,8) + EqualsRange = Some (14,14--14,15) + WithKeyword = None })], (14,4--14,25)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [M6], + PreXmlDoc ((15,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (15,9--15,11)), + ObjectModel + (Class, + [ImplicitCtor + (None, [], Const (Unit, (15,11--15,13)), None, + PreXmlDoc ((15,11), FSharp.Compiler.Xml.XmlDocCollector), + (15,9--15,11), { AsKeyword = None })], (15,16--15,25)), + [], + Some + (ImplicitCtor + (None, [], Const (Unit, (15,11--15,13)), None, + PreXmlDoc ((15,11), FSharp.Compiler.Xml.XmlDocCollector), + (15,9--15,11), { AsKeyword = None })), (15,9--15,25), + { LeadingKeyword = Type (15,4--15,8) + EqualsRange = Some (15,14--15,15) + WithKeyword = None })], (15,4--15,25)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((17,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (17,5--17,6)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([C], [], [None])), + (17,9--17,10)), (17,9--17,10)), [], None, (17,5--17,10), + { LeadingKeyword = Type (17,0--17,4) + EqualsRange = Some (17,7--17,8) + WithKeyword = None })], (17,0--17,10))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--17,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(10,4)-(10,10) parse warning Invalid declaration syntax +(11,4)-(11,10) parse warning Invalid declaration syntax +(12,4)-(12,10) parse warning Invalid declaration syntax diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs new file mode 100644 index 00000000000..e7431a493ce --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs @@ -0,0 +1,11 @@ +module Module + +let x = 1 +type x_t = int +type t = + | X of int + module Nested = begin + let x = 1 + type x_t = int + type t = X of int + end \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl new file mode 100644 index 00000000000..55206deded5 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl @@ -0,0 +1,123 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Type Defn 11.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), None), + Named (SynIdent (x, None), false, None, (3,4--3,5)), None, + Const (Int32 1, (3,8--3,9)), (3,4--3,5), Yes (3,0--3,9), + { LeadingKeyword = Let (3,0--3,3) + InlineKeyword = None + EqualsRange = Some (3,6--3,7) })], (3,0--3,9)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [x_t], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,8)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (4,11--4,14)), (4,11--4,14)), [], None, (4,5--4,14), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,9--4,10) + WithKeyword = None })], (4,0--4,14)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [t], + PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,5--5,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (X, None), + Fields + [SynField + ([], false, None, + LongIdent (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((6,9), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,9--6,12), { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((6,2), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,4--6,12), { BarRange = Some (6,2--6,3) })], + (6,2--6,12)), (6,2--6,12)), [], None, (5,5--6,12), + { LeadingKeyword = Type (5,0--5,4) + EqualsRange = Some (5,7--5,8) + WithKeyword = None })], (5,0--6,12)); + NestedModule + (SynComponentInfo + ([], None, [], [Nested], + PreXmlDoc ((7,2), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,2--7,15)), 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)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [x_t], + PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (9,9--9,12)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (9,15--9,18)), (9,15--9,18)), [], None, (9,9--9,18), + { LeadingKeyword = Type (9,4--9,8) + EqualsRange = Some (9,13--9,14) + WithKeyword = None })], (9,4--9,18)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [t], + PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (10,9--10,10)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (X, None), + Fields + [SynField + ([], false, None, + LongIdent + (SynLongIdent ([int], [], [None])), + false, + PreXmlDoc ((10,18), FSharp.Compiler.Xml.XmlDocCollector), + None, (10,18--10,21), + { LeadingKeyword = None + MutableKeyword = None })], + PreXmlDoc ((10,13), FSharp.Compiler.Xml.XmlDocCollector), + None, (10,13--10,21), { BarRange = None })], + (10,13--10,21)), (10,13--10,21)), [], None, + (10,9--10,21), { LeadingKeyword = Type (10,4--10,8) + EqualsRange = Some (10,11--10,12) + WithKeyword = None })], (10,4--10,21))], + false, (7,2--11,5), { ModuleKeyword = Some (7,2--7,8) + EqualsRange = Some (7,16--7,17) })], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--11,5), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(7,2)-(7,8) parse warning Invalid declaration syntax From 8354b8907599626987f86737be34c0c535046f4d Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 6 Aug 2025 16:46:50 +0200 Subject: [PATCH 16/36] Update tests --- src/Compiler/SyntaxTree/ParseHelpers.fs | 2 - .../WarnOnUnexpectedModuleDefinitions.fs | 43 +++++++------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index 7c9619842d3..47e72d67b92 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1092,8 +1092,6 @@ let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2 for defn in rest do match defn with | NestedModuleAt mKeyword -> - lexBuf.CheckLanguageFeatureAndRecover LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes mKeyword - if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then if mKeyword.StartColumn > lastTypeColumn.StartColumn then warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword)) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs index 33c2442f97b..3b4ff283b9d 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs @@ -32,20 +32,20 @@ type R = type A = A -module M1 = begin end -module M2 = begin end -module M3 = begin end +module M4 = begin end +module M5 = begin end +module M6 = begin end type B = | B - module M4 = begin end - module M5 = begin end - module M6 = begin end + module M7 = begin end + module M8 = begin end + module M9 = begin end module ThisIsFine = let f () = () -type C = C +type D = D """ |> withLangVersionPreview |> typecheck @@ -86,34 +86,21 @@ type R = type A = A -module M1 = begin end -module M2 = begin end -module M3 = begin end +module M5 = begin end +module M6 = begin end +module M7 = begin end type B = | B - module M4 = begin end - module M5 = begin end - module M6 = begin end + module M8 = begin end + module M9 = begin end + module M10 = begin end module ThisIsFine = let f () = () -type C = C +type D = D """ |> withLangVersion10 |> typecheck - |> shouldFail - |> withDiagnostics [ - (Error 3350, Line 31, Col 5, Line 31, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 32, Col 5, Line 32, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 33, Col 5, Line 33, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 35, Col 1, Line 35, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 20, Col 5, Line 20, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 25, Col 1, Line 25, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 26, Col 1, Line 26, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 27, Col 1, Line 27, Col 7, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 15, Col 5, Line 15, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 9, Col 5, Line 9, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - (Error 3350, Line 4, Col 5, Line 4, Col 11, "Feature 'Warn when a module definition is encountered inside a type definition' is not available in F# 10.0. Please use language version 'PREVIEW' or greater.") - ] + |> shouldSucceed From 0f1c26f0a9f69e41e5828c552e77d8796d8834da Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 10 Aug 2025 00:02:53 +0200 Subject: [PATCH 17/36] Update src/Compiler/SyntaxTree/ParseHelpers.fs Co-authored-by: Brian Rourke Boll --- src/Compiler/SyntaxTree/ParseHelpers.fs | 43 +++++++------------------ 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index 47e72d67b92..fa5cc86120c 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1065,38 +1065,17 @@ let leadingKeywordIsAbstract = | SynLeadingKeyword.StaticAbstractMember _ -> true | _ -> false -[] -let (|NestedModuleAt|_|) = - function - | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> ValueSome mKeyword - | _ -> ValueNone - -[] -let (|TypesFollowedByModules|_|) = - function - | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> ValueSome(defns, rest) - | _ -> ValueNone - -let getLastTypeColumn (defns: SynTypeDefn list) = - defns - |> List.choose (function - | SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range) - |> List.tryLast - |> Option.defaultValue range0 - -let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2: SynModuleDecl list) (lexBuf: Lexbuf) = - match moduleDecls1, moduleDecls2 with - | TypesFollowedByModules(defns, rest) -> - let lastTypeColumn = getLastTypeColumn defns - - for defn in rest do - match defn with - | NestedModuleAt mKeyword -> - if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then - if mKeyword.StartColumn > lastTypeColumn.StartColumn then - warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword)) - | _ -> () - | _ -> () +/// See https://github.com/dotnet/fsharp/issues/10066. +let checkMisleadinglyIndentedTrailingDecls (leadingDecls: SynModuleDecl list) (trailingDecls: SynModuleDecl list) (lexBuf: Lexbuf) = + if lexBuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes then + leadingDecls + |> List.tryLast + |> Option.iter (fun leadingDecl -> + let leadingStartCol = leadingDecl.Range.StartColumn + for trailingDecl in trailingDecls do + let mTrailing = trailingDecl.Range + if leadingStartCol < mTrailing.StartColumn then + warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mTrailing))) /// Unified helper for creating let/let!/use/use! expressions /// Creates either SynExpr.LetOrUse or SynExpr.LetOrUseBang based on isBang parameter From b98dbdf883c4d10b6a58eeb69626bd42738e5352 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 11 Aug 2025 15:58:26 +0100 Subject: [PATCH 18/36] Revert "Update src/Compiler/SyntaxTree/ParseHelpers.fs" This reverts commit 0f1c26f0a9f69e41e5828c552e77d8796d8834da. --- src/Compiler/SyntaxTree/ParseHelpers.fs | 43 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index fa5cc86120c..47e72d67b92 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1065,17 +1065,38 @@ let leadingKeywordIsAbstract = | SynLeadingKeyword.StaticAbstractMember _ -> true | _ -> false -/// See https://github.com/dotnet/fsharp/issues/10066. -let checkMisleadinglyIndentedTrailingDecls (leadingDecls: SynModuleDecl list) (trailingDecls: SynModuleDecl list) (lexBuf: Lexbuf) = - if lexBuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes then - leadingDecls - |> List.tryLast - |> Option.iter (fun leadingDecl -> - let leadingStartCol = leadingDecl.Range.StartColumn - for trailingDecl in trailingDecls do - let mTrailing = trailingDecl.Range - if leadingStartCol < mTrailing.StartColumn then - warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mTrailing))) +[] +let (|NestedModuleAt|_|) = + function + | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> ValueSome mKeyword + | _ -> ValueNone + +[] +let (|TypesFollowedByModules|_|) = + function + | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> ValueSome(defns, rest) + | _ -> ValueNone + +let getLastTypeColumn (defns: SynTypeDefn list) = + defns + |> List.choose (function + | SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range) + |> List.tryLast + |> Option.defaultValue range0 + +let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2: SynModuleDecl list) (lexBuf: Lexbuf) = + match moduleDecls1, moduleDecls2 with + | TypesFollowedByModules(defns, rest) -> + let lastTypeColumn = getLastTypeColumn defns + + for defn in rest do + match defn with + | NestedModuleAt mKeyword -> + if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then + if mKeyword.StartColumn > lastTypeColumn.StartColumn then + warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword)) + | _ -> () + | _ -> () /// Unified helper for creating let/let!/use/use! expressions /// Creates either SynExpr.LetOrUse or SynExpr.LetOrUseBang based on isBang parameter From bdf8a93cc22208237de5fe347c730ac56417e1a1 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 13 Aug 2025 09:32:11 +0100 Subject: [PATCH 19/36] Use LexFilter instead ParseHelper to raise the warnings. --- src/Compiler/SyntaxTree/LexFilter.fs | 102 ++++++++++++++++++ src/Compiler/SyntaxTree/ParseHelpers.fs | 33 ------ src/Compiler/SyntaxTree/ParseHelpers.fsi | 4 - src/Compiler/pars.fsy | 6 +- ...rningInvalidConstructsInTypeDefinition.fs} | 14 +-- .../FSharp.Compiler.ComponentTests.fsproj | 2 +- 6 files changed, 112 insertions(+), 49 deletions(-) rename tests/FSharp.Compiler.ComponentTests/ErrorMessages/{WarnOnUnexpectedModuleDefinitions.fs => WarningInvalidConstructsInTypeDefinition.fs} (63%) diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 1fb62e72940..722513ef2d8 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1368,6 +1368,94 @@ 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. We traverse the context stack looking for a CtxtTypeDefns + // 2. If found, we check if the current token is indented inside it (column check) + // 3. We verify we're not in a legitimate nested context (members, augmentations, or escaped to module/namespace) + // 4. If all conditions match and the language feature is enabled, we issue a warning + // + // Note: We don't check 'let' bindings as they can be valid in classes with constructors + // Note: We skip validation inside parentheses to avoid false positives with inline IL syntax (# ... type ... #) + let checkIfInvalidConstructsInTypeDefinition keyword = + // Only perform validation if the language feature is enabled + if not (lexbuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then + () + else + // 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 + 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 + if 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, 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 warningMessage = + match keyword with + | "TYPE" -> + "Nested type definitions are not allowed. Types must be defined at module or namespace level." + | "MODULE" -> + "Modules cannot be nested inside types. Define modules at module or namespace level." + | "EXCEPTION" -> + "Exceptions must be defined at module level, not inside types." + | "OPEN" -> + "'open' declarations must appear at module level, not inside types." + | _ -> + sprintf "'%s' must be defined at module level, not inside a type." keyword + + warn tokenTup warningMessage + 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 +2107,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 + checkIfInvalidConstructsInTypeDefinition "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 +2121,8 @@ type LexFilterImpl ( // exception ... ~~~> CtxtException | EXCEPTION, _ :: _ -> + // Check if this exception definition is inappropriately nested in a type + checkIfInvalidConstructsInTypeDefinition "EXCEPTION" if debug then dprintf "EXCEPTION: entering CtxtException(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtException tokenStartPos) returnToken tokenLexbufState token @@ -2470,6 +2564,9 @@ type LexFilterImpl ( returnToken tokenLexbufState token | TYPE, _ -> + // Check if this type definition is inappropriately nested in another type + checkIfInvalidConstructsInTypeDefinition "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 +2587,11 @@ type LexFilterImpl ( | OBLOCKBEGIN, _ -> returnToken tokenLexbufState token + | OPEN, _ :: _ -> + // Check if this open declaration is inappropriately nested in a type + checkIfInvalidConstructsInTypeDefinition "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.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index e944907388f..4db7221c787 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1065,39 +1065,6 @@ let leadingKeywordIsAbstract = | SynLeadingKeyword.StaticAbstractMember _ -> true | _ -> false -[] -let (|NestedModuleAt|_|) = - function - | SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> ValueSome mKeyword - | _ -> ValueNone - -[] -let (|TypesFollowedByModules|_|) = - function - | [ SynModuleDecl.Types(typeDefns = defns) ], rest -> ValueSome(defns, rest) - | _ -> ValueNone - -let getLastTypeColumn (defns: SynTypeDefn list) = - defns - |> List.choose (function - | SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range) - |> List.tryLast - |> Option.defaultValue range0 - -let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2: SynModuleDecl list) (lexBuf: Lexbuf) = - match moduleDecls1, moduleDecls2 with - | TypesFollowedByModules(defns, rest) -> - let lastTypeColumn = getLastTypeColumn defns - - for defn in rest do - match defn with - | NestedModuleAt mKeyword -> - if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then - if mKeyword.StartColumn > lastTypeColumn.StartColumn then - warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword)) - | _ -> () - | _ -> () - /// Unified helper for creating let/let!/use/use! expressions /// Creates SynExpr.LetOrUse based on isBang parameter /// Handles all four cases: 'let', 'let!', 'use', and 'use!' diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fsi b/src/Compiler/SyntaxTree/ParseHelpers.fsi index fa60442c6e5..301e72e0ed7 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fsi +++ b/src/Compiler/SyntaxTree/ParseHelpers.fsi @@ -270,7 +270,3 @@ val mkSynField: SynField val leadingKeywordIsAbstract: SynLeadingKeyword -> bool - -/// Check for invalid declarations inside type definitions -val checkInvalidDeclsInTypeDefn: - moduleDecls1: SynModuleDecl list -> moduleDecls2: SynModuleDecl list -> lexBuf: Lexbuf -> unit diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index c73c01ef309..99da176d18e 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -1272,12 +1272,10 @@ moduleDefnsOrExpr: /* A sequence of definitions in a namespace or module */ moduleDefns: | moduleDefnOrDirective moduleDefnOrDirective - { checkInvalidDeclsInTypeDefn $1 $2 parseState.LexBuffer - $1 @ $2 } + { $1 @ $2 } | moduleDefnOrDirective moduleDefns - { checkInvalidDeclsInTypeDefn $1 $2 parseState.LexBuffer - $1 @ $2 } + { $1 @ $2 } | moduleDefnOrDirective topSeparators moduleDefnsOrExpr { $1 @ $3 } diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs similarity index 63% rename from tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs index 3b4ff283b9d..40ccca55553 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnOnUnexpectedModuleDefinitions.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs @@ -51,13 +51,13 @@ type D = D |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 554, Line 31, Col 5, Line 31, Col 11, "Invalid declaration syntax") - (Warning 554, Line 32, Col 5, Line 32, Col 11, "Invalid declaration syntax") - (Warning 554, Line 33, Col 5, Line 33, Col 11, "Invalid declaration syntax") - (Warning 554, Line 20, Col 5, Line 20, Col 11, "Invalid declaration syntax") - (Warning 554, Line 15, Col 5, Line 15, Col 11, "Invalid declaration syntax") - (Warning 554, Line 9, Col 5, Line 9, Col 11, "Invalid declaration syntax"); - (Warning 554, Line 4, Col 5, Line 4, Col 11, "Invalid declaration syntax") + (Warning 58, Line 4, Col 5, Line 4, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 9, Col 5, Line 9, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 15, Col 5, Line 15, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 20, Col 5, Line 20, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 31, Col 5, Line 31, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 32, Col 5, Line 32, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 33, Col 5, Line 33, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 40a517abe0b..7317ca88ea1 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -221,7 +221,7 @@ - + From 0b46a40f3c9760d8001beeb4e7915887a96a6fd7 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 13 Aug 2025 10:19:52 +0100 Subject: [PATCH 20/36] Update baselines --- .../NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl | 2 ++ .../SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl | 2 +- .../SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl | 2 +- .../SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl | 2 +- .../SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl | 2 +- .../SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl | 6 +++--- .../SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl | 6 +++--- .../SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl | 3 +++ .../SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl | 6 +++--- .../SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl | 9 ++++++--- .../SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl | 2 +- .../Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl | 2 ++ 12 files changed, 27 insertions(+), 17 deletions(-) diff --git a/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl b/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl index 091be309d37..9c1cbab1e36 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 warning Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl index 3b4119781ae..03090b1784a 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl @@ -68,4 +68,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(5,4)-(5,10) parse warning Invalid declaration syntax +(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl index bda7d32fe20..911c768aad4 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl @@ -81,4 +81,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(5,4)-(5,10) parse warning Invalid declaration syntax +(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl index 85227371b4a..1a3ec1aba13 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl @@ -54,4 +54,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(6,4)-(6,10) parse warning Invalid declaration syntax +(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl index 2503cdeecfb..b3035248bd3 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl @@ -52,4 +52,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(5,4)-(5,10) parse warning Invalid declaration syntax +(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl index ec4349c70c6..e4628796124 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl @@ -74,6 +74,6 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(7,4)-(7,10) parse warning Invalid declaration syntax -(8,4)-(8,10) parse warning Invalid declaration syntax -(9,4)-(9,10) parse warning Invalid declaration syntax +(7,4)-(7,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(9,4)-(9,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl index d4b2954a1b8..3f261790070 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl @@ -95,6 +95,6 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(11,4)-(11,10) parse warning Invalid declaration syntax -(12,4)-(12,10) parse warning Invalid declaration syntax -(13,4)-(13,10) parse warning Invalid declaration syntax +(11,4)-(11,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(12,4)-(12,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(13,4)-(13,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl index 4b786d93011..f9d930d88bd 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl @@ -61,5 +61,8 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) +(12,8)-(12,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. (12,8)-(12,14) parse error Unexpected keyword 'module' in type definition. Expected incomplete structured construct at or before this point, 'end' or other token. +(13,8)-(13,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. (13,8)-(13,14) parse error Unexpected keyword 'module' in implementation file +(14,8)-(14,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl index 1cfe90cc1b9..73bbea49267 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl @@ -143,6 +143,6 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(10,4)-(10,10) parse warning Invalid declaration syntax -(11,4)-(11,10) parse warning Invalid declaration syntax -(12,4)-(12,10) parse warning Invalid declaration syntax +(10,4)-(10,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(11,4)-(11,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(12,4)-(12,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl index 2b7791c10b2..2af73d14f3b 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl @@ -206,6 +206,9 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(10,4)-(10,10) parse warning Invalid declaration syntax -(11,4)-(11,10) parse warning Invalid declaration syntax -(12,4)-(12,10) parse warning Invalid declaration syntax +(10,4)-(10,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(11,4)-(11,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(12,4)-(12,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(13,4)-(13,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(14,4)-(14,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(15,4)-(15,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl index 55206deded5..90dddf258a9 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl @@ -120,4 +120,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(7,2)-(7,8) parse warning Invalid declaration syntax +(7,2)-(7,8) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl b/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl index 536c4cc9e54..4fb5fce3e4e 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 warning Nested type definitions are not allowed. Types must be defined at module or namespace level. From 6a9ddd94a6286f354d61ed34c2c759f3c5577044 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 13 Aug 2025 18:06:46 +0100 Subject: [PATCH 21/36] update tests --- ...stract Class With Invalid Constructs 01.fs | 13 ++ ...ct Class With Invalid Constructs 01.fs.bsl | 101 +++++++++ .../Type/Cascading Invalid Constructs 01.fs | 13 ++ .../Cascading Invalid Constructs 01.fs.bsl | 89 ++++++++ .../SyntaxTree/Type/Code Quotations 01.fs | 18 ++ .../SyntaxTree/Type/Code Quotations 01.fs.bsl | 108 +++++++++ .../Type/Comments With Keywords 01.fs | 17 ++ .../Type/Comments With Keywords 01.fs.bsl | 116 ++++++++++ .../Type/Deeply Indented Type 01.fs | 12 + .../Type/Deeply Indented Type 01.fs.bsl | 111 +++++++++ .../Do Binding With Invalid Constructs 01.fs | 21 ++ ... Binding With Invalid Constructs 01.fs.bsl | 91 ++++++++ .../Type/Double Semicolon Delimiters 01.fs | 13 ++ .../Double Semicolon Delimiters 01.fs.bsl | 86 +++++++ .../Type/Exception Inside Type 01.fs | 6 + .../Type/Exception Inside Type 01.fs.bsl | 13 ++ .../Inherit With Invalid Constructs 01.fs | 13 ++ .../Inherit With Invalid Constructs 01.fs.bsl | 107 +++++++++ .../SyntaxTree/Type/Inline IL With Type 01.fs | 4 + .../Type/Inline IL With Type 01.fs.bsl | 63 ++++++ .../Type/Interleaved Invalid Constructs 01.fs | 10 + .../Interleaved Invalid Constructs 01.fs.bsl | 80 +++++++ .../SyntaxTree/Type/Keywords In Strings 01.fs | 12 + .../Type/Keywords In Strings 01.fs.bsl | 129 +++++++++++ .../SyntaxTree/Type/Let Inside Class 01.fs | 9 + .../Type/Let Inside Class 01.fs.bsl | 140 ++++++++++++ .../Type/Module After Do Binding 01.fs | 7 + .../Type/Module After Do Binding 01.fs.bsl | 71 ++++++ .../Type/Module After Members 01.fs | 9 + .../Type/Module After Members 01.fs.bsl | 109 +++++++++ .../Type/Module At Module Level 01.fs | 8 + .../Type/Module At Module Level 01.fs.bsl | 69 ++++++ .../Type/Module At Type Column 01.fs | 8 + .../Type/Module At Type Column 01.fs.bsl | 69 ++++++ .../SyntaxTree/Type/Module Inside Class 01.fs | 7 + ...2.fs.bsl => Module Inside Class 01.fs.bsl} | 70 +++--- ...Module Inside Class With Constructor 01.fs | 8 + ...le Inside Class With Constructor 01.fs.bsl | 107 +++++++++ .../Type/Module Inside Delegate 01.fs | 6 + .../Type/Module Inside Delegate 01.fs.bsl | 93 ++++++++ ...fn 01.fs => Module Inside Interface 01.fs} | 3 +- ....bsl => Module Inside Interface 01.fs.bsl} | 52 ++--- ...5.fs => Module Inside Interface End 01.fs} | 3 +- ... => Module Inside Interface End 01.fs.bsl} | 36 +-- .../Type/Module Inside Nested Type 01.fs | 9 + .../Type/Module Inside Nested Type 01.fs.bsl | 69 ++++++ .../Type/Module Inside Record 01.fs | 7 + ....fs.bsl => Module Inside Record 01.fs.bsl} | 42 ++-- .../Type/Module Inside Struct 01.fs | 9 + .../Type/Module Inside Struct 01.fs.bsl | 68 ++++++ .../Type/Module Inside Type Defn 02.fs | 6 - .../Type/Module Inside Type Defn 03.fs | 7 - .../Type/Module Inside Type Defn 04.fs | 6 - .../Type/Module Inside Type Defn 04.fs.bsl | 55 ----- .../Type/Module Inside Type Defn 06.fs | 11 - .../Type/Module Inside Type Defn 06.fs.bsl | 79 ------- .../Type/Module Inside Type Defn 07.fs | 15 -- .../Type/Module Inside Type Defn 07.fs.bsl | 100 -------- .../Type/Module Inside Type Defn 08.fs | 16 -- .../Type/Module Inside Type Defn 08.fs.bsl | 68 ------ .../Type/Module Inside Type Defn 09.fs | 14 -- .../Type/Module Inside Type Defn 09.fs.bsl | 148 ------------ .../Type/Module Inside Type Defn 10.fs | 17 -- .../Type/Module Inside Type Defn 10.fs.bsl | 214 ------------------ .../Type/Module Inside Type Defn 11.fs | 11 - .../Type/Module Inside Type Defn 11.fs.bsl | 123 ---------- ...Module Inside Type With Augmentation 01.fs | 7 + ...le Inside Type With Augmentation 01.fs.bsl | 32 +++ .../SyntaxTree/Type/Module Inside Union 01.fs | 8 + .../Type/Module Inside Union 01.fs.bsl | 57 +++++ .../Type/Module Less Indented 01.fs | 8 + .../Type/Module Less Indented 01.fs.bsl | 68 ++++++ .../Type/Module Same Indentation 01.fs | 12 + .../Type/Module Same Indentation 01.fs.bsl | 88 +++++++ .../Module With Semicolon Delimiter 01.fs | 7 + .../Module With Semicolon Delimiter 01.fs.bsl | 49 ++++ ...Constructors With Invalid Constructs 01.fs | 14 ++ ...tructors With Invalid Constructs 01.fs.bsl | 114 ++++++++++ .../Multiple Invalid Constructs In Type 01.fs | 10 + ...tiple Invalid Constructs In Type 01.fs.bsl | 79 +++++++ .../Type/Nested Module Hierarchy 01.fs | 17 ++ .../Type/Nested Module Hierarchy 01.fs.bsl | 126 +++++++++++ .../Type/One Line With Semicolons 01.fs | 4 + .../Type/One Line With Semicolons 01.fs.bsl | 82 +++++++ .../SyntaxTree/Type/Open Inside Type 01.fs | 6 + .../Type/Open Inside Type 01.fs.bsl | 13 ++ .../Type/Same Line Declarations 01.fs | 4 + .../Type/Same Line Declarations 01.fs.bsl | 60 +++++ ...atic Members With Invalid Constructs 01.fs | 11 + ... Members With Invalid Constructs 01.fs.bsl | 105 +++++++++ .../SyntaxTree/Type/Type Inside Type 01.fs | 7 + .../Type/Type Inside Type 01.fs.bsl | 54 +++++ 92 files changed, 3273 insertions(+), 993 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Code Quotations 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Inline IL With Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module After Members 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module At Module Level 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module At Type Column 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs rename tests/service/data/SyntaxTree/Type/{Module Inside Type Defn 02.fs.bsl => Module Inside Class 01.fs.bsl} (50%) create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl rename tests/service/data/SyntaxTree/Type/{Module Inside Type Defn 01.fs => Module Inside Interface 01.fs} (50%) rename tests/service/data/SyntaxTree/Type/{Module Inside Type Defn 01.fs.bsl => Module Inside Interface 01.fs.bsl} (55%) rename tests/service/data/SyntaxTree/Type/{Module Inside Type Defn 05.fs => Module Inside Interface End 01.fs} (63%) rename tests/service/data/SyntaxTree/Type/{Module Inside Type Defn 05.fs.bsl => Module Inside Interface End 01.fs.bsl} (57%) create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs rename tests/service/data/SyntaxTree/Type/{Module Inside Type Defn 03.fs.bsl => Module Inside Record 01.fs.bsl} (57%) create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Less Indented 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module Same Indentation 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module With Semicolon Delimiter 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/One Line With Semicolons 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs.bsl diff --git a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs new file mode 100644 index 00000000000..5f559c66818 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs @@ -0,0 +1,13 @@ +// Expected: Multiple warnings for module and type +module Module + +[] +type AbstractBase() = + abstract member Method : int -> int + + module InvalidModule = + let helper = 10 + + type InvalidType = string + + default _.Method(x) = x * 2 diff --git a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..4501df63a99 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl @@ -0,0 +1,101 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Abstract Class With Invalid Constructs 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([{ Attributes = + [{ TypeName = + SynLongIdent ([AbstractClass], [], [None]) + ArgExpr = Const (Unit, (4,2--4,15)) + Target = None + AppliesToGetterAndSetter = false + Range = (4,2--4,15) }] + Range = (4,0--4,17) }], None, [], [AbstractBase], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,5--5,17)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (5,17--5,19)), None, + PreXmlDoc ((5,17), FSharp.Compiler.Xml.XmlDocCollector), + (5,5--5,17), { AsKeyword = None }); + AbstractSlot + (SynValSig + ([], SynIdent (Method, None), + SynValTyparDecls (None, true), + Fun + (LongIdent (SynLongIdent ([int], [], [None])), + LongIdent (SynLongIdent ([int], [], [None])), + (6,29--6,39), { ArrowRange = (6,33--6,35) }), + SynValInfo + ([[SynArgInfo ([], false, None)]], + SynArgInfo ([], false, None)), false, false, + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + Single None, None, (6,4--6,39), + { LeadingKeyword = + AbstractMember ((6,4--6,12), (6,13--6,19)) + InlineKeyword = None + WithKeyword = None + EqualsRange = None }), + { IsInstance = true + IsDispatchSlot = true + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, (6,4--6,39), + { GetSetKeywords = None })], (6,4--6,39)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (5,17--5,19)), None, + PreXmlDoc ((5,17), FSharp.Compiler.Xml.XmlDocCollector), + (5,5--5,17), { AsKeyword = None })), (4,0--6,39), + { LeadingKeyword = Type (5,0--5,4) + EqualsRange = Some (5,20--5,21) + WithKeyword = None })], (4,0--6,39)); + 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) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [InvalidType], + PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (11,9--11,20)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([string], [], [None])), + (11,23--11,29)), (11,23--11,29)), [], None, + (11,9--11,29), { LeadingKeyword = Type (11,4--11,8) + EqualsRange = Some (11,21--11,22) + WithKeyword = None })], (11,4--11,29))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--11,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,50)] }, set [])) + +(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(11,4)-(11,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(13,4)-(13,11) parse error Unexpected keyword 'default' in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs new file mode 100644 index 00000000000..205584cb8b6 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs @@ -0,0 +1,13 @@ +// Expected: Multiple warnings for each inappropriately nested construct +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/Cascading Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..8c3ef784302 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl @@ -0,0 +1,89 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Cascading 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 + (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, [], [B], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,9--6,10)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (6,13--6,14)), (6,13--6,14)), [], None, (6,9--6,14), + { LeadingKeyword = Type (6,4--6,8) + EqualsRange = Some (6,11--6,12) + WithKeyword = None })], (6,4--6,14)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,8--7,16)), false, + [Expr (Const (Unit, (7,19--7,21)), (7,19--7,21))], false, + (7,8--7,21), { ModuleKeyword = Some (7,8--7,14) + EqualsRange = Some (7,17--7,18) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (D, None), Fields [], PreXmlDocEmpty, None, + (8,22--8,23), { BarRange = None }), None, + PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (8,12--8,23)), None, [], (8,12--8,23)), (8,12--8,23)); + ModuleAbbrev (E, [C], (9,16--9,28)); + Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((10,20), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (10,26--10,28)), (10,26--10,28))], + None, (10,24--10,28)), None, Const (Unit, (10,31--10,33)), + (10,24--10,28), NoneAtLet, + { LeadingKeyword = Let (10,20--10,23) + InlineKeyword = None + EqualsRange = Some (10,29--10,30) })], (10,20--10,33)); + Open + (ModuleOrNamespace + (SynLongIdent ([System], [], [None]), (11,29--11,35)), + (11,24--11,35)); + NestedModule + (SynComponentInfo + ([], None, [], [G], + PreXmlDoc ((12,28), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (12,28--12,36)), false, + [ModuleAbbrev (H, [E], (13,32--13,44))], false, (12,28--13,44), + { ModuleKeyword = Some (12,28--12,34) + EqualsRange = Some (12,37--12,38) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--13,44), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,72)] }, set [])) + +(6,4)-(6,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(7,8)-(7,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs b/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs new file mode 100644 index 00000000000..b110431c83b --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs @@ -0,0 +1,18 @@ +// Expected: No warning - constructs in quotations are data +module Module + +open FSharp.Quotations + +type MyClass() = + member _.GetQuotation() = + <@ + type T = int + module M = + let x = 1 + @> + + member _.GetQuotation2() = + <@@ + exception E of string + open System + @@> diff --git a/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl new file mode 100644 index 00000000000..94e011061a5 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl @@ -0,0 +1,108 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Code Quotations 01.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Open + (ModuleOrNamespace + (SynLongIdent + ([FSharp; Quotations], [(4,11--4,12)], [None; None]), + (4,5--4,22)), (4,0--4,22)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [MyClass], + 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 }); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,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 + ([_; GetQuotation], [(7,12--7,13)], + [None; None]), None, None, + Pats + [Paren + (Const (Unit, (7,25--7,27)), (7,25--7,27))], + None, (7,11--7,27)), None, + FromParseError + (Quote + (Ident op_Quotation, false, + ArbitraryAfterError + ("quoteExpr2", (8,10--8,10)), false, + (8,8--8,10)), (8,8--8,10)), (7,11--7,27), + NoneAtInvisible, + { LeadingKeyword = Member (7,4--7,10) + InlineKeyword = None + EqualsRange = Some (7,28--7,29) }), (7,4--8,10))], + (7,4--8,10)), [], + 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--8,10), + { LeadingKeyword = Type (6,0--6,4) + EqualsRange = Some (6,15--6,16) + WithKeyword = None })], (6,0--8,10)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [T], + PreXmlDoc ((9,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (9,17--9,18)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (9,21--9,24)), (9,21--9,24)), [], None, (9,17--9,24), + { LeadingKeyword = Type (9,12--9,16) + EqualsRange = Some (9,19--9,20) + WithKeyword = None })], (9,12--9,24)); + NestedModule + (SynComponentInfo + ([], None, [], [M], + PreXmlDoc ((10,12), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (10,12--10,20)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((11,16), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named (SynIdent (x, None), false, None, (11,20--11,21)), + None, Const (Int32 1, (11,24--11,25)), (11,20--11,21), + Yes (11,16--11,25), { LeadingKeyword = Let (11,16--11,19) + InlineKeyword = None + EqualsRange = Some (11,22--11,23) })], + (11,16--11,25))], false, (10,12--11,25), + { ModuleKeyword = Some (10,12--10,18) + EqualsRange = Some (10,21--10,22) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--11,25), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,59)] }, set [])) + +(9,12)-(9,16) parse error Incomplete structured construct at or before this point in quotation literal +(8,8)-(8,10) parse error Unmatched '<@ @>' +(9,12)-(9,16) parse error Unexpected keyword 'type' in type definition. Expected incomplete structured construct at or before this point or other token. +(10,12)-(10,18) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(12,8)-(12,10) parse error Unexpected end of quotation in definition. Expected incomplete structured construct at or before this point or other token. 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..6ce256beda0 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs @@ -0,0 +1,17 @@ +// Expected: No warning - keywords in comments are ignored +module Module + +type MyType() = + // This comment mentions module and type + member _.Method() = 1 + + (* This multi-line comment also contains + module MyModule + type MyType + exception MyException + open System + *) + member _.AnotherMethod() = 2 + + /// XML doc comment with module, type, exception keywords + member _.DocumentedMethod() = 3 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..7ec21126bc6 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl @@ -0,0 +1,116 @@ +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, + [ImplicitCtor + (None, [], Const (Unit, (4,11--4,13)), None, + PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,11), { AsKeyword = None }); + 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 ((14,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], [(14,12--14,13)], + [None; None]), None, None, + Pats + [Paren + (Const (Unit, (14,26--14,28)), + (14,26--14,28))], None, (14,11--14,28)), + None, Const (Int32 2, (14,31--14,32)), + (14,11--14,28), NoneAtInvisible, + { LeadingKeyword = Member (14,4--14,10) + InlineKeyword = None + EqualsRange = Some (14,29--14,30) }), + (14,4--14,32)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((17,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 + ([_; DocumentedMethod], [(17,12--17,13)], + [None; None]), None, None, + Pats + [Paren + (Const (Unit, (17,29--17,31)), + (17,29--17,31))], None, (17,11--17,31)), + None, Const (Int32 3, (17,34--17,35)), (16,4--17,31), + NoneAtInvisible, + { LeadingKeyword = Member (17,4--17,10) + InlineKeyword = None + EqualsRange = Some (17,32--17,33) }), + (16,4--17,35))], (6,4--17,35)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,11--4,13)), None, + PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,11), { AsKeyword = None })), (4,5--17,35), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,14--4,15) + WithKeyword = None })], (4,0--17,35))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--17,35), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = + [LineComment (1,0--1,58); LineComment (5,4--5,44); + BlockComment (8,4--13,6)] }, 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..fe645b29cf7 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs @@ -0,0 +1,12 @@ +// Expected: Multiple warnings for nested invalid constructs +module OuterModule + +module InnerModule = + module DeeplyNested = + type IndentedType = + | Case1 + | Case2 + type NestedType = int // Should warn + module NestedModule = // Should warn + let x = 1 + exception NestedExc of string // Should warn 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..a17d5f76db7 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl @@ -0,0 +1,111 @@ +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 + (Union + (None, + [SynUnionCase + ([], SynIdent (Case1, None), Fields [], + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (7,14--7,19), + { BarRange = Some (7,12--7,13) }); + SynUnionCase + ([], SynIdent (Case2, None), Fields [], + PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (8,14--8,19), + { BarRange = Some (8,12--8,13) })], + (7,12--8,19)), (7,12--8,19)), [], None, + (6,13--8,19), { LeadingKeyword = Type (6,8--6,12) + EqualsRange = Some (6,26--6,27) + WithKeyword = None })], (6,8--8,19)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [NestedType], + PreXmlDoc ((9,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (9,17--9,27)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (9,30--9,33)), (9,30--9,33)), [], None, + (9,17--9,33), { LeadingKeyword = Type (9,12--9,16) + EqualsRange = Some (9,28--9,29) + WithKeyword = None })], (9,12--9,33)); + NestedModule + (SynComponentInfo + ([], None, [], [NestedModule], + PreXmlDoc ((10,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (10,12--10,31)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((11,16), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (x, None), false, None, (11,20--11,21)), + None, Const (Int32 1, (11,24--11,25)), + (11,20--11,21), Yes (11,16--11,25), + { LeadingKeyword = Let (11,16--11,19) + InlineKeyword = None + EqualsRange = Some (11,22--11,23) })], + (11,16--11,25))], false, (10,12--11,25), + { ModuleKeyword = Some (10,12--10,18) + EqualsRange = Some (10,32--10,33) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (NestedExc, None), + Fields + [SynField + ([], false, None, + LongIdent + (SynLongIdent ([string], [], [None])), + false, + PreXmlDoc ((12,35), FSharp.Compiler.Xml.XmlDocCollector), + None, (12,35--12,41), + { LeadingKeyword = None + MutableKeyword = None })], PreXmlDocEmpty, + None, (12,22--12,41), { BarRange = None }), None, + PreXmlDoc ((12,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (12,12--12,41)), None, [], (12,12--12,41)), + (12,12--12,41))], false, (5,4--12,41), + { ModuleKeyword = Some (5,4--5,10) + EqualsRange = Some (5,24--5,25) })], false, (4,0--12,41), + { ModuleKeyword = Some (4,0--4,6) + EqualsRange = Some (4,19--4,20) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--12,41), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = + [LineComment (1,0--1,60); LineComment (9,35--9,49); + LineComment (10,35--10,49); LineComment (12,43--12,57)] }, set [])) + +(9,12)-(9,16) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(10,12)-(10,18) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(12,12)-(12,21) parse warning Exceptions must be defined at module level, not inside types. diff --git a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs new file mode 100644 index 00000000000..d175e7f26a9 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs @@ -0,0 +1,21 @@ +// Expected: Multiple warnings for type, module, and open +module Module + +type ClassWithDoBinding() = + let mutable initialized = false + + do + printfn "Starting initialization" + initialized <- true + + type InternalType = int + + do + printfn "More initialization" + + module InternalModule = + let x = 1 + + open System.Collections + + member _.IsInitialized = initialized diff --git a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..67ce00efed8 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl @@ -0,0 +1,91 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Do Binding With Invalid Constructs 01.fs", false, + QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [ClassWithDoBinding], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,23)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,23--4,25)), None, + PreXmlDoc ((4,23), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,23), { AsKeyword = None }); + LetBindings + ([SynBinding + (None, Normal, false, true, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (initialized, None), false, None, + (5,16--5,27)), None, + Const (Bool false, (5,30--5,35)), (5,16--5,27), + Yes (5,4--5,35), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,28--5,29) })], false, false, + (5,4--5,35)); + LetBindings + ([SynBinding + (None, Do, false, false, [], PreXmlDocEmpty, + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), Const (Unit, (7,4--9,27)), None, + Sequential + (SuppressNeither, true, + App + (NonAtomic, false, Ident printfn, + Const + (String + ("Starting initialization", Regular, + (8,16--8,41)), (8,16--8,41)), + (8,8--8,41)), + LongIdentSet + (SynLongIdent ([initialized], [], [None]), + Const (Bool true, (9,23--9,27)), (9,8--9,27)), + (8,8--9,27), { SeparatorRange = None }), + (7,4--9,27), NoneAtDo, + { LeadingKeyword = Do (7,4--7,6) + InlineKeyword = None + EqualsRange = None })], false, false, (7,4--9,27))], + (5,4--9,27)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,23--4,25)), None, + PreXmlDoc ((4,23), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,23), { AsKeyword = None })), (4,5--9,27), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,26--4,27) + WithKeyword = None })], (4,0--9,27)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [InternalType], + PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (11,9--11,21)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (11,24--11,27)), (11,24--11,27)), [], None, + (11,9--11,27), { LeadingKeyword = Type (11,4--11,8) + EqualsRange = Some (11,22--11,23) + WithKeyword = None })], (11,4--11,27))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--11,27), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,57)] }, set [])) + +(11,4)-(11,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(13,4)-(13,6) parse error Unexpected keyword 'do' in definition. Expected incomplete structured construct at or before this point or other token. +(16,4)-(16,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(19,4)-(19,8) parse warning 'open' declarations must appear 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..75b768809ad --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs @@ -0,0 +1,13 @@ +// 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/Double Semicolon Delimiters 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl new file mode 100644 index 00000000000..217a5acb19a --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl @@ -0,0 +1,86 @@ +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 + (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, [], [B], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,9--6,10)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([A], [], [None])), + (6,13--6,14)), (6,13--6,14)), [], None, (6,9--6,14), + { LeadingKeyword = Type (6,4--6,8) + EqualsRange = Some (6,11--6,12) + WithKeyword = None })], (6,4--6,14)); + NestedModule + (SynComponentInfo + ([], None, [], [C], + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,8--7,16)), false, + [Expr (Const (Unit, (7,19--7,21)), (7,19--7,21))], false, + (7,8--7,21), { ModuleKeyword = Some (7,8--7,14) + EqualsRange = Some (7,17--7,18) }); + Exception + (SynExceptionDefn + (SynExceptionDefnRepr + ([], + SynUnionCase + ([], SynIdent (D, None), Fields [], PreXmlDocEmpty, None, + (8,22--8,23), { BarRange = None }), None, + PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), + None, (8,12--8,23)), None, [], (8,12--8,23)), (8,12--8,23)); + ModuleAbbrev (E, [C], (9,16--9,28)); + Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((10,20), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent ([f], [], [None]), None, None, + Pats [Paren (Const (Unit, (10,26--10,28)), (10,26--10,28))], + None, (10,24--10,28)), None, Const (Unit, (10,31--10,33)), + (10,24--10,28), NoneAtLet, + { LeadingKeyword = Let (10,20--10,23) + InlineKeyword = None + EqualsRange = Some (10,29--10,30) })], (10,20--10,33)); + Open + (ModuleOrNamespace + (SynLongIdent ([System], [], [None]), (11,29--11,35)), + (11,24--11,35)); + NestedModule + (SynComponentInfo + ([], None, [], [G], + PreXmlDoc ((12,28), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (12,28--12,36)), false, + [ModuleAbbrev (H, [E], (13,32--13,44))], false, (12,28--13,44), + { ModuleKeyword = Some (12,28--12,34) + EqualsRange = Some (12,37--12,38) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--13,44), { 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/Exception Inside Type 01.fs b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs new file mode 100644 index 00000000000..b6bde6322af --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs @@ -0,0 +1,6 @@ +// Expected: Warning for exception inside type +module Module + +type A = + | A + exception MyException of string 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..1d2ee056ab3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl @@ -0,0 +1,13 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Exception Inside Type 01.fs", false, + QualifiedNameOfFile Exception Inside Type 01, [], + [SynModuleOrNamespace + ([Exception Inside Type 01], false, AnonModule, [], PreXmlDocEmpty, [], + None, (7,0--7,0), { LeadingKeyword = None })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,46)] }, set [])) + +(6,4)-(6,13) parse warning Exceptions must be defined at module level, not inside types. +(6,4)-(6,13) parse error Unexpected keyword 'exception' in member definition diff --git a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs new file mode 100644 index 00000000000..1ec3319af1c --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs @@ -0,0 +1,13 @@ +// Expected: Warning for module after inherit +module Module + +type Base() = + member _.BaseMethod() = 1 + +type Derived() = + inherit Base() + + module InvalidModule = + let x = 2 + + override _.ToString() = "Derived" diff --git a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..141c7eb8b3d --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl @@ -0,0 +1,107 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Inherit With Invalid Constructs 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 + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (4,9--4,11)), None, + PreXmlDoc ((4,9), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,9), { 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 + ([_; BaseMethod], [(5,12--5,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (5,23--5,25)), (5,23--5,25))], + None, (5,11--5,25)), None, + Const (Int32 1, (5,28--5,29)), (5,11--5,25), + NoneAtInvisible, + { LeadingKeyword = Member (5,4--5,10) + InlineKeyword = None + EqualsRange = Some (5,26--5,27) }), (5,4--5,29))], + (5,4--5,29)), [], + 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--5,29), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,12--4,13) + WithKeyword = None })], (4,0--5,29)); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [Derived], + PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (7,5--7,12)), + ObjectModel + (Unspecified, + [ImplicitCtor + (None, [], Const (Unit, (7,12--7,14)), None, + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + (7,5--7,12), { AsKeyword = None }); + ImplicitInherit + (LongIdent (SynLongIdent ([Base], [], [None])), + Const (Unit, (8,16--8,18)), None, (8,4--8,18), + { InheritKeyword = (8,4--8,11) })], (8,4--8,18)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (7,12--7,14)), None, + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + (7,5--7,12), { AsKeyword = None })), (7,5--8,18), + { LeadingKeyword = Type (7,0--7,4) + EqualsRange = Some (7,15--7,16) + WithKeyword = None })], (7,0--8,18)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (10,4--10,24)), 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 2, (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,25--10,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--11,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,45)] }, set [])) + +(10,4)-(10,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(13,4)-(13,12) parse error Unexpected keyword 'override' in definition. Expected incomplete structured construct at or before this point or other token. 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/Interleaved Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs new file mode 100644 index 00000000000..afbcaadb61f --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs @@ -0,0 +1,10 @@ +// Expected: Multiple warnings for module and exception +module Module + +type Interleaved() = + member _.X = 1 + module M1 = + let y = 2 + member _.Y = 2 + exception E1 of int + member _.Z = 3 diff --git a/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..25cafa653f4 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl @@ -0,0 +1,80 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Interleaved Invalid Constructs 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, + [ImplicitCtor + (None, [], Const (Unit, (4,16--4,18)), None, + PreXmlDoc ((4,16), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,16), { 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 + ([_; 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)), [], + 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--5,18), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,19--4,20) + 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,55)] }, set [])) + +(6,4)-(6,10) parse warning 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 warning Exceptions must be defined at module level, not inside types. 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..b455cda954e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs @@ -0,0 +1,12 @@ +// Expected: No warning - keywords in strings are not declarations +module Module + +type MyClass() = + let message = "This string contains type and module keywords" + let code = """ + type Example = int + module Sample = + let x = 1 + """ + member _.GetMessage() = message + member _.GetCode() = code 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..a8fef977486 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl @@ -0,0 +1,129 @@ +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, + [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 (message, None), false, None, + (5,8--5,15)), None, + Const + (String + ("This string contains type and module keywords", + Regular, (5,18--5,65)), (5,18--5,65)), + (5,8--5,15), Yes (5,4--5,65), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,16--5,17) })], false, false, + (5,4--5,65)); + LetBindings + ([SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (code, None), false, None, (6,8--6,12)), + None, + Const + (String + (" + type Example = int + module Sample = + let x = 1 + ", + TripleQuote, (6,15--10,7)), (6,15--10,7)), + (6,8--6,12), Yes (6,4--10,7), + { LeadingKeyword = Let (6,4--6,7) + InlineKeyword = None + EqualsRange = Some (6,13--6,14) })], false, false, + (6,4--10,7)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((11,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], [(11,12--11,13)], + [None; None]), None, None, + Pats + [Paren + (Const (Unit, (11,23--11,25)), + (11,23--11,25))], None, (11,11--11,25)), + None, Ident message, (11,11--11,25), NoneAtInvisible, + { LeadingKeyword = Member (11,4--11,10) + InlineKeyword = None + EqualsRange = Some (11,26--11,27) }), + (11,4--11,35)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((12,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 + ([_; GetCode], [(12,12--12,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (12,20--12,22)), + (12,20--12,22))], None, (12,11--12,22)), + None, Ident code, (12,11--12,22), NoneAtInvisible, + { LeadingKeyword = Member (12,4--12,10) + InlineKeyword = None + EqualsRange = Some (12,23--12,24) }), + (12,4--12,29))], (5,4--12,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--12,29), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,15--4,16) + WithKeyword = None })], (4,0--12,29))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--12,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,66)] }, 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..b26f9f3a2ac --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs @@ -0,0 +1,9 @@ +// Expected: No warning - let bindings are valid in classes +module Module + +type MyClass() = + let mutable privateField = 10 + let helper x = x * 2 + + member _.GetValue() = helper privateField + member _.SetValue(v) = privateField <- v 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..0cd0d4ff6c3 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl @@ -0,0 +1,140 @@ +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, true, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (privateField, None), false, None, + (5,16--5,28)), None, + Const (Int32 10, (5,31--5,33)), (5,16--5,28), + Yes (5,4--5,33), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,29--5,30) })], false, false, + (5,4--5,33)); + LetBindings + ([SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo + ([[SynArgInfo ([], false, Some x)]], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent ([helper], [], [None]), None, None, + Pats + [Named + (SynIdent (x, None), false, None, + (6,15--6,16))], None, (6,8--6,16)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,21--6,22)), Ident x, (6,19--6,22)), + Const (Int32 2, (6,23--6,24)), (6,19--6,24)), + (6,8--6,16), NoneAtLet, + { LeadingKeyword = Let (6,4--6,7) + InlineKeyword = None + EqualsRange = Some (6,17--6,18) })], false, false, + (6,4--6,24)); + 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 + ([_; GetValue], [(8,12--8,13)], [None; None]), + None, None, + Pats + [Paren + (Const (Unit, (8,21--8,23)), (8,21--8,23))], + None, (8,11--8,23)), None, + App + (NonAtomic, false, Ident helper, + Ident privateField, (8,26--8,45)), (8,11--8,23), + NoneAtInvisible, + { LeadingKeyword = Member (8,4--8,10) + InlineKeyword = None + EqualsRange = Some (8,24--8,25) }), (8,4--8,45)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((9,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, Some v)]], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent + ([_; SetValue], [(9,12--9,13)], [None; None]), + None, None, + Pats + [Paren + (Named + (SynIdent (v, None), false, None, + (9,22--9,23)), (9,21--9,24))], None, + (9,11--9,24)), None, + LongIdentSet + (SynLongIdent ([privateField], [], [None]), + Ident v, (9,27--9,44)), (9,11--9,24), + NoneAtInvisible, + { LeadingKeyword = Member (9,4--9,10) + InlineKeyword = None + EqualsRange = Some (9,25--9,26) }), (9,4--9,44))], + (5,4--9,44)), [], + 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--9,44), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,15--4,16) + WithKeyword = None })], (4,0--9,44))], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--9,44), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,59)] }, 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..74763193124 --- /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 warning 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..357b832ef8c --- /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 warning Modules cannot be nested inside types. Define modules 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 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 Type Defn 02.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl similarity index 50% rename from tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl rename to tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl index 911c768aad4..f8dd4eba902 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl @@ -1,25 +1,25 @@ ImplFile (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 02.fs", false, - QualifiedNameOfFile Module, [], + ("/root/Type/Module Inside Class 01.fs", false, QualifiedNameOfFile Module, + [], [SynModuleOrNamespace ([Module], false, NamedModule, [Types ([SynTypeDefn (SynComponentInfo ([], None, [], [C], - PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (3,5--3,6)), + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), ObjectModel (Unspecified, [ImplicitCtor - (None, [], Const (Unit, (3,7--3,9)), None, - PreXmlDoc ((3,7), FSharp.Compiler.Xml.XmlDocCollector), - (3,5--3,6), { AsKeyword = None }); + (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 ((4,4), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), SynValData (Some { IsInstance = true IsDispatchSlot = false @@ -32,53 +32,53 @@ ImplFile SynArgInfo ([], false, None)), None), LongIdent (SynLongIdent - ([_; F], [(4,12--4,13)], [None; None]), None, + ([_; F], [(5,12--5,13)], [None; None]), None, None, Pats [Paren - (Const (Unit, (4,15--4,17)), (4,15--4,17))], - None, (4,11--4,17)), None, - Const (Int32 3, (4,20--4,21)), (4,11--4,17), + (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 (4,4--4,10) + { LeadingKeyword = Member (5,4--5,10) InlineKeyword = None - EqualsRange = Some (4,18--4,19) }), (4,4--4,21))], - (4,4--4,21)), [], + EqualsRange = Some (5,18--5,19) }), (5,4--5,21))], + (5,4--5,21)), [], Some (ImplicitCtor - (None, [], Const (Unit, (3,7--3,9)), None, - PreXmlDoc ((3,7), FSharp.Compiler.Xml.XmlDocCollector), - (3,5--3,6), { AsKeyword = None })), (3,5--4,21), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,10--3,11) - WithKeyword = None })], (3,0--4,21)); + (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 ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (5,4--5,13)), false, + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,13)), false, [Let (false, [SynBinding (None, Normal, false, false, [], - PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), SynValData (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), LongIdent (SynLongIdent ([f], [], [None]), None, None, - Pats [Paren (Const (Unit, (6,14--6,16)), (6,14--6,16))], - None, (6,12--6,16)), None, Const (Unit, (6,19--6,21)), - (6,12--6,16), NoneAtLet, - { LeadingKeyword = Let (6,8--6,11) + 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 (6,17--6,18) })], (6,8--6,21))], - false, (5,4--6,21), { ModuleKeyword = Some (5,4--5,10) - EqualsRange = Some (5,14--5,15) })], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--6,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + 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 = [] }, set [])) + CodeComments = [LineComment (1,0--1,44)] }, set [])) -(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(6,4)-(6,10) parse warning 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..ec2476b7c00 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs @@ -0,0 +1,8 @@ +// Expected: Warning for module inside class with constructor +module Module + +type MyClass(x: int) = + let mutable value = x + member _.Value = value + 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..f93fdf33ee0 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs.bsl @@ -0,0 +1,107 @@ +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 }); + LetBindings + ([SynBinding + (None, Normal, false, true, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (value, None), false, None, + (5,16--5,21)), None, Ident x, (5,16--5,21), + Yes (5,4--5,25), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,22--5,23) })], 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 + ([_; Value], [(6,12--6,13)], [None; None]), + None, None, Pats [], None, (6,11--6,18)), None, + Ident value, (6,11--6,18), NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = Some (6,19--6,20) }), (6,4--6,26))], + (5,4--6,26)), [], + 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--6,26), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,21--4,22) + WithKeyword = None })], (4,0--6,26)); + NestedModule + (SynComponentInfo + ([], None, [], [InternalModule], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,25)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + None), + LongIdent + (SynLongIdent ([helper], [], [None]), None, None, + Pats [Paren (Const (Unit, (8,18--8,20)), (8,18--8,20))], + None, (8,12--8,20)), None, + Const (Int32 42, (8,23--8,25)), (8,12--8,20), NoneAtLet, + { LeadingKeyword = Let (8,8--8,11) + InlineKeyword = None + EqualsRange = Some (8,21--8,22) })], (8,8--8,25))], + false, (7,4--8,25), { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,26--7,27) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--8,25), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,61)] }, set [])) + +(7,4)-(7,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. 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..f9c8eacae01 --- /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 warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs similarity index 50% rename from tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs rename to tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs index 29bf10b74e5..a4898ae9e5a 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs @@ -1,6 +1,7 @@ +// Expected: Warning for module inside interface module Module type IFace = abstract F : int -> int module M = - let f () = () \ No newline at end of file + let f () = () diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl similarity index 55% rename from tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl rename to tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl index 03090b1784a..118f69a180e 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl @@ -1,6 +1,6 @@ ImplFile (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 01.fs", false, + ("/root/Type/Module Inside Interface 01.fs", false, QualifiedNameOfFile Module, [], [SynModuleOrNamespace ([Module], false, NamedModule, @@ -8,8 +8,8 @@ ImplFile ([SynTypeDefn (SynComponentInfo ([], None, [], [IFace], - PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (3,5--3,10)), + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,10)), ObjectModel (Unspecified, [AbstractSlot @@ -19,13 +19,13 @@ ImplFile Fun (LongIdent (SynLongIdent ([int], [], [None])), LongIdent (SynLongIdent ([int], [], [None])), - (4,17--4,27), { ArrowRange = (4,21--4,23) }), + (5,17--5,27), { ArrowRange = (5,21--5,23) }), SynValInfo ([[SynArgInfo ([], false, None)]], SynArgInfo ([], false, None)), false, false, - PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector), - Single None, None, (4,4--4,27), - { LeadingKeyword = Abstract (4,4--4,12) + 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 }), @@ -34,38 +34,38 @@ ImplFile IsOverrideOrExplicitImpl = false IsFinal = false GetterOrSetterIsCompilerGenerated = false - MemberKind = Member }, (4,4--4,27), - { GetSetKeywords = None })], (4,4--4,27)), [], None, - (3,5--4,27), { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,11--3,12) - WithKeyword = None })], (3,0--4,27)); + 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 ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (5,4--5,12)), false, + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (6,4--6,12)), false, [Let (false, [SynBinding (None, Normal, false, false, [], - PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), SynValData (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), LongIdent (SynLongIdent ([f], [], [None]), None, None, - Pats [Paren (Const (Unit, (6,14--6,16)), (6,14--6,16))], - None, (6,12--6,16)), None, Const (Unit, (6,19--6,21)), - (6,12--6,16), NoneAtLet, - { LeadingKeyword = Let (6,8--6,11) + 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 (6,17--6,18) })], (6,8--6,21))], - false, (5,4--6,21), { ModuleKeyword = Some (5,4--5,10) - EqualsRange = Some (5,13--5,14) })], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--6,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + 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 = [] }, set [])) + CodeComments = [LineComment (1,0--1,48)] }, set [])) -(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs similarity index 63% rename from tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs rename to tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs index 4c2b52f49a1..6a8edb2f309 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs @@ -1,3 +1,4 @@ +// Expected: Warning for module inside interface...end block module Module type IFace = @@ -5,4 +6,4 @@ type IFace = abstract F : int -> int module M = let f () = f () - end \ No newline at end of file + end diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs.bsl similarity index 57% rename from tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl rename to tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs.bsl index 084728abb29..8bcf248f981 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 05.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface End 01.fs.bsl @@ -1,6 +1,6 @@ ImplFile (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 05.fs", false, + ("/root/Type/Module Inside Interface End 01.fs", false, QualifiedNameOfFile Module, [], [SynModuleOrNamespace ([Module], false, NamedModule, @@ -8,8 +8,8 @@ ImplFile ([SynTypeDefn (SynComponentInfo ([], None, [], [IFace], - PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (3,5--3,10)), + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,10)), ObjectModel (Interface, [AbstractSlot @@ -19,13 +19,13 @@ ImplFile Fun (LongIdent (SynLongIdent ([int], [], [None])), LongIdent (SynLongIdent ([int], [], [None])), - (5,21--5,31), { ArrowRange = (5,25--5,27) }), + (6,21--6,31), { ArrowRange = (6,25--6,27) }), SynValInfo ([[SynArgInfo ([], false, None)]], SynArgInfo ([], false, None)), false, false, - PreXmlDoc ((5,8), FSharp.Compiler.Xml.XmlDocCollector), - Single None, None, (5,8--5,31), - { LeadingKeyword = Abstract (5,8--5,16) + 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 }), @@ -34,17 +34,17 @@ ImplFile IsOverrideOrExplicitImpl = false IsFinal = false GetterOrSetterIsCompilerGenerated = false - MemberKind = Member }, (5,8--5,31), - { GetSetKeywords = None })], (4,4--5,31)), [], None, - (3,5--5,31), { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,11--3,12) - WithKeyword = None })], (3,0--5,31))], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--5,31), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + 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 = [] }, set [])) + CodeComments = [LineComment (1,0--1,60)] }, set [])) -(4,4)-(4,13) 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. +(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..71512a17a5b --- /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 warning 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 Type Defn 03.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl similarity index 57% rename from tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl rename to tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl index 1a3ec1aba13..fdf9d50e8d9 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl @@ -1,33 +1,31 @@ ImplFile (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 03.fs", false, - QualifiedNameOfFile Module, [], + ("/root/Type/Module Inside Record 01.fs", false, QualifiedNameOfFile Module, + [], [SynModuleOrNamespace ([Module], false, NamedModule, [Types ([SynTypeDefn (SynComponentInfo - ([], None, [], [U], - PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (3,5--3,6)), + ([], None, [], [R], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (4,5--4,6)), Simple - (Union + (Record (None, - [SynUnionCase - ([], SynIdent (A, None), Fields [], - PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (4,6--4,7), { BarRange = Some (4,4--4,5) }); - SynUnionCase - ([], SynIdent (B, None), Fields [], - PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (5,6--5,7), { BarRange = Some (5,4--5,5) })], - (4,4--5,7)), (4,4--5,7)), [], None, (3,5--5,7), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--5,7)); + [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, [], [M3], + ([], None, [], [M4], PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), false, None, (6,4--6,13)), false, [Let @@ -48,10 +46,10 @@ ImplFile 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 ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--7,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--7,21), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [] }, set [])) + CodeComments = [LineComment (1,0--1,45)] }, set [])) (6,4)-(6,10) parse warning 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..6d15ab44043 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs @@ -0,0 +1,9 @@ +// Expected: Warning for module inside struct +module Module + +[] +type MyStruct = + val X: int + val Y: int + module InvalidModule = + let helper = 10 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..1571f2ce4bf --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl @@ -0,0 +1,68 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Module Inside Struct 01.fs", false, QualifiedNameOfFile Module, + [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([{ Attributes = + [{ TypeName = SynLongIdent ([Struct], [], [None]) + ArgExpr = Const (Unit, (4,2--4,8)) + Target = None + AppliesToGetterAndSetter = false + Range = (4,2--4,8) }] + Range = (4,0--4,10) }], None, [], [MyStruct], + PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,5--5,13)), + ObjectModel + (Unspecified, + [ValField + (SynField + ([], false, Some X, + LongIdent (SynLongIdent ([int], [], [None])), false, + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (6,4--6,14), + { LeadingKeyword = Some (Val (6,4--6,7)) + MutableKeyword = None }), (6,4--6,14)); + ValField + (SynField + ([], false, Some Y, + LongIdent (SynLongIdent ([int], [], [None])), false, + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (7,4--7,14), + { LeadingKeyword = Some (Val (7,4--7,7)) + MutableKeyword = None }), (7,4--7,14))], + (6,4--7,14)), [], None, (4,0--7,14), + { LeadingKeyword = Type (5,0--5,4) + EqualsRange = Some (5,14--5,15) + WithKeyword = None })], (4,0--7,14)); + 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 warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs deleted file mode 100644 index d063e1a1aff..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 02.fs +++ /dev/null @@ -1,6 +0,0 @@ -module Module - -type C () = - member _.F () = 3 - module M2 = - let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs deleted file mode 100644 index 3e63110f83a..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 03.fs +++ /dev/null @@ -1,7 +0,0 @@ -module Module - -type U = - | A - | B - module M3 = - let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs deleted file mode 100644 index aa286f18512..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs +++ /dev/null @@ -1,6 +0,0 @@ -module Module - -type R = - { A : int } - module M4 = - let f () = () \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl deleted file mode 100644 index b3035248bd3..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 04.fs.bsl +++ /dev/null @@ -1,55 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 04.fs", false, - QualifiedNameOfFile Module, [], - [SynModuleOrNamespace - ([Module], false, NamedModule, - [Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [R], - PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (3,5--3,6)), - Simple - (Record - (None, - [SynField - ([], false, Some A, - LongIdent (SynLongIdent ([int], [], [None])), false, - PreXmlDoc ((4,6), FSharp.Compiler.Xml.XmlDocCollector), - None, (4,6--4,13), { LeadingKeyword = None - MutableKeyword = None })], - (4,4--4,15)), (4,4--4,15)), [], None, (3,5--4,15), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--4,15)); - NestedModule - (SynComponentInfo - ([], None, [], [M4], - PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (5,4--5,13)), false, - [Let - (false, - [SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, SynValInfo ([[]], SynArgInfo ([], false, None)), - None), - LongIdent - (SynLongIdent ([f], [], [None]), None, None, - Pats [Paren (Const (Unit, (6,14--6,16)), (6,14--6,16))], - None, (6,12--6,16)), None, Const (Unit, (6,19--6,21)), - (6,12--6,16), NoneAtLet, - { LeadingKeyword = Let (6,8--6,11) - InlineKeyword = None - EqualsRange = Some (6,17--6,18) })], (6,8--6,21))], - false, (5,4--6,21), { ModuleKeyword = Some (5,4--5,10) - EqualsRange = Some (5,14--5,15) })], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--6,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [] }, set [])) - -(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs deleted file mode 100644 index 4706f19608e..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs +++ /dev/null @@ -1,11 +0,0 @@ -module Module - -type A = A - -type B = - | B - module M1 = begin end - module M2 = begin end - module M3 = begin end - -type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl deleted file mode 100644 index e4628796124..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 06.fs.bsl +++ /dev/null @@ -1,79 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 06.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 - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--3,10)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [B], - PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,5--5,6)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (B, None), Fields [], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], - (6,4--6,7)), (6,4--6,7)), [], None, (5,5--6,7), - { LeadingKeyword = Type (5,0--5,4) - EqualsRange = Some (5,7--5,8) - WithKeyword = None })], (5,0--6,7)); - NestedModule - (SynComponentInfo - ([], None, [], [M1], - PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,4--7,13)), false, [], false, (7,4--7,25), - { ModuleKeyword = Some (7,4--7,10) - EqualsRange = Some (7,14--7,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M2], - PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (8,4--8,13)), false, [], false, (8,4--8,25), - { ModuleKeyword = Some (8,4--8,10) - EqualsRange = Some (8,14--8,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M3], - PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (9,4--9,13)), false, [], false, (9,4--9,25), - { ModuleKeyword = Some (9,4--9,10) - EqualsRange = Some (9,14--9,15) }); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [C], - PreXmlDoc ((11,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (11,5--11,6)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([C], [], [None])), - (11,9--11,10)), (11,9--11,10)), [], None, (11,5--11,10), - { LeadingKeyword = Type (11,0--11,4) - EqualsRange = Some (11,7--11,8) - WithKeyword = None })], (11,0--11,10))], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--11,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [] }, set [])) - -(7,4)-(7,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(9,4)-(9,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs deleted file mode 100644 index dd101d44c44..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs +++ /dev/null @@ -1,15 +0,0 @@ -module Module - -type A = A - -module M1 = begin end -module M2 = begin end -module M3 = begin end - -type B = - | B - module M4 = begin end - module M5 = begin end - module M6 = begin end - -type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl deleted file mode 100644 index 3f261790070..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 07.fs.bsl +++ /dev/null @@ -1,100 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 07.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 - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--3,10)); - NestedModule - (SynComponentInfo - ([], None, [], [M1], - PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (5,0--5,9)), false, [], false, (5,0--5,21), - { ModuleKeyword = Some (5,0--5,6) - EqualsRange = Some (5,10--5,11) }); - NestedModule - (SynComponentInfo - ([], None, [], [M2], - PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (6,0--6,9)), false, [], false, (6,0--6,21), - { ModuleKeyword = Some (6,0--6,6) - EqualsRange = Some (6,10--6,11) }); - NestedModule - (SynComponentInfo - ([], None, [], [M3], - PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,0--7,9)), false, [], false, (7,0--7,21), - { ModuleKeyword = Some (7,0--7,6) - EqualsRange = Some (7,10--7,11) }); - 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)); - NestedModule - (SynComponentInfo - ([], None, [], [M4], - PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (11,4--11,13)), false, [], false, (11,4--11,25), - { ModuleKeyword = Some (11,4--11,10) - EqualsRange = Some (11,14--11,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M5], - PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (12,4--12,13)), false, [], false, (12,4--12,25), - { ModuleKeyword = Some (12,4--12,10) - EqualsRange = Some (12,14--12,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M6], - PreXmlDoc ((13,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (13,4--13,13)), false, [], false, (13,4--13,25), - { ModuleKeyword = Some (13,4--13,10) - EqualsRange = Some (13,14--13,15) }); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [C], - PreXmlDoc ((15,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (15,5--15,6)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([C], [], [None])), - (15,9--15,10)), (15,9--15,10)), [], None, (15,5--15,10), - { LeadingKeyword = Type (15,0--15,4) - EqualsRange = Some (15,7--15,8) - WithKeyword = None })], (15,0--15,10))], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--15,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [] }, set [])) - -(11,4)-(11,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(12,4)-(12,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(13,4)-(13,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs deleted file mode 100644 index b28f2d2585d..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs +++ /dev/null @@ -1,16 +0,0 @@ -module Module - -type A = A - -module M1 = begin end -module M2 = begin end -module M3 = begin end - -type B = - | B - with - module M4 = begin end - module M5 = begin end - module M6 = begin end - -type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl deleted file mode 100644 index f9d930d88bd..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 08.fs.bsl +++ /dev/null @@ -1,68 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 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 - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--3,10)); - NestedModule - (SynComponentInfo - ([], None, [], [M1], - PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (5,0--5,9)), false, [], false, (5,0--5,21), - { ModuleKeyword = Some (5,0--5,6) - EqualsRange = Some (5,10--5,11) }); - NestedModule - (SynComponentInfo - ([], None, [], [M2], - PreXmlDoc ((6,0), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (6,0--6,9)), false, [], false, (6,0--6,21), - { ModuleKeyword = Some (6,0--6,6) - EqualsRange = Some (6,10--6,11) }); - NestedModule - (SynComponentInfo - ([], None, [], [M3], - PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,0--7,9)), false, [], false, (7,0--7,21), - { ModuleKeyword = Some (7,0--7,6) - EqualsRange = Some (7,10--7,11) }); - 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 = Some (11,4--11,8) })], (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 [])) - -(12,8)-(12,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(12,8)-(12,14) parse error Unexpected keyword 'module' in type definition. Expected incomplete structured construct at or before this point, 'end' or other token. -(13,8)-(13,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(13,8)-(13,14) parse error Unexpected keyword 'module' in implementation file -(14,8)-(14,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs deleted file mode 100644 index 064e08df649..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs +++ /dev/null @@ -1,14 +0,0 @@ -module Module - -type A = A - -type B = - | B - member this.M1 = 1 - member this.M2 = 2 - member this.M3 = 3 - module M1 = begin end - module M2 = begin end - module M3 = begin end - -type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl deleted file mode 100644 index 73bbea49267..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 09.fs.bsl +++ /dev/null @@ -1,148 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 09.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 - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--3,10)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [B], - PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,5--5,6)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (B, None), Fields [], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], - (6,4--6,7)), (6,4--6,7)), - [Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((7,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 - ([this; M1], [(7,15--7,16)], [None; None]), None, - None, Pats [], None, (7,11--7,18)), None, - Const (Int32 1, (7,21--7,22)), (7,11--7,18), - NoneAtInvisible, { LeadingKeyword = Member (7,4--7,10) - InlineKeyword = None - EqualsRange = Some (7,19--7,20) }), - (7,4--7,22)); - 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 - ([this; M2], [(8,15--8,16)], [None; None]), None, - None, Pats [], None, (8,11--8,18)), None, - Const (Int32 2, (8,21--8,22)), (8,11--8,18), - NoneAtInvisible, { LeadingKeyword = Member (8,4--8,10) - InlineKeyword = None - EqualsRange = Some (8,19--8,20) }), - (8,4--8,22)); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((9,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 - ([this; M3], [(9,15--9,16)], [None; None]), None, - None, Pats [], None, (9,11--9,18)), None, - Const (Int32 3, (9,21--9,22)), (9,11--9,18), - NoneAtInvisible, { LeadingKeyword = Member (9,4--9,10) - InlineKeyword = None - EqualsRange = Some (9,19--9,20) }), - (9,4--9,22))], None, (5,5--9,22), - { LeadingKeyword = Type (5,0--5,4) - EqualsRange = Some (5,7--5,8) - WithKeyword = None })], (5,0--9,22)); - NestedModule - (SynComponentInfo - ([], None, [], [M1], - PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (10,4--10,13)), false, [], false, (10,4--10,25), - { ModuleKeyword = Some (10,4--10,10) - EqualsRange = Some (10,14--10,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M2], - PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (11,4--11,13)), false, [], false, (11,4--11,25), - { ModuleKeyword = Some (11,4--11,10) - EqualsRange = Some (11,14--11,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M3], - PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (12,4--12,13)), false, [], false, (12,4--12,25), - { ModuleKeyword = Some (12,4--12,10) - EqualsRange = Some (12,14--12,15) }); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [C], - PreXmlDoc ((14,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (14,5--14,6)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([C], [], [None])), - (14,9--14,10)), (14,9--14,10)), [], None, (14,5--14,10), - { LeadingKeyword = Type (14,0--14,4) - EqualsRange = Some (14,7--14,8) - WithKeyword = None })], (14,0--14,10))], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--14,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [] }, set [])) - -(10,4)-(10,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(11,4)-(11,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(12,4)-(12,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs deleted file mode 100644 index 989dc7dade3..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs +++ /dev/null @@ -1,17 +0,0 @@ -module Module - -type A = A - -type B = - | B - member this.M1 = 1 - member this.M2 = 2 - member this.M3 = 3 - module M1 = begin end - module M2 = begin end - module M3 = begin end - type M4() = class end - type M5() = class end - type M6() = class end - -type C = C \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl deleted file mode 100644 index 2af73d14f3b..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 10.fs.bsl +++ /dev/null @@ -1,214 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 10.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 - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (3,9--3,10)), (3,9--3,10)), [], None, (3,5--3,10), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,7--3,8) - WithKeyword = None })], (3,0--3,10)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [B], - PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,5--5,6)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (B, None), Fields [], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (6,6--6,7), { BarRange = Some (6,4--6,5) })], - (6,4--6,7)), (6,4--6,7)), - [Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((7,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 - ([this; M1], [(7,15--7,16)], [None; None]), None, - None, Pats [], None, (7,11--7,18)), None, - Const (Int32 1, (7,21--7,22)), (7,11--7,18), - NoneAtInvisible, { LeadingKeyword = Member (7,4--7,10) - InlineKeyword = None - EqualsRange = Some (7,19--7,20) }), - (7,4--7,22)); - 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 - ([this; M2], [(8,15--8,16)], [None; None]), None, - None, Pats [], None, (8,11--8,18)), None, - Const (Int32 2, (8,21--8,22)), (8,11--8,18), - NoneAtInvisible, { LeadingKeyword = Member (8,4--8,10) - InlineKeyword = None - EqualsRange = Some (8,19--8,20) }), - (8,4--8,22)); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((9,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 - ([this; M3], [(9,15--9,16)], [None; None]), None, - None, Pats [], None, (9,11--9,18)), None, - Const (Int32 3, (9,21--9,22)), (9,11--9,18), - NoneAtInvisible, { LeadingKeyword = Member (9,4--9,10) - InlineKeyword = None - EqualsRange = Some (9,19--9,20) }), - (9,4--9,22))], None, (5,5--9,22), - { LeadingKeyword = Type (5,0--5,4) - EqualsRange = Some (5,7--5,8) - WithKeyword = None })], (5,0--9,22)); - NestedModule - (SynComponentInfo - ([], None, [], [M1], - PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (10,4--10,13)), false, [], false, (10,4--10,25), - { ModuleKeyword = Some (10,4--10,10) - EqualsRange = Some (10,14--10,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M2], - PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (11,4--11,13)), false, [], false, (11,4--11,25), - { ModuleKeyword = Some (11,4--11,10) - EqualsRange = Some (11,14--11,15) }); - NestedModule - (SynComponentInfo - ([], None, [], [M3], - PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (12,4--12,13)), false, [], false, (12,4--12,25), - { ModuleKeyword = Some (12,4--12,10) - EqualsRange = Some (12,14--12,15) }); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [M4], - PreXmlDoc ((13,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (13,9--13,11)), - ObjectModel - (Class, - [ImplicitCtor - (None, [], Const (Unit, (13,11--13,13)), None, - PreXmlDoc ((13,11), FSharp.Compiler.Xml.XmlDocCollector), - (13,9--13,11), { AsKeyword = None })], (13,16--13,25)), - [], - Some - (ImplicitCtor - (None, [], Const (Unit, (13,11--13,13)), None, - PreXmlDoc ((13,11), FSharp.Compiler.Xml.XmlDocCollector), - (13,9--13,11), { AsKeyword = None })), (13,9--13,25), - { LeadingKeyword = Type (13,4--13,8) - EqualsRange = Some (13,14--13,15) - WithKeyword = None })], (13,4--13,25)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [M5], - PreXmlDoc ((14,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (14,9--14,11)), - ObjectModel - (Class, - [ImplicitCtor - (None, [], Const (Unit, (14,11--14,13)), None, - PreXmlDoc ((14,11), FSharp.Compiler.Xml.XmlDocCollector), - (14,9--14,11), { AsKeyword = None })], (14,16--14,25)), - [], - Some - (ImplicitCtor - (None, [], Const (Unit, (14,11--14,13)), None, - PreXmlDoc ((14,11), FSharp.Compiler.Xml.XmlDocCollector), - (14,9--14,11), { AsKeyword = None })), (14,9--14,25), - { LeadingKeyword = Type (14,4--14,8) - EqualsRange = Some (14,14--14,15) - WithKeyword = None })], (14,4--14,25)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [M6], - PreXmlDoc ((15,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (15,9--15,11)), - ObjectModel - (Class, - [ImplicitCtor - (None, [], Const (Unit, (15,11--15,13)), None, - PreXmlDoc ((15,11), FSharp.Compiler.Xml.XmlDocCollector), - (15,9--15,11), { AsKeyword = None })], (15,16--15,25)), - [], - Some - (ImplicitCtor - (None, [], Const (Unit, (15,11--15,13)), None, - PreXmlDoc ((15,11), FSharp.Compiler.Xml.XmlDocCollector), - (15,9--15,11), { AsKeyword = None })), (15,9--15,25), - { LeadingKeyword = Type (15,4--15,8) - EqualsRange = Some (15,14--15,15) - WithKeyword = None })], (15,4--15,25)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [C], - PreXmlDoc ((17,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (17,5--17,6)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([C], [], [None])), - (17,9--17,10)), (17,9--17,10)), [], None, (17,5--17,10), - { LeadingKeyword = Type (17,0--17,4) - EqualsRange = Some (17,7--17,8) - WithKeyword = None })], (17,0--17,10))], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--17,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [] }, set [])) - -(10,4)-(10,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(11,4)-(11,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(12,4)-(12,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(13,4)-(13,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. -(14,4)-(14,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. -(15,4)-(15,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs deleted file mode 100644 index e7431a493ce..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs +++ /dev/null @@ -1,11 +0,0 @@ -module Module - -let x = 1 -type x_t = int -type t = - | X of int - module Nested = begin - let x = 1 - type x_t = int - type t = X of int - end \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl deleted file mode 100644 index 90dddf258a9..00000000000 --- a/tests/service/data/SyntaxTree/Type/Module Inside Type Defn 11.fs.bsl +++ /dev/null @@ -1,123 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Module Inside Type Defn 11.fs", false, - QualifiedNameOfFile Module, [], - [SynModuleOrNamespace - ([Module], false, NamedModule, - [Let - (false, - [SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, SynValInfo ([], SynArgInfo ([], false, None)), None), - Named (SynIdent (x, None), false, None, (3,4--3,5)), None, - Const (Int32 1, (3,8--3,9)), (3,4--3,5), Yes (3,0--3,9), - { LeadingKeyword = Let (3,0--3,3) - InlineKeyword = None - EqualsRange = Some (3,6--3,7) })], (3,0--3,9)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [x_t], - PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (4,5--4,8)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([int], [], [None])), - (4,11--4,14)), (4,11--4,14)), [], None, (4,5--4,14), - { LeadingKeyword = Type (4,0--4,4) - EqualsRange = Some (4,9--4,10) - WithKeyword = None })], (4,0--4,14)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [t], - PreXmlDoc ((5,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,5--5,6)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (X, None), - Fields - [SynField - ([], false, None, - LongIdent (SynLongIdent ([int], [], [None])), - false, - PreXmlDoc ((6,9), FSharp.Compiler.Xml.XmlDocCollector), - None, (6,9--6,12), { LeadingKeyword = None - MutableKeyword = None })], - PreXmlDoc ((6,2), FSharp.Compiler.Xml.XmlDocCollector), - None, (6,4--6,12), { BarRange = Some (6,2--6,3) })], - (6,2--6,12)), (6,2--6,12)), [], None, (5,5--6,12), - { LeadingKeyword = Type (5,0--5,4) - EqualsRange = Some (5,7--5,8) - WithKeyword = None })], (5,0--6,12)); - NestedModule - (SynComponentInfo - ([], None, [], [Nested], - PreXmlDoc ((7,2), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,2--7,15)), 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)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [x_t], - PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (9,9--9,12)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([int], [], [None])), - (9,15--9,18)), (9,15--9,18)), [], None, (9,9--9,18), - { LeadingKeyword = Type (9,4--9,8) - EqualsRange = Some (9,13--9,14) - WithKeyword = None })], (9,4--9,18)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [t], - PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (10,9--10,10)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (X, None), - Fields - [SynField - ([], false, None, - LongIdent - (SynLongIdent ([int], [], [None])), - false, - PreXmlDoc ((10,18), FSharp.Compiler.Xml.XmlDocCollector), - None, (10,18--10,21), - { LeadingKeyword = None - MutableKeyword = None })], - PreXmlDoc ((10,13), FSharp.Compiler.Xml.XmlDocCollector), - None, (10,13--10,21), { BarRange = None })], - (10,13--10,21)), (10,13--10,21)), [], None, - (10,9--10,21), { LeadingKeyword = Type (10,4--10,8) - EqualsRange = Some (10,11--10,12) - WithKeyword = None })], (10,4--10,21))], - false, (7,2--11,5), { ModuleKeyword = Some (7,2--7,8) - EqualsRange = Some (7,16--7,17) })], - PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (1,0--11,5), { LeadingKeyword = Module (1,0--1,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [] }, set [])) - -(7,2)-(7,8) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. 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..e185d90c8dd --- /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 warning 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..36017fb7c48 --- /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 warning 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 Constructors With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs new file mode 100644 index 00000000000..2ea7fba463e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs @@ -0,0 +1,14 @@ +// Expected: Warning for module between constructors +module Module + +type MyClass(primary: int) = + let mutable value = primary + + new() = MyClass(0) + + module InvalidModule = + let x = 1 + + new(s: string) = MyClass(int s) + + member _.Value = value diff --git a/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..5890db5c7df --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl @@ -0,0 +1,114 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Multiple Constructors With Invalid Constructs 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 (primary, None), false, None, + (4,13--4,20)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,13--4,25)), (4,12--4,26)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None }); + LetBindings + ([SynBinding + (None, Normal, false, true, [], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo ([], SynArgInfo ([], false, None)), + None), + Named + (SynIdent (value, None), false, None, + (5,16--5,21)), None, Ident primary, (5,16--5,21), + Yes (5,4--5,31), + { LeadingKeyword = Let (5,4--5,7) + InlineKeyword = None + EqualsRange = Some (5,22--5,23) })], false, false, + (5,4--5,31)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((7,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, (7,7--7,9)), (7,7--7,9))], + None, (7,4--7,7)), None, + App + (Atomic, false, Ident MyClass, + Paren + (Const (Int32 0, (7,20--7,21)), (7,19--7,20), + Some (7,21--7,22), (7,19--7,22)), (7,12--7,22)), + (7,4--7,9), NoneAtInvisible, + { LeadingKeyword = New (7,4--7,7) + InlineKeyword = None + EqualsRange = Some (7,10--7,11) }), (7,4--7,22))], + (5,4--7,22)), [], + Some + (ImplicitCtor + (None, [], + Paren + (Typed + (Named + (SynIdent (primary, None), false, None, + (4,13--4,20)), + LongIdent (SynLongIdent ([int], [], [None])), + (4,13--4,25)), (4,12--4,26)), None, + PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,12), { AsKeyword = None })), (4,5--7,22), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,27--4,28) + WithKeyword = None })], (4,0--7,22)); + 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 1, (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,52)] }, set [])) + +(9,4)-(9,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(12,4)-(12,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/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..b9710df359f --- /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 warning Modules cannot be nested inside types. Define modules at module or namespace level. +(8,4)-(8,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(9,4)-(9,13) parse warning Exceptions must be defined at module level, not inside types. +(10,4)-(10,8) parse warning '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..75cba2f0d9e --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs @@ -0,0 +1,17 @@ +// Expected: Warning for module inside type at deep nesting level +module Root + +module Level1 = + type ValidType1 = int + + module Level2 = + type ValidType2 = string + + module Level3 = + type TypeWithInvalidModule = + | A + | B + module InvalidModule = + let x = 1 + + type ValidType3 = float 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..2834e6253cc --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl @@ -0,0 +1,126 @@ +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, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [ValidType1], + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,9--5,19)), + Simple + (TypeAbbrev + (Ok, LongIdent (SynLongIdent ([int], [], [None])), + (5,22--5,25)), (5,22--5,25)), [], None, (5,9--5,25), + { LeadingKeyword = Type (5,4--5,8) + EqualsRange = Some (5,20--5,21) + WithKeyword = None })], (5,4--5,25)); + NestedModule + (SynComponentInfo + ([], None, [], [Level2], + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (7,4--7,17)), false, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [ValidType2], + PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,13--8,23)), + Simple + (TypeAbbrev + (Ok, + LongIdent (SynLongIdent ([string], [], [None])), + (8,26--8,32)), (8,26--8,32)), [], None, + (8,13--8,32), { LeadingKeyword = Type (8,8--8,12) + EqualsRange = Some (8,24--8,25) + WithKeyword = None })], (8,8--8,32)); + NestedModule + (SynComponentInfo + ([], None, [], [Level3], + PreXmlDoc ((10,8), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (10,8--10,21)), false, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [TypeWithInvalidModule], + PreXmlDoc ((11,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (11,17--11,38)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((12,16), FSharp.Compiler.Xml.XmlDocCollector), + None, (12,18--12,19), + { BarRange = Some (12,16--12,17) }); + SynUnionCase + ([], SynIdent (B, None), Fields [], + PreXmlDoc ((13,16), FSharp.Compiler.Xml.XmlDocCollector), + None, (13,18--13,19), + { BarRange = Some (13,16--13,17) })], + (12,16--13,19)), (12,16--13,19)), [], None, + (11,17--13,19), + { LeadingKeyword = Type (11,12--11,16) + EqualsRange = Some (11,39--11,40) + WithKeyword = None })], (11,12--13,19)); + NestedModule + (SynComponentInfo + ([], None, [], [InvalidModule], + PreXmlDoc ((14,16), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (14,16--14,36)), false, + [Let + (false, + [SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((15,20), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (None, + SynValInfo + ([], SynArgInfo ([], false, None)), None), + Named + (SynIdent (x, None), false, None, + (15,24--15,25)), None, + Const (Int32 1, (15,28--15,29)), + (15,24--15,25), Yes (15,20--15,29), + { LeadingKeyword = Let (15,20--15,23) + InlineKeyword = None + EqualsRange = Some (15,26--15,27) })], + (15,20--15,29))], false, (14,16--15,29), + { ModuleKeyword = Some (14,16--14,22) + EqualsRange = Some (14,37--14,38) }); + Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [ValidType3], + PreXmlDoc ((17,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (17,17--17,27)), + Simple + (TypeAbbrev + (Ok, + LongIdent + (SynLongIdent ([float], [], [None])), + (17,30--17,35)), (17,30--17,35)), [], None, + (17,17--17,35), + { LeadingKeyword = Type (17,12--17,16) + EqualsRange = Some (17,28--17,29) + WithKeyword = None })], (17,12--17,35))], false, + (10,8--17,35), { ModuleKeyword = Some (10,8--10,14) + EqualsRange = Some (10,22--10,23) })], + false, (7,4--17,35), { ModuleKeyword = Some (7,4--7,10) + EqualsRange = Some (7,18--7,19) })], + false, (4,0--17,35), { ModuleKeyword = Some (4,0--4,6) + EqualsRange = Some (4,14--4,15) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--17,35), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,65)] }, set [])) + +(14,16)-(14,22) parse warning Modules cannot be nested inside types. Define modules 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..9d13712f7e8 --- /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 warning '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..26331a23c04 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs @@ -0,0 +1,4 @@ +// Expected: May be valid F# - depends on implementation +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..6710749836d --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl @@ -0,0 +1,60 @@ +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,56)] }, set [])) + +(4,11)-(4,15) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(4,22)-(4,28) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs new file mode 100644 index 00000000000..2323679878b --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs @@ -0,0 +1,11 @@ +// Expected: Warning for module after static members +module Module + +type MyType() = + static member StaticMethod() = 42 + static member StaticProperty = "hello" + + module InvalidModule = + let x = 1 + + static member AnotherStatic() = true diff --git a/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl new file mode 100644 index 00000000000..5bafde22394 --- /dev/null +++ b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl @@ -0,0 +1,105 @@ +ImplFile + (ParsedImplFileInput + ("/root/Type/Static Members With Invalid Constructs 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, + [ImplicitCtor + (None, [], Const (Unit, (4,11--4,13)), None, + PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,11), { 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 = 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)); + Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,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 ([StaticProperty], [], [None]), None, + None, Pats [], None, (6,18--6,32)), None, + Const + (String ("hello", Regular, (6,35--6,42)), + (6,35--6,42)), (6,18--6,32), NoneAtInvisible, + { LeadingKeyword = + StaticMember ((6,4--6,10), (6,11--6,17)) + InlineKeyword = None + EqualsRange = Some (6,33--6,34) }), (6,4--6,42))], + (5,4--6,42)), [], + Some + (ImplicitCtor + (None, [], Const (Unit, (4,11--4,13)), None, + PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), + (4,5--4,11), { AsKeyword = None })), (4,5--6,42), + { LeadingKeyword = Type (4,0--4,4) + EqualsRange = Some (4,14--4,15) + WithKeyword = None })], (4,0--6,42)); + 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 (x, None), false, None, (9,12--9,13)), + None, Const (Int32 1, (9,16--9,17)), (9,12--9,13), + Yes (9,8--9,17), { LeadingKeyword = Let (9,8--9,11) + InlineKeyword = None + EqualsRange = Some (9,14--9,15) })], + (9,8--9,17))], false, (8,4--9,17), + { ModuleKeyword = Some (8,4--8,10) + EqualsRange = Some (8,25--8,26) })], + PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (2,0--9,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [LineComment (1,0--1,52)] }, set [])) + +(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(11,4)-(11,10) parse error Unexpected keyword 'static' in definition. Expected incomplete structured construct at or before this point or other token. 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..7e8044d6964 --- /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 warning Nested type definitions are not allowed. Types must be defined at module or namespace level. From 3c00990e2d1c8718bafa44518d2f25219418b176 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 13 Aug 2025 20:25:27 +0100 Subject: [PATCH 22/36] No warning - all declarations at same indentation level --- src/Compiler/SyntaxTree/LexFilter.fs | 25 +++++++++++-------- .../Type/Same Line Declarations 01.fs | 2 +- .../Type/Same Line Declarations 01.fs.bsl | 5 +--- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 722513ef2d8..a49d0677e8d 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1371,18 +1371,19 @@ type LexFilterImpl ( // 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. We traverse the context stack looking for a CtxtTypeDefns - // 2. If found, we check if the current token is indented inside it (column check) - // 3. We verify we're not in a legitimate nested context (members, augmentations, or escaped to module/namespace) - // 4. If all conditions match and the language feature is enabled, we issue a warning + // 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 a warning // // Note: We don't check 'let' bindings as they can be valid in classes with constructors - // Note: We skip validation inside parentheses to avoid false positives with inline IL syntax (# ... type ... #) + // Note: Constructs at the same column level are NOT nested (e.g., type A = A type B = B on same line) let checkIfInvalidConstructsInTypeDefinition keyword = // Only perform validation if the language feature is enabled - if not (lexbuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then - () - else + if lexbuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes 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 @@ -1394,6 +1395,7 @@ type LexFilterImpl ( // 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 | [] -> @@ -1407,7 +1409,10 @@ type LexFilterImpl ( | CtxtTypeDefns(typePos, _) :: rest -> // Found a type definition - check if we're inappropriately inside it - if tokenStartCol > typePos.Column then + // 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 = @@ -1422,7 +1427,7 @@ type LexFilterImpl ( not (isInMemberContext stack) else - // Not indented inside this type, check deeper in the stack + // Not indented inside this type (same column or less), check deeper in the stack checkNesting rest true | CtxtSeqBlock _ :: rest diff --git a/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs index 26331a23c04..f3f576f3e71 100644 --- a/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs +++ b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs @@ -1,4 +1,4 @@ -// Expected: May be valid F# - depends on implementation +// 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 index 6710749836d..81c58ccf689 100644 --- a/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Same Line Declarations 01.fs.bsl @@ -54,7 +54,4 @@ ImplFile (2,0--4,46), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,56)] }, set [])) - -(4,11)-(4,15) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. -(4,22)-(4,28) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. + CodeComments = [LineComment (1,0--1,68)] }, set [])) From cca0cc891c8fe135ea098d1a992cb70f24aa4ced Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Wed, 13 Aug 2025 21:14:55 +0100 Subject: [PATCH 23/36] Update FSComp.txt --- src/Compiler/FSComp.txt | 5 + src/Compiler/SyntaxTree/LexFilter.fs | 42 ++++--- src/Compiler/xlf/FSComp.txt.cs.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.de.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.es.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.it.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 25 ++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 25 ++++ .../SyntaxTree/Type/Code Quotations 01.fs | 18 --- .../SyntaxTree/Type/Code Quotations 01.fs.bsl | 108 ------------------ 17 files changed, 358 insertions(+), 140 deletions(-) delete mode 100644 tests/service/data/SyntaxTree/Type/Code Quotations 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index ff8da13cd47..76480af9d75 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'." diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index a49d0677e8d..fa52eb851cc 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1380,9 +1380,11 @@ type LexFilterImpl ( // // 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 checkIfInvalidConstructsInTypeDefinition keyword = + let (|InvalidConstructInTypeDefinition|_|) keyword = // Only perform validation if the language feature is enabled - if lexbuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes then + if not (lexbuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then + None + else // 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 = @@ -1394,7 +1396,9 @@ type LexFilterImpl ( | _ -> false // Don't validate if we're in a paren context (could be inline IL or other valid syntax) - if not (hasParenContext offsideStack) then + if hasParenContext offsideStack then + None + else // Find the nearest type definition context and check if we're inappropriately nested let rec checkNesting stack typeDefnsSeen = match stack with @@ -1445,22 +1449,24 @@ type LexFilterImpl ( // Other contexts - continue checking checkNesting rest typeDefnsSeen + // Perform the check and return warning message if needed if checkNesting offsideStack false then let warningMessage = match keyword with | "TYPE" -> - "Nested type definitions are not allowed. Types must be defined at module or namespace level." + FSComp.SR.lexfltInvalidNestedTypeDefinition() | "MODULE" -> - "Modules cannot be nested inside types. Define modules at module or namespace level." + FSComp.SR.lexfltInvalidNestedModule() | "EXCEPTION" -> - "Exceptions must be defined at module level, not inside types." + FSComp.SR.lexfltInvalidNestedExceptionDefinition() | "OPEN" -> - "'open' declarations must appear at module level, not inside types." + FSComp.SR.lexfltInvalidNestedOpenDeclaration() | _ -> - sprintf "'%s' must be defined at module level, not inside a type." keyword + FSComp.SR.lexfltInvalidNestedConstruct(keyword) - warn tokenTup warningMessage - + Some warningMessage + else + None let isSemiSemi = match token with SEMICOLON_SEMICOLON -> true | _ -> false let relaxWhitespace2OffsideRule = // Offside rule for CtxtLetDecl (in types or modules) / CtxtMemberHead / CtxtTypeDefns... (given RelaxWhitespace2) @@ -2115,7 +2121,9 @@ type LexFilterImpl ( // Check for inappropriate nesting within type definitions | MODULE, _ :: _ -> // Check if this module definition is inappropriately nested in a type - checkIfInvalidConstructsInTypeDefinition "MODULE" + match "MODULE" with + | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | _ -> () 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 @@ -2127,7 +2135,9 @@ type LexFilterImpl ( // exception ... ~~~> CtxtException | EXCEPTION, _ :: _ -> // Check if this exception definition is inappropriately nested in a type - checkIfInvalidConstructsInTypeDefinition "EXCEPTION" + match "EXCEPTION" with + | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | _ -> () if debug then dprintf "EXCEPTION: entering CtxtException(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtException tokenStartPos) returnToken tokenLexbufState token @@ -2570,7 +2580,9 @@ type LexFilterImpl ( | TYPE, _ -> // Check if this type definition is inappropriately nested in another type - checkIfInvalidConstructsInTypeDefinition "TYPE" + match "TYPE" with + | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | _ -> () insertComingSoonTokens("TYPE", TYPE_COMING_SOON, TYPE_IS_HERE) if debug then dprintf "TYPE, pushing CtxtTypeDefns(%a)\n" outputPos tokenStartPos @@ -2594,7 +2606,9 @@ type LexFilterImpl ( | OPEN, _ :: _ -> // Check if this open declaration is inappropriately nested in a type - checkIfInvalidConstructsInTypeDefinition "OPEN" + match "OPEN" with + | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | _ -> () returnToken tokenLexbufState token | ODUMMY _, _ -> diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index f3509399089..50258a6ebef 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -912,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 1371cdf823a..22fd8ca0a34 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -912,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 f926fc09070..c85330dfe6c 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -912,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 51d5132aa5a..3ebd287863f 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -912,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 08c722a614d..666d58e13a1 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -912,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 cd1c792b718..9dd8200225a 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -912,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 4167bdb349f..b22d38dd1e7 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -912,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 e6f07eaccc7..eef02b48a5d 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -912,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 9af2778c751..bef03f75f30 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -912,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 9d489f101a4..a10cb98b720 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -912,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 8397e47d93e..690bd832ad0 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -912,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 8dd31405948..653fb19f598 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -912,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 debf52d292c..c73074f89b8 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -912,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/service/data/SyntaxTree/Type/Code Quotations 01.fs b/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs deleted file mode 100644 index b110431c83b..00000000000 --- a/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs +++ /dev/null @@ -1,18 +0,0 @@ -// Expected: No warning - constructs in quotations are data -module Module - -open FSharp.Quotations - -type MyClass() = - member _.GetQuotation() = - <@ - type T = int - module M = - let x = 1 - @> - - member _.GetQuotation2() = - <@@ - exception E of string - open System - @@> diff --git a/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl deleted file mode 100644 index 94e011061a5..00000000000 --- a/tests/service/data/SyntaxTree/Type/Code Quotations 01.fs.bsl +++ /dev/null @@ -1,108 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Code Quotations 01.fs", false, QualifiedNameOfFile Module, [], - [SynModuleOrNamespace - ([Module], false, NamedModule, - [Open - (ModuleOrNamespace - (SynLongIdent - ([FSharp; Quotations], [(4,11--4,12)], [None; None]), - (4,5--4,22)), (4,0--4,22)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [MyClass], - 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 }); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((7,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 - ([_; GetQuotation], [(7,12--7,13)], - [None; None]), None, None, - Pats - [Paren - (Const (Unit, (7,25--7,27)), (7,25--7,27))], - None, (7,11--7,27)), None, - FromParseError - (Quote - (Ident op_Quotation, false, - ArbitraryAfterError - ("quoteExpr2", (8,10--8,10)), false, - (8,8--8,10)), (8,8--8,10)), (7,11--7,27), - NoneAtInvisible, - { LeadingKeyword = Member (7,4--7,10) - InlineKeyword = None - EqualsRange = Some (7,28--7,29) }), (7,4--8,10))], - (7,4--8,10)), [], - 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--8,10), - { LeadingKeyword = Type (6,0--6,4) - EqualsRange = Some (6,15--6,16) - WithKeyword = None })], (6,0--8,10)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [T], - PreXmlDoc ((9,12), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (9,17--9,18)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([int], [], [None])), - (9,21--9,24)), (9,21--9,24)), [], None, (9,17--9,24), - { LeadingKeyword = Type (9,12--9,16) - EqualsRange = Some (9,19--9,20) - WithKeyword = None })], (9,12--9,24)); - NestedModule - (SynComponentInfo - ([], None, [], [M], - PreXmlDoc ((10,12), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (10,12--10,20)), false, - [Let - (false, - [SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((11,16), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, SynValInfo ([], SynArgInfo ([], false, None)), - None), - Named (SynIdent (x, None), false, None, (11,20--11,21)), - None, Const (Int32 1, (11,24--11,25)), (11,20--11,21), - Yes (11,16--11,25), { LeadingKeyword = Let (11,16--11,19) - InlineKeyword = None - EqualsRange = Some (11,22--11,23) })], - (11,16--11,25))], false, (10,12--11,25), - { ModuleKeyword = Some (10,12--10,18) - EqualsRange = Some (10,21--10,22) })], - PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--11,25), { LeadingKeyword = Module (2,0--2,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [LineComment (1,0--1,59)] }, set [])) - -(9,12)-(9,16) parse error Incomplete structured construct at or before this point in quotation literal -(8,8)-(8,10) parse error Unmatched '<@ @>' -(9,12)-(9,16) parse error Unexpected keyword 'type' in type definition. Expected incomplete structured construct at or before this point or other token. -(10,12)-(10,18) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(12,8)-(12,10) parse error Unexpected end of quotation in definition. Expected incomplete structured construct at or before this point or other token. From 399755a0d8cb6d1cd0221fdad547ccac659c7f6b Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 11:32:39 +0100 Subject: [PATCH 24/36] Add more tests and rename feature flag --- src/Compiler/FSComp.txt | 2 +- src/Compiler/Facilities/LanguageFeatures.fs | 6 +- src/Compiler/Facilities/LanguageFeatures.fsi | 2 +- src/Compiler/SyntaxTree/LexFilter.fs | 12 +- src/Compiler/xlf/FSComp.txt.cs.xlf | 6 +- src/Compiler/xlf/FSComp.txt.de.xlf | 6 +- src/Compiler/xlf/FSComp.txt.es.xlf | 6 +- src/Compiler/xlf/FSComp.txt.fr.xlf | 6 +- src/Compiler/xlf/FSComp.txt.it.xlf | 6 +- src/Compiler/xlf/FSComp.txt.ja.xlf | 6 +- src/Compiler/xlf/FSComp.txt.ko.xlf | 6 +- src/Compiler/xlf/FSComp.txt.pl.xlf | 6 +- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 6 +- src/Compiler/xlf/FSComp.txt.ru.xlf | 6 +- src/Compiler/xlf/FSComp.txt.tr.xlf | 6 +- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 6 +- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 6 +- ...arningInvalidConstructsInTypeDefinition.fs | 106 --- .../WarningOnInvalidDeclsInTypeDefinitions.fs | 766 ++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 2 +- 20 files changed, 817 insertions(+), 157 deletions(-) delete mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 76480af9d75..b96a6d5734e 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1807,7 +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" -featureWarnOnUnexpectedModuleDefinitionsInsideTypes,"Warn when a module definition is encountered inside a type definition" +featureWarnOnInvalidDeclsInTypeDefinitions,"Warn 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 0f3d49b66ec..13f30b0eed5 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -102,7 +102,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn - | WarnOnUnexpectedModuleDefinitionsInsideTypes + | WarnOnInvalidDeclsInTypeDefinitions | AllowTypedLetUseAndBang | ReturnFromFinal @@ -241,10 +241,10 @@ type LanguageVersion(versionText) = LanguageFeature.UnmanagedConstraintCsharpInterop, languageVersion100 LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, languageVersion100 LanguageFeature.ReturnFromFinal, languageVersion100 + LanguageFeature.WarnOnInvalidDeclsInTypeDefinitions, languageVersion100 // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work - LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -412,7 +412,7 @@ type LanguageVersion(versionText) = | LanguageFeature.UseBangBindingValueDiscard -> FSComp.SR.featureUseBangBindingValueDiscard () | LanguageFeature.BetterAnonymousRecordParsing -> FSComp.SR.featureBetterAnonymousRecordParsing () | LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn () - | LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes -> FSComp.SR.featureWarnOnUnexpectedModuleDefinitionsInsideTypes () + | LanguageFeature.WarnOnInvalidDeclsInTypeDefinitions -> FSComp.SR.featureWarnOnInvalidDeclsInTypeDefinitions () | 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 2e8541d5736..8d41fbc7143 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -93,7 +93,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn - | WarnOnUnexpectedModuleDefinitionsInsideTypes + | WarnOnInvalidDeclsInTypeDefinitions | AllowTypedLetUseAndBang | ReturnFromFinal diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index fa52eb851cc..479a679ea1d 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1380,9 +1380,9 @@ type LexFilterImpl ( // // 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 (|InvalidConstructInTypeDefinition|_|) keyword = + let (|InvalidDeclsInTypeDefn|_|) keyword = // Only perform validation if the language feature is enabled - if not (lexbuf.SupportsFeature LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then + if not (lexbuf.SupportsFeature LanguageFeature.WarnOnInvalidDeclsInTypeDefinitions) then None else // Skip validation if we're inside a parenthesis context @@ -2122,7 +2122,7 @@ type LexFilterImpl ( | MODULE, _ :: _ -> // Check if this module definition is inappropriately nested in a type match "MODULE" with - | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg | _ -> () insertComingSoonTokens("MODULE", MODULE_COMING_SOON, MODULE_IS_HERE) @@ -2136,7 +2136,7 @@ type LexFilterImpl ( | EXCEPTION, _ :: _ -> // Check if this exception definition is inappropriately nested in a type match "EXCEPTION" with - | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg | _ -> () if debug then dprintf "EXCEPTION: entering CtxtException(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtException tokenStartPos) @@ -2581,7 +2581,7 @@ type LexFilterImpl ( | TYPE, _ -> // Check if this type definition is inappropriately nested in another type match "TYPE" with - | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg | _ -> () insertComingSoonTokens("TYPE", TYPE_COMING_SOON, TYPE_IS_HERE) @@ -2607,7 +2607,7 @@ type LexFilterImpl ( | OPEN, _ :: _ -> // Check if this open declaration is inappropriately nested in a type match "OPEN" with - | InvalidConstructInTypeDefinition warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg | _ -> () returnToken tokenLexbufState token diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 50258a6ebef..1ffdd78c050 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 22fd8ca0a34..909e6c65b22 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index c85330dfe6c..5484129d4f2 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 3ebd287863f..cb5e3fc6b30 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 666d58e13a1..3162bebe14c 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 9dd8200225a..bdfb2de3ba7 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index b22d38dd1e7..59eefe645cd 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index eef02b48a5d..5f73b8b3d4e 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index bef03f75f30..80985228ef9 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index a10cb98b720..43e7e6542c5 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 690bd832ad0..71603761250 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 653fb19f598..c627ff07488 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index c73074f89b8..9c74e36fb7c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -687,9 +687,9 @@ Use type conversion cache during compilation - - Warn when a module definition is encountered inside a type definition - Warn when a module definition is encountered inside a type definition + + Warn when invalid declarations are used in type definitions. + Warn when invalid declarations are used in type definitions. diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs deleted file mode 100644 index 40ccca55553..00000000000 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningInvalidConstructsInTypeDefinition.fs +++ /dev/null @@ -1,106 +0,0 @@ -// 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 ``Module definition is encountered inside a type definition`` = - - [] - let ``Warn when a module definition is encountered inside a type definition``() = - Fsx """ -type IFace = - abstract F : int -> int - module M = - let f () = () - -type C () = - member _.F () = 3 - module M2 = - let f () = () - -type U = - | A - | B - module M3 = - let f () = () - -type R = - { A : int } - module M4 = - let f () = () - -type A = A - -module M4 = begin end -module M5 = begin end -module M6 = begin end - -type B = - | B - module M7 = begin end - module M8 = begin end - module M9 = begin end - -module ThisIsFine = - let f () = () - -type D = D - """ - |> withLangVersionPreview - |> typecheck - |> shouldFail - |> withDiagnostics [ - (Warning 58, Line 4, Col 5, Line 4, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 9, Col 5, Line 9, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 15, Col 5, Line 15, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 20, Col 5, Line 20, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 31, Col 5, Line 31, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 32, Col 5, Line 32, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 33, Col 5, Line 33, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - ] - - [] - let ``Don't warn when a module definition is encountered inside a type definition``() = - Fsx """ -type IFace = - abstract F : int -> int - module M = - let f () = () - -type C () = - member _.F () = 3 - module M2 = - let f () = () - -type U = - | A - | B - module M3 = - let f () = () - -type R = - { A : int } - module M4 = - let f () = () - -type A = A - -module M5 = begin end -module M6 = begin end -module M7 = begin end - -type B = - | B - module M8 = begin end - module M9 = begin end - module M10 = begin end - -module ThisIsFine = - let f () = () - -type D = D - """ - |> withLangVersion10 - |> typecheck - |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs new file mode 100644 index 00000000000..64972baefc9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs @@ -0,0 +1,766 @@ +// 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 WarningOnInvalidDeclsInTypeDefinitions = + module ``Module inside interface`` = + [] + let ``Warn when module is inside interface``() = + Fsx """ +module TestModule + +type IFace = + abstract F : int -> int + module M = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn when module is inside class``() = + Fsx """ +module TestModule + +type C () = + member _.F () = 3 + module M2 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn 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 [ + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn when module is inside discriminated union``() = + Fsx """ +module TestModule + +type U = + | A + | B + module M3 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn when module is inside record``() = + Fsx """ +module TestModule + +type R = + { A : int } + module M4 = + let f () = () + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn when module is inside record``() = + Fsx """ +module TestModule + +type R = + { A : int } + module M4 = + let f () = () + """ + |> withLangVersion90 + |> typecheck + |> shouldSucceed + + module ``Module inside struct`` = + [] + let ``Warn 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 [ + (Warning 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn when module appears after delegate``() = + Fsx """ +module TestModule + +type MyDelegate = delegate of int * int -> int + module InvalidModule = + let x = 1 + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 58, Line 5, Col 5, Line 5, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn 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 [ + (Warning 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn 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 [ + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn when exception is inside type``() = + Fsx """ +module TestModule + +type A = + | A + exception MyException of string + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 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 Warn 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 ``Warn when open declaration is inside type``() = + Fsx """ +module TestModule + +type A = + | A + open System + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 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 Warn 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 ``Warn when type is nested inside another type``() = + Fsx """ +module TestModule + +type OuterType = + | Case1 + | Case2 + type InnerType = int + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 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 Warn 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 ``Warn 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 [ + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 8, Col 5, Line 8, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + (Warning 58, Line 9, Col 5, Line 9, Col 14, "Exceptions must be defined at module level, not inside types.") + (Warning 58, Line 10, Col 5, Line 10, Col 9, "'open' declarations must appear at module level, not inside types.") + ] + + [] + let ``No Warn 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 ``Warn 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 [ + (Warning 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 ``Warn 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 [ + (Warning 58, Line 9, Col 13, Line 9, Col 17, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + (Warning 58, Line 10, Col 13, Line 10, Col 19, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 12, Col 13, Line 12, Col 22, "Exceptions must be defined at module level, not inside types.") + ] + + [] + let ``No Warn 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 ``Warn 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 [ + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 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 Warn 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 ``Warn 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 [ + (Warning 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 Warn 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 ``Warn 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 [ + (Warning 58, Line 6, Col 5, Line 6, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") + (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Warning 58, Line 8, Col 5, Line 8, Col 9, "'open' declarations must appear at module level, not inside types.") + ] + + + [] + let ``No Warn 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 ``Warn for invalid constructs after inherit``() = + Fsx """ +module TestModule + +type Base() = class end + +type Derived() = + inherit Base() + module InvalidModule = begin end + """ + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + ] + + [] + let ``No Warn 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 warning 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 warning 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 warning 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 warning 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 warning 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 warning 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 7317ca88ea1..6e80a0e3fe7 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -221,7 +221,7 @@ - + From 20cd6463d21b7bba8d63b63e0042b19dcfa61522 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 13:15:56 +0100 Subject: [PATCH 25/36] update tests --- .../AttributeUsage/AttributeUsage.fs | 1 + .../ImportDeclarations/ImportDeclarations.fs | 2 ++ ...ClassTypeVisibilityNamespaceRootWithFsi.fs | 24 ++++++------------- 3 files changed, 10 insertions(+), 17 deletions(-) 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..ba47f593edd 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -234,6 +234,7 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ + (Warning 58, Line 50, Col 4, Line 50, Col 8, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") (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") diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs index 449fb5bd9d3..2c707c2338f 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 [ + (Warning 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") + (Warning 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..b8ec1deebe7 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"); + (Warning 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") + ] From f625bbba00db2e7d7bca994387227b4338179dbb Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 14:55:27 +0100 Subject: [PATCH 26/36] Update tests --- src/Compiler/SyntaxTree/LexFilter.fs | 16 ++--- .../AttributeUsage/AttributeUsage.fs | 17 +---- ...ClassTypeVisibilityNamespaceRootWithFsi.fs | 2 +- .../WarningOnInvalidDeclsInTypeDefinitions.fs | 70 +++++++++---------- ...dTypeHasStaticTypeAsLeadingKeyword.fsi.bsl | 2 +- ...ct Class With Invalid Constructs 01.fs.bsl | 4 +- .../Cascading Invalid Constructs 01.fs.bsl | 4 +- .../Type/Deeply Indented Type 01.fs.bsl | 6 +- ... Binding With Invalid Constructs 01.fs.bsl | 6 +- .../Type/Exception Inside Type 01.fs.bsl | 2 +- .../Inherit With Invalid Constructs 01.fs.bsl | 2 +- .../Interleaved Invalid Constructs 01.fs.bsl | 4 +- .../Type/Module After Do Binding 01.fs.bsl | 2 +- .../Type/Module After Members 01.fs.bsl | 2 +- .../Type/Module Inside Class 01.fs.bsl | 2 +- ...le Inside Class With Constructor 01.fs.bsl | 2 +- .../Type/Module Inside Delegate 01.fs.bsl | 2 +- .../Type/Module Inside Interface 01.fs.bsl | 2 +- .../Type/Module Inside Nested Type 01.fs.bsl | 2 +- .../Type/Module Inside Record 01.fs.bsl | 2 +- .../Type/Module Inside Struct 01.fs.bsl | 2 +- ...le Inside Type With Augmentation 01.fs.bsl | 2 +- .../Type/Module Inside Union 01.fs.bsl | 2 +- ...tructors With Invalid Constructs 01.fs.bsl | 2 +- ...tiple Invalid Constructs In Type 01.fs.bsl | 8 +-- .../Type/Nested Module Hierarchy 01.fs.bsl | 2 +- ...edTypeHasStaticTypeAsLeadingKeyword.fs.bsl | 2 +- .../Type/Open Inside Type 01.fs.bsl | 2 +- ... Members With Invalid Constructs 01.fs.bsl | 2 +- .../Type/Type Inside Type 01.fs.bsl | 2 +- 30 files changed, 81 insertions(+), 96 deletions(-) diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 479a679ea1d..6be90cfa483 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1376,7 +1376,7 @@ type LexFilterImpl ( // 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 a warning + // 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) @@ -1449,9 +1449,8 @@ type LexFilterImpl ( // Other contexts - continue checking checkNesting rest typeDefnsSeen - // Perform the check and return warning message if needed if checkNesting offsideStack false then - let warningMessage = + let errorMessage = match keyword with | "TYPE" -> FSComp.SR.lexfltInvalidNestedTypeDefinition() @@ -1464,9 +1463,10 @@ type LexFilterImpl ( | _ -> FSComp.SR.lexfltInvalidNestedConstruct(keyword) - Some warningMessage + Some errorMessage else None + let isSemiSemi = match token with SEMICOLON_SEMICOLON -> true | _ -> false let relaxWhitespace2OffsideRule = // Offside rule for CtxtLetDecl (in types or modules) / CtxtMemberHead / CtxtTypeDefns... (given RelaxWhitespace2) @@ -2122,7 +2122,7 @@ type LexFilterImpl ( | MODULE, _ :: _ -> // Check if this module definition is inappropriately nested in a type match "MODULE" with - | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg | _ -> () insertComingSoonTokens("MODULE", MODULE_COMING_SOON, MODULE_IS_HERE) @@ -2136,7 +2136,7 @@ type LexFilterImpl ( | EXCEPTION, _ :: _ -> // Check if this exception definition is inappropriately nested in a type match "EXCEPTION" with - | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg | _ -> () if debug then dprintf "EXCEPTION: entering CtxtException(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtException tokenStartPos) @@ -2581,7 +2581,7 @@ type LexFilterImpl ( | TYPE, _ -> // Check if this type definition is inappropriately nested in another type match "TYPE" with - | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg | _ -> () insertComingSoonTokens("TYPE", TYPE_COMING_SOON, TYPE_IS_HERE) @@ -2607,7 +2607,7 @@ type LexFilterImpl ( | OPEN, _ :: _ -> // Check if this open declaration is inappropriately nested in a type match "OPEN" with - | InvalidDeclsInTypeDefn warningMsg -> warn tokenTup warningMsg + | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg | _ -> () returnToken tokenLexbufState token 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 ba47f593edd..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,22 +234,7 @@ module CustomAttributes_AttributeUsage = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Warning 58, Line 50, Col 4, Line 50, Col 8, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") - (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/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs index b8ec1deebe7..0d08b96bd8f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs @@ -1220,7 +1220,7 @@ type TestType () = |> typecheck |> withDiagnostics [ (Error 10, Line 4, Col 12, Line 4, Col 13, "Unexpected symbol ':' in member definition"); - (Warning 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 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/WarningOnInvalidDeclsInTypeDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs index 64972baefc9..74bc8c5d389 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs @@ -20,7 +20,7 @@ type IFace = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 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 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -52,7 +52,7 @@ type C () = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 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 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -86,7 +86,7 @@ type MyClass(x: int) = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 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 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -120,7 +120,7 @@ type U = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 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 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -153,7 +153,7 @@ type R = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 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 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -187,7 +187,7 @@ type MyStruct = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 8, Col 5, Line 8, 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.") ] [] @@ -220,7 +220,7 @@ type MyDelegate = delegate of int * int -> int |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 5, Col 5, Line 5, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (Error 58, Line 5, Col 5, Line 5, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -253,7 +253,7 @@ type ClassWithMembers() = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 8, Col 5, Line 8, 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.") ] [] @@ -288,7 +288,7 @@ type ClassWithStatic() = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 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 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") ] [] @@ -319,7 +319,7 @@ type A = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 6, Col 5, Line 6, Col 14, "Exceptions must be defined at module level, not inside types."); + (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") ] @@ -353,7 +353,7 @@ type A = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 6, Col 5, Line 6, Col 9, "'open' declarations must appear at module level, not inside types.") + (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") ] @@ -388,7 +388,7 @@ type OuterType = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 7, Col 5, Line 7, 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 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") ] [] @@ -423,10 +423,10 @@ type MultiTest = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 8, Col 5, Line 8, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") - (Warning 58, Line 9, Col 5, Line 9, Col 14, "Exceptions must be defined at module level, not inside types.") - (Warning 58, Line 10, Col 5, Line 10, Col 9, "'open' declarations must appear at module level, not inside types.") + (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.") ] [] @@ -462,9 +462,9 @@ type B = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 6, Col 5, Line 6, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 8, Col 5, Line 8, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") + (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.") ] [] @@ -502,9 +502,9 @@ module InnerModule = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 9, Col 13, Line 9, Col 17, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") - (Warning 58, Line 10, Col 13, Line 10, Col 19, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 12, Col 13, Line 12, Col 22, "Exceptions must be defined at module level, not inside types.") + (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.") ] [] @@ -542,8 +542,8 @@ type AbstractBase() = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 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 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.") ] [] @@ -578,7 +578,7 @@ type Original with |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 8, Col 5, Line 8, 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.") (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") ] @@ -619,9 +619,9 @@ type TypeWithDo() = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 6, Col 5, Line 6, Col 9, "Nested type definitions are not allowed. Types must be defined at module or namespace level.") - (Warning 58, Line 7, Col 5, Line 7, Col 11, "Modules cannot be nested inside types. Define modules at module or namespace level.") - (Warning 58, Line 8, Col 5, Line 8, Col 9, "'open' declarations must appear at module level, not inside types.") + (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.") ] @@ -656,7 +656,7 @@ type Derived() = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 58, Line 8, Col 5, Line 8, 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.") ] [] @@ -676,7 +676,7 @@ type Derived() = module ``Valid module placement`` = [] - let ``No warning for modules at correct level``() = + let ``No Error for modules at correct level``() = Fsx """ module TestModule @@ -695,7 +695,7 @@ module ValidModule3 = |> shouldSucceed [] - let ``No warning for modules at correct level 2``() = + let ``No Error for modules at correct level 2``() = Fsx """ module TestModule @@ -714,7 +714,7 @@ module ValidModule3 = |> shouldSucceed [] - let ``No warning for let bindings inside class``() = + let ``No Error for let bindings inside class``() = Fsx """ module TestModule @@ -728,7 +728,7 @@ type ClassWithLet() = |> shouldSucceed [] - let ``No warning for let bindings inside class 2``() = + let ``No Error for let bindings inside class 2``() = Fsx """ module TestModule @@ -742,7 +742,7 @@ type ClassWithLet() = |> shouldSucceed [] - let ``No warning for modules at same indentation as type``() = + let ``No Error for modules at same indentation as type``() = Fsx """ module TestModule @@ -754,7 +754,7 @@ module B = begin end // Same column as type, not nested |> shouldSucceed [] - let ``No warning for modules at same indentation as type 2``() = + let ``No Error for modules at same indentation as type 2``() = Fsx """ module TestModule diff --git a/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl b/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl index 9c1cbab1e36..b509927045c 100644 --- a/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl +++ b/tests/service/data/SyntaxTree/SignatureType/NestedTypeHasStaticTypeAsLeadingKeyword.fsi.bsl @@ -32,4 +32,4 @@ SigFile WarnDirectives = [] CodeComments = [] }, set [])) -(3,11)-(3,15) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(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/Abstract Class With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl index 4501df63a99..d6c34d87ec5 100644 --- a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl @@ -96,6 +96,6 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,50)] }, set [])) -(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(11,4)-(11,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(8,4)-(8,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(11,4)-(11,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. (13,4)-(13,11) parse error Unexpected keyword 'default' in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl index 8c3ef784302..958967c0e19 100644 --- a/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl @@ -85,5 +85,5 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,72)] }, set [])) -(6,4)-(6,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. -(7,8)-(7,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(6,4)-(6,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(7,8)-(7,14) parse error Modules cannot be nested inside types. Define modules at module or namespace level. 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 index a17d5f76db7..3e14dd3d314 100644 --- a/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl @@ -106,6 +106,6 @@ ImplFile [LineComment (1,0--1,60); LineComment (9,35--9,49); LineComment (10,35--10,49); LineComment (12,43--12,57)] }, set [])) -(9,12)-(9,16) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. -(10,12)-(10,18) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(12,12)-(12,21) parse warning Exceptions must be defined at module level, not inside types. +(9,12)-(9,16) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. +(10,12)-(10,18) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(12,12)-(12,21) parse error Exceptions must be defined at module level, not inside types. diff --git a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl index 67ce00efed8..7a44a962d47 100644 --- a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl @@ -85,7 +85,7 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,57)] }, set [])) -(11,4)-(11,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(11,4)-(11,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. (13,4)-(13,6) parse error Unexpected keyword 'do' in definition. Expected incomplete structured construct at or before this point or other token. -(16,4)-(16,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(19,4)-(19,8) parse warning 'open' declarations must appear at module level, not inside types. +(16,4)-(16,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(19,4)-(19,8) parse error 'open' declarations must appear at module level, not inside types. 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 index 1d2ee056ab3..efc29955a5c 100644 --- a/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl @@ -9,5 +9,5 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,46)] }, set [])) -(6,4)-(6,13) parse warning Exceptions must be defined at module level, not inside types. +(6,4)-(6,13) parse error Exceptions must be defined at module level, not inside types. (6,4)-(6,13) parse error Unexpected keyword 'exception' in member definition diff --git a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl index 141c7eb8b3d..6a8306c2032 100644 --- a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl @@ -103,5 +103,5 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,45)] }, set [])) -(10,4)-(10,10) parse warning Modules cannot be nested inside types. Define modules 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,12) parse error Unexpected keyword 'override' in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl index 25cafa653f4..d46bff05c3b 100644 --- a/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl @@ -75,6 +75,6 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,55)] }, set [])) -(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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 warning Exceptions must be defined at module level, not inside types. +(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 After Do Binding 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module After Do Binding 01.fs.bsl index 74763193124..fa44a076bea 100644 --- 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 @@ -68,4 +68,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,48)] }, set [])) -(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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 Members 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl index 357b832ef8c..bb9dc70cb4a 100644 --- a/tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module After Members 01.fs.bsl @@ -106,4 +106,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,45)] }, set [])) -(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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 Inside Class 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl index f8dd4eba902..61191bc287b 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Class 01.fs.bsl @@ -81,4 +81,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,44)] }, set [])) -(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs.bsl index f93fdf33ee0..10f12be832f 100644 --- 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 @@ -104,4 +104,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,61)] }, set [])) -(7,4)-(7,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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 Inside Delegate 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl index f9c8eacae01..02ce751defb 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Delegate 01.fs.bsl @@ -90,4 +90,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,46)] }, set [])) -(5,4)-(5,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl index 118f69a180e..4894de15039 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Interface 01.fs.bsl @@ -68,4 +68,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,48)] }, set [])) -(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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 Nested Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Nested Type 01.fs.bsl index 71512a17a5b..fa6bc697236 100644 --- 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 @@ -66,4 +66,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,50)] }, set [])) -(8,12)-(8,18) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl index fdf9d50e8d9..51daf2093d3 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Record 01.fs.bsl @@ -52,4 +52,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,45)] }, set [])) -(6,4)-(6,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl index 1571f2ce4bf..021c379d909 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl @@ -65,4 +65,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,45)] }, set [])) -(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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 Inside Type With Augmentation 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Type With Augmentation 01.fs.bsl index e185d90c8dd..8cd1248d8de 100644 --- 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 @@ -27,6 +27,6 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,52)] }, set [])) -(7,8)-(7,14) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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.bsl b/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl index 36017fb7c48..c49a40c24b3 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Union 01.fs.bsl @@ -54,4 +54,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,44)] }, set [])) -(7,4)-(7,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(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/Multiple Constructors With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl index 5890db5c7df..7c33267bff4 100644 --- a/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl @@ -110,5 +110,5 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,52)] }, set [])) -(9,4)-(9,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(9,4)-(9,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. (12,4)-(12,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/Multiple Invalid Constructs In Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Multiple Invalid Constructs In Type 01.fs.bsl index b9710df359f..c2c35d68f89 100644 --- 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 @@ -73,7 +73,7 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,68)] }, set [])) -(7,4)-(7,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. -(8,4)-(8,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. -(9,4)-(9,13) parse warning Exceptions must be defined at module level, not inside types. -(10,4)-(10,8) parse warning 'open' declarations must appear at module level, not inside types. +(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.bsl b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl index 2834e6253cc..8faff222172 100644 --- a/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl @@ -123,4 +123,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,65)] }, set [])) -(14,16)-(14,22) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(14,16)-(14,22) parse error Modules cannot be nested inside types. Define modules at module or namespace level. diff --git a/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl b/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl index 4fb5fce3e4e..b494146b3bb 100644 --- a/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/NestedTypeHasStaticTypeAsLeadingKeyword.fs.bsl @@ -33,4 +33,4 @@ ImplFile WarnDirectives = [] CodeComments = [] }, set [])) -(3,11)-(3,15) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(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/Open Inside Type 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl index 9d13712f7e8..84f5af755cd 100644 --- a/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Open Inside Type 01.fs.bsl @@ -9,5 +9,5 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,41)] }, set [])) -(6,4)-(6,8) parse warning 'open' declarations must appear at module level, not inside types. +(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/Static Members With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl index 5bafde22394..f49f7405fd4 100644 --- a/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl @@ -101,5 +101,5 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,52)] }, set [])) -(8,4)-(8,10) parse warning Modules cannot be nested inside types. Define modules at module or namespace level. +(8,4)-(8,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. (11,4)-(11,10) parse error Unexpected keyword 'static' in definition. Expected incomplete structured construct at or before this point or other token. 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 index 7e8044d6964..2890c48d450 100644 --- a/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Type Inside Type 01.fs.bsl @@ -51,4 +51,4 @@ ImplFile WarnDirectives = [] CodeComments = [LineComment (1,0--1,41)] }, set [])) -(6,4)-(6,8) parse warning Nested type definitions are not allowed. Types must be defined at module or namespace level. +(6,4)-(6,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. From b55be44678b2a080c6a839542ea98ac09abdf309 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 16:40:45 +0100 Subject: [PATCH 27/36] more renaming --- src/Compiler/FSComp.txt | 2 +- src/Compiler/Facilities/LanguageFeatures.fs | 6 +- src/Compiler/Facilities/LanguageFeatures.fsi | 2 +- src/Compiler/SyntaxTree/LexFilter.fs | 2 +- src/Compiler/xlf/FSComp.txt.cs.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.de.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.es.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.fr.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.it.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.ja.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.ko.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.pl.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.ru.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.tr.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 10 +-- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 10 +-- .../ImportDeclarations/ImportDeclarations.fs | 4 +- ...> ErrorOnInvalidDeclsInTypeDefinitions.fs} | 78 +++++++++---------- .../FSharp.Compiler.ComponentTests.fsproj | 2 +- 20 files changed, 113 insertions(+), 113 deletions(-) rename tests/FSharp.Compiler.ComponentTests/ErrorMessages/{WarningOnInvalidDeclsInTypeDefinitions.fs => ErrorOnInvalidDeclsInTypeDefinitions.fs} (88%) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index b96a6d5734e..4e3c9f81b45 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1807,7 +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" -featureWarnOnInvalidDeclsInTypeDefinitions,"Warn when invalid declarations are used in type definitions." +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 13f30b0eed5..4b032db713f 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -102,7 +102,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn - | WarnOnInvalidDeclsInTypeDefinitions + | ErrorOnInvalidDeclsInTypeDefinitions | AllowTypedLetUseAndBang | ReturnFromFinal @@ -241,7 +241,7 @@ type LanguageVersion(versionText) = LanguageFeature.UnmanagedConstraintCsharpInterop, languageVersion100 LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, languageVersion100 LanguageFeature.ReturnFromFinal, languageVersion100 - LanguageFeature.WarnOnInvalidDeclsInTypeDefinitions, languageVersion100 + LanguageFeature.ErrorOnInvalidDeclsInTypeDefinitions, languageVersion100 // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work @@ -412,7 +412,7 @@ type LanguageVersion(versionText) = | LanguageFeature.UseBangBindingValueDiscard -> FSComp.SR.featureUseBangBindingValueDiscard () | LanguageFeature.BetterAnonymousRecordParsing -> FSComp.SR.featureBetterAnonymousRecordParsing () | LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn () - | LanguageFeature.WarnOnInvalidDeclsInTypeDefinitions -> FSComp.SR.featureWarnOnInvalidDeclsInTypeDefinitions () + | 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 8d41fbc7143..1217b83baf6 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -93,7 +93,7 @@ type LanguageFeature = | UseBangBindingValueDiscard | BetterAnonymousRecordParsing | ScopedNowarn - | WarnOnInvalidDeclsInTypeDefinitions + | ErrorOnInvalidDeclsInTypeDefinitions | AllowTypedLetUseAndBang | ReturnFromFinal diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 6be90cfa483..424c9c7a164 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1382,7 +1382,7 @@ type LexFilterImpl ( // Note: Constructs at the same column level are NOT nested (e.g., type A = A type B = B on same line) let (|InvalidDeclsInTypeDefn|_|) keyword = // Only perform validation if the language feature is enabled - if not (lexbuf.SupportsFeature LanguageFeature.WarnOnInvalidDeclsInTypeDefinitions) then + if not (lexbuf.SupportsFeature LanguageFeature.ErrorOnInvalidDeclsInTypeDefinitions) then None else // Skip validation if we're inside a parenthesis context diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 1ffdd78c050..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Metoda getter a setter indexované vlastnosti musí mít stejný typ. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 909e6c65b22..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Getter und Setter für indizierte Eigenschaften müssen denselben Typ aufweisen. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 5484129d4f2..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type El captador y el establecedor de propiedades indexadas deben tener el mismo tipo. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index cb5e3fc6b30..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Les propriétés indexées getter et setter doivent avoir le même type diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 3162bebe14c..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Il getter e il setter delle proprietà indicizzate devono avere lo stesso tipo diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index bdfb2de3ba7..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 静的クラスに関するエラー報告 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type インデックス付きプロパティのゲッターとセッターの型は同じである必要があります diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 59eefe645cd..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 정적 클래스에 대한 오류 보고 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type 인덱싱된 속성 getter와 setter의 형식이 같아야 합니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 5f73b8b3d4e..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Metoda pobierająca i metoda ustawiająca właściwości indeksowanych muszą mieć taki sam typ. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 80985228ef9..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type As propriedades indexadas getter e setter devem ter o mesmo tipo diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 43e7e6542c5..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 Отчеты об ошибках для статических классов @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Методы получения и установки индексированных свойств должны иметь один и тот же тип. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 71603761250..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 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type Dizini oluşturulmuş özelliklerin alıcısı ve ayarlayıcısı aynı türde olmalıdır diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index c627ff07488..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 有关静态类的错误报告 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type 索引属性 getter 和 setter 必须具有相同的类型 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 9c74e36fb7c..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 報告靜態類別時發生錯誤 @@ -687,11 +692,6 @@ Use type conversion cache during compilation - - Warn when invalid declarations are used in type definitions. - Warn when invalid declarations are used in type definitions. - - Indexed properties getter and setter must have the same type 索引屬性 getter 和 setter 必須具有相同的類型 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs index 2c707c2338f..b8e86960969 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ImportDeclarations/ImportDeclarations.fs @@ -60,7 +60,7 @@ module ImportDeclarations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Warning 58, Line 7, Col 5, Line 7, Col 9, "'open' declarations must appear at module level, not inside types.") + (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") ] @@ -73,7 +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") - (Warning 58, Line 23, Col 9, Line 23, Col 13, "'open' declarations must appear at module level, not inside types.") + (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/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs similarity index 88% rename from tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs rename to tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs index 74bc8c5d389..823d46466f3 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarningOnInvalidDeclsInTypeDefinitions.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs @@ -4,10 +4,10 @@ namespace ErrorMessages open Xunit open FSharp.Test.Compiler -module WarningOnInvalidDeclsInTypeDefinitions = +module ErrorOnInvalidDeclsInTypeDefinitions = module ``Module inside interface`` = [] - let ``Warn when module is inside interface``() = + let ``Error when module is inside interface``() = Fsx """ module TestModule @@ -24,7 +24,7 @@ type IFace = ] [] - let ``No Warn when module is inside interface``() = + let ``No Error when module is inside interface``() = Fsx """ module TestModule @@ -39,7 +39,7 @@ type IFace = module ``Module inside class`` = [] - let ``Warn when module is inside class``() = + let ``Error when module is inside class``() = Fsx """ module TestModule @@ -56,7 +56,7 @@ type C () = ] [] - let ``No Warn when module is inside class``() = + let ``No Error when module is inside class``() = Fsx """ module TestModule @@ -72,7 +72,7 @@ type C () = module ``Module inside class with constructor`` = [] - let ``Warn when module is inside class with constructor``() = + let ``Error when module is inside class with constructor``() = Fsx """ module TestModule @@ -90,7 +90,7 @@ type MyClass(x: int) = ] [] - let ``No Warn when module is inside class with constructor``() = + let ``No Error when module is inside class with constructor``() = Fsx """ module TestModule @@ -106,7 +106,7 @@ type MyClass(x: int) = module ``Module inside union`` = [] - let ``Warn when module is inside discriminated union``() = + let ``Error when module is inside discriminated union``() = Fsx """ module TestModule @@ -124,7 +124,7 @@ type U = ] [] - let ``No Warn when module is inside discriminated union``() = + let ``No Error when module is inside discriminated union``() = Fsx """ module TestModule @@ -140,7 +140,7 @@ type U = module ``Module inside record`` = [] - let ``Warn when module is inside record``() = + let ``Error when module is inside record``() = Fsx """ module TestModule @@ -157,7 +157,7 @@ type R = ] [] - let ``No Warn when module is inside record``() = + let ``No Error when module is inside record``() = Fsx """ module TestModule @@ -172,7 +172,7 @@ type R = module ``Module inside struct`` = [] - let ``Warn when module is inside struct``() = + let ``Error when module is inside struct``() = Fsx """ module TestModule @@ -191,7 +191,7 @@ type MyStruct = ] [] - let ``No Warn when module is inside struct``() = + let ``No Error when module is inside struct``() = Fsx """ module TestModule @@ -208,7 +208,7 @@ type MyStruct = module ``Module after delegate`` = [] - let ``Warn when module appears after delegate``() = + let ``Error when module appears after delegate``() = Fsx """ module TestModule @@ -224,7 +224,7 @@ type MyDelegate = delegate of int * int -> int ] [] - let ``No Warn when module appears after delegate``() = + let ``No Error when module appears after delegate``() = Fsx """ module TestModule @@ -238,7 +238,7 @@ type MyDelegate = delegate of int * int -> int module ``Module after type members`` = [] - let ``Warn when module appears after type members``() = + let ``Error when module appears after type members``() = Fsx """ module TestModule @@ -257,7 +257,7 @@ type ClassWithMembers() = ] [] - let ``No Warn when module appears after type members``() = + let ``No Error when module appears after type members``() = Fsx """ module TestModule @@ -274,7 +274,7 @@ type ClassWithMembers() = module ``Module after static members`` = [] - let ``Warn when module appears after static members``() = + let ``Error when module appears after static members``() = Fsx """ module TestModule @@ -292,7 +292,7 @@ type ClassWithStatic() = ] [] - let ``No Warn when module appears after static members``() = + let ``No Error when module appears after static members``() = Fsx """ module TestModule @@ -307,7 +307,7 @@ type ClassWithStatic() = |> shouldSucceed module ``Exception inside type`` = [] - let ``Warn when exception is inside type``() = + let ``Error when exception is inside type``() = Fsx """ module TestModule @@ -324,7 +324,7 @@ type A = ] [] - let ``No Warn when exception is inside type``() = + let ``No Error when exception is inside type``() = Fsx """ module TestModule @@ -341,7 +341,7 @@ type A = module ``Open inside type`` = [] - let ``Warn when open declaration is inside type``() = + let ``Error when open declaration is inside type``() = Fsx """ module TestModule @@ -358,7 +358,7 @@ type A = ] [] - let ``No Warn when open declaration is inside type``() = + let ``No Error when open declaration is inside type``() = Fsx """ module TestModule @@ -375,7 +375,7 @@ type A = module ``Type inside type`` = [] - let ``Warn when type is nested inside another type``() = + let ``Error when type is nested inside another type``() = Fsx """ module TestModule @@ -392,7 +392,7 @@ type OuterType = ] [] - let ``No Warn when type is nested inside another type``() = + let ``No Error when type is nested inside another type``() = Fsx """ module TestModule @@ -407,7 +407,7 @@ type OuterType = module ``Multiple invalid constructs`` = [] - let ``Warn for all invalid nested constructs in single type``() = + let ``Error for all invalid nested constructs in single type``() = Fsx """ module TestModule @@ -430,7 +430,7 @@ type MultiTest = ] [] - let ``No Warn for all invalid nested constructs in single type``() = + let ``No Error for all invalid nested constructs in single type``() = Fsx """ module TestModule @@ -448,7 +448,7 @@ type MultiTest = module ``Multiple modules in single type`` = [] - let ``Warn for each module inside type``() = + let ``Error for each module inside type``() = Fsx """ module TestModule @@ -468,7 +468,7 @@ type B = ] [] - let ``No Warn for each module inside type``() = + let ``No Error for each module inside type``() = Fsx """ module TestModule @@ -484,7 +484,7 @@ type B = module ``Deeply nested invalid constructs`` = [] - let ``Warn for invalid constructs in deeply nested context``() = + let ``Error for invalid constructs in deeply nested context``() = Fsx """ module OuterModule @@ -508,7 +508,7 @@ module InnerModule = ] [] - let ``No Warn for invalid constructs in deeply nested context``() = + let ``No Error for invalid constructs in deeply nested context``() = Fsx """ module OuterModule @@ -528,7 +528,7 @@ module InnerModule = module ``Abstract class with invalid constructs`` = [] - let ``Warn for invalid constructs in abstract class``() = + let ``Error for invalid constructs in abstract class``() = Fsx """ module TestModule @@ -547,7 +547,7 @@ type AbstractBase() = ] [] - let ``No Warn for invalid constructs in abstract class``() = + let ``No Error for invalid constructs in abstract class``() = Fsx """ module TestModule @@ -563,7 +563,7 @@ type AbstractBase() = module ``Type augmentation with invalid constructs`` = [] - let ``Warn for module in type augmentation``() = + let ``Error for module in type augmentation``() = Fsx """ module TestModule @@ -584,7 +584,7 @@ type Original with ] [] - let ``No Warn for module in type augmentation``() = + let ``No Error for module in type augmentation``() = Fsx """ module TestModule @@ -605,7 +605,7 @@ type Original with module ``Do binding with invalid constructs`` = [] - let ``Warn for invalid constructs after do binding``() = + let ``Error for invalid constructs after do binding``() = Fsx """ module TestModule @@ -626,7 +626,7 @@ type TypeWithDo() = [] - let ``No Warn for invalid constructs after do binding``() = + let ``No Error for invalid constructs after do binding``() = Fsx """ module TestModule @@ -642,7 +642,7 @@ type TypeWithDo() = module ``Inherit with invalid constructs`` = [] - let ``Warn for invalid constructs after inherit``() = + let ``Error for invalid constructs after inherit``() = Fsx """ module TestModule @@ -660,7 +660,7 @@ type Derived() = ] [] - let ``No Warn for invalid constructs after inherit``() = + let ``No Error for invalid constructs after inherit``() = Fsx """ module TestModule diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 6e80a0e3fe7..d13ac568b4c 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -221,7 +221,7 @@ - + From 3a37b0607ab33b9595c2972db2fd571a5431a8c5 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 21:41:13 +0100 Subject: [PATCH 28/36] use a simple function instead of an AP --- src/Compiler/SyntaxTree/LexFilter.fs | 31 +++++++--------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 424c9c7a164..e74f514f812 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -1380,11 +1380,8 @@ type LexFilterImpl ( // // 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 (|InvalidDeclsInTypeDefn|_|) keyword = - // Only perform validation if the language feature is enabled - if not (lexbuf.SupportsFeature LanguageFeature.ErrorOnInvalidDeclsInTypeDefinitions) then - None - else + 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 = @@ -1396,9 +1393,7 @@ type LexFilterImpl ( | _ -> false // Don't validate if we're in a paren context (could be inline IL or other valid syntax) - if hasParenContext offsideStack then - None - else + 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 @@ -1463,9 +1458,7 @@ type LexFilterImpl ( | _ -> FSComp.SR.lexfltInvalidNestedConstruct(keyword) - Some errorMessage - else - None + error tokenTup errorMessage let isSemiSemi = match token with SEMICOLON_SEMICOLON -> true | _ -> false let relaxWhitespace2OffsideRule = @@ -2121,9 +2114,7 @@ type LexFilterImpl ( // Check for inappropriate nesting within type definitions | MODULE, _ :: _ -> // Check if this module definition is inappropriately nested in a type - match "MODULE" with - | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg - | _ -> () + 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 @@ -2135,9 +2126,7 @@ type LexFilterImpl ( // exception ... ~~~> CtxtException | EXCEPTION, _ :: _ -> // Check if this exception definition is inappropriately nested in a type - match "EXCEPTION" with - | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg - | _ -> () + checkForInvalidDeclsInTypeDefn "EXCEPTION" if debug then dprintf "EXCEPTION: entering CtxtException(%a)\n" outputPos tokenStartPos pushCtxt tokenTup (CtxtException tokenStartPos) returnToken tokenLexbufState token @@ -2580,9 +2569,7 @@ type LexFilterImpl ( | TYPE, _ -> // Check if this type definition is inappropriately nested in another type - match "TYPE" with - | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg - | _ -> () + checkForInvalidDeclsInTypeDefn "TYPE" insertComingSoonTokens("TYPE", TYPE_COMING_SOON, TYPE_IS_HERE) if debug then dprintf "TYPE, pushing CtxtTypeDefns(%a)\n" outputPos tokenStartPos @@ -2606,9 +2593,7 @@ type LexFilterImpl ( | OPEN, _ :: _ -> // Check if this open declaration is inappropriately nested in a type - match "OPEN" with - | InvalidDeclsInTypeDefn errorMsg -> error tokenTup errorMsg - | _ -> () + checkForInvalidDeclsInTypeDefn "OPEN" returnToken tokenLexbufState token | ODUMMY _, _ -> From 7585e0470d5fbcb7e5a42047d74bebb4567e1659 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 22:19:56 +0100 Subject: [PATCH 29/36] simplify and update baselines --- ...stract Class With Invalid Constructs 01.fs | 13 -- ...ct Class With Invalid Constructs 01.fs.bsl | 101 -------------- .../Type/Cascading Invalid Constructs 01.fs | 13 -- .../Cascading Invalid Constructs 01.fs.bsl | 89 ------------- .../Cascading Nested Invalid Constructs 01.fs | 7 + ...cading Nested Invalid Constructs 01.fs.bsl | 55 ++++++++ .../Type/Comments With Keywords 01.fs | 15 +-- .../Type/Comments With Keywords 01.fs.bsl | 65 ++------- .../Type/Deeply Indented Type 01.fs | 10 +- .../Type/Deeply Indented Type 01.fs.bsl | 89 +++++-------- .../Do Binding With Invalid Constructs 01.fs | 21 --- ... Binding With Invalid Constructs 01.fs.bsl | 91 ------------- .../Type/Double Semicolon Delimiters 01.fs | 14 +- .../Double Semicolon Delimiters 01.fs.bsl | 76 ++++------- .../Type/Exception Inside Type 01.fs | 5 +- .../Type/Exception Inside Type 01.fs.bsl | 33 ++++- .../Inherit With Invalid Constructs 01.fs | 13 -- .../Inherit With Invalid Constructs 01.fs.bsl | 107 --------------- .../SyntaxTree/Type/Keywords In Strings 01.fs | 12 +- .../Type/Keywords In Strings 01.fs.bsl | 94 +++---------- .../SyntaxTree/Type/Let Inside Class 01.fs | 9 +- .../Type/Let Inside Class 01.fs.bsl | 102 +++------------ .../Type/Module After Inherit 01.fs | 10 ++ .../Type/Module After Inherit 01.fs.bsl | 78 +++++++++++ .../Type/Module After Static Members 01.fs | 8 ++ .../Module After Static Members 01.fs.bsl | 72 ++++++++++ ... Exception Interleaved With Members 01.fs} | 6 +- ...eption Interleaved With Members 01.fs.bsl} | 19 +-- .../Module And Type After Do Binding 01.fs | 13 ++ ...Module And Type After Do Binding 01.fs.bsl | 90 +++++++++++++ .../Type/Module And Type Inside Type 01.fs | 8 ++ .../Module And Type Inside Type 01.fs.bsl | 59 +++++++++ .../Type/Module Between Constructors 01.fs | 10 ++ ... => Module Between Constructors 01.fs.bsl} | 82 +++++------- ...Module Inside Class With Constructor 01.fs | 6 +- ...le Inside Class With Constructor 01.fs.bsl | 78 +++-------- .../Type/Module Inside Struct 01.fs | 11 +- .../Type/Module Inside Struct 01.fs.bsl | 65 ++------- ...Constructors With Invalid Constructs 01.fs | 14 -- .../Type/Nested Module Hierarchy 01.fs | 10 +- .../Type/Nested Module Hierarchy 01.fs.bsl | 123 +++++------------- ...atic Members With Invalid Constructs 01.fs | 11 -- ... Members With Invalid Constructs 01.fs.bsl | 105 --------------- 43 files changed, 672 insertions(+), 1240 deletions(-) delete mode 100644 tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Cascading Nested Invalid Constructs 01.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl delete mode 100644 tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module After Inherit 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module After Static Members 01.fs.bsl rename tests/service/data/SyntaxTree/Type/{Interleaved Invalid Constructs 01.fs => Module And Exception Interleaved With Members 01.fs} (51%) rename tests/service/data/SyntaxTree/Type/{Interleaved Invalid Constructs 01.fs.bsl => Module And Exception Interleaved With Members 01.fs.bsl} (82%) create mode 100644 tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module And Type After Do Binding 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs create mode 100644 tests/service/data/SyntaxTree/Type/Module And Type Inside Type 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs rename tests/service/data/SyntaxTree/Type/{Multiple Constructors With Invalid Constructs 01.fs.bsl => Module Between Constructors 01.fs.bsl} (50%) delete mode 100644 tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs delete mode 100644 tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl diff --git a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs deleted file mode 100644 index 5f559c66818..00000000000 --- a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs +++ /dev/null @@ -1,13 +0,0 @@ -// Expected: Multiple warnings for module and type -module Module - -[] -type AbstractBase() = - abstract member Method : int -> int - - module InvalidModule = - let helper = 10 - - type InvalidType = string - - default _.Method(x) = x * 2 diff --git a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl deleted file mode 100644 index d6c34d87ec5..00000000000 --- a/tests/service/data/SyntaxTree/Type/Abstract Class With Invalid Constructs 01.fs.bsl +++ /dev/null @@ -1,101 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Abstract Class With Invalid Constructs 01.fs", false, - QualifiedNameOfFile Module, [], - [SynModuleOrNamespace - ([Module], false, NamedModule, - [Types - ([SynTypeDefn - (SynComponentInfo - ([{ Attributes = - [{ TypeName = - SynLongIdent ([AbstractClass], [], [None]) - ArgExpr = Const (Unit, (4,2--4,15)) - Target = None - AppliesToGetterAndSetter = false - Range = (4,2--4,15) }] - Range = (4,0--4,17) }], None, [], [AbstractBase], - PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,5--5,17)), - ObjectModel - (Unspecified, - [ImplicitCtor - (None, [], Const (Unit, (5,17--5,19)), None, - PreXmlDoc ((5,17), FSharp.Compiler.Xml.XmlDocCollector), - (5,5--5,17), { AsKeyword = None }); - AbstractSlot - (SynValSig - ([], SynIdent (Method, None), - SynValTyparDecls (None, true), - Fun - (LongIdent (SynLongIdent ([int], [], [None])), - LongIdent (SynLongIdent ([int], [], [None])), - (6,29--6,39), { ArrowRange = (6,33--6,35) }), - SynValInfo - ([[SynArgInfo ([], false, None)]], - SynArgInfo ([], false, None)), false, false, - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - Single None, None, (6,4--6,39), - { LeadingKeyword = - AbstractMember ((6,4--6,12), (6,13--6,19)) - InlineKeyword = None - WithKeyword = None - EqualsRange = None }), - { IsInstance = true - IsDispatchSlot = true - IsOverrideOrExplicitImpl = false - IsFinal = false - GetterOrSetterIsCompilerGenerated = false - MemberKind = Member }, (6,4--6,39), - { GetSetKeywords = None })], (6,4--6,39)), [], - Some - (ImplicitCtor - (None, [], Const (Unit, (5,17--5,19)), None, - PreXmlDoc ((5,17), FSharp.Compiler.Xml.XmlDocCollector), - (5,5--5,17), { AsKeyword = None })), (4,0--6,39), - { LeadingKeyword = Type (5,0--5,4) - EqualsRange = Some (5,20--5,21) - WithKeyword = None })], (4,0--6,39)); - 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) }); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [InvalidType], - PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (11,9--11,20)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([string], [], [None])), - (11,23--11,29)), (11,23--11,29)), [], None, - (11,9--11,29), { LeadingKeyword = Type (11,4--11,8) - EqualsRange = Some (11,21--11,22) - WithKeyword = None })], (11,4--11,29))], - PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--11,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [LineComment (1,0--1,50)] }, set [])) - -(8,4)-(8,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. -(11,4)-(11,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. -(13,4)-(13,11) parse error Unexpected keyword 'default' in definition. Expected incomplete structured construct at or before this point or other token. diff --git a/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs deleted file mode 100644 index 205584cb8b6..00000000000 --- a/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs +++ /dev/null @@ -1,13 +0,0 @@ -// Expected: Multiple warnings for each inappropriately nested construct -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/Cascading Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl deleted file mode 100644 index 958967c0e19..00000000000 --- a/tests/service/data/SyntaxTree/Type/Cascading Invalid Constructs 01.fs.bsl +++ /dev/null @@ -1,89 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Cascading 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 - (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, [], [B], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (6,9--6,10)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (6,13--6,14)), (6,13--6,14)), [], None, (6,9--6,14), - { LeadingKeyword = Type (6,4--6,8) - EqualsRange = Some (6,11--6,12) - WithKeyword = None })], (6,4--6,14)); - NestedModule - (SynComponentInfo - ([], None, [], [C], - PreXmlDoc ((7,8), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,8--7,16)), false, - [Expr (Const (Unit, (7,19--7,21)), (7,19--7,21))], false, - (7,8--7,21), { ModuleKeyword = Some (7,8--7,14) - EqualsRange = Some (7,17--7,18) }); - Exception - (SynExceptionDefn - (SynExceptionDefnRepr - ([], - SynUnionCase - ([], SynIdent (D, None), Fields [], PreXmlDocEmpty, None, - (8,22--8,23), { BarRange = None }), None, - PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), - None, (8,12--8,23)), None, [], (8,12--8,23)), (8,12--8,23)); - ModuleAbbrev (E, [C], (9,16--9,28)); - Let - (false, - [SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((10,20), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), - LongIdent - (SynLongIdent ([f], [], [None]), None, None, - Pats [Paren (Const (Unit, (10,26--10,28)), (10,26--10,28))], - None, (10,24--10,28)), None, Const (Unit, (10,31--10,33)), - (10,24--10,28), NoneAtLet, - { LeadingKeyword = Let (10,20--10,23) - InlineKeyword = None - EqualsRange = Some (10,29--10,30) })], (10,20--10,33)); - Open - (ModuleOrNamespace - (SynLongIdent ([System], [], [None]), (11,29--11,35)), - (11,24--11,35)); - NestedModule - (SynComponentInfo - ([], None, [], [G], - PreXmlDoc ((12,28), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (12,28--12,36)), false, - [ModuleAbbrev (H, [E], (13,32--13,44))], false, (12,28--13,44), - { ModuleKeyword = Some (12,28--12,34) - EqualsRange = Some (12,37--12,38) })], - PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--13,44), { LeadingKeyword = Module (2,0--2,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [LineComment (1,0--1,72)] }, set [])) - -(6,4)-(6,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. -(7,8)-(7,14) parse error Modules cannot be nested inside types. Define modules 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 index 6ce256beda0..df2f7296d49 100644 --- a/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs +++ b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs @@ -1,17 +1,8 @@ -// Expected: No warning - keywords in comments are ignored +// Testing: Keywords in comments should be ignored module Module -type MyType() = +type MyType = // This comment mentions module and type member _.Method() = 1 - - (* This multi-line comment also contains - module MyModule - type MyType - exception MyException - open System - *) + (* module MyModule *) member _.AnotherMethod() = 2 - - /// XML doc comment with module, type, exception keywords - member _.DocumentedMethod() = 3 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 index 7ec21126bc6..90710f91ec7 100644 --- a/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Comments With Keywords 01.fs.bsl @@ -12,11 +12,7 @@ ImplFile false, None, (4,5--4,11)), ObjectModel (Unspecified, - [ImplicitCtor - (None, [], Const (Unit, (4,11--4,13)), None, - PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,11), { AsKeyword = None }); - Member + [Member (SynBinding (None, Normal, false, false, [], PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), @@ -46,35 +42,7 @@ ImplFile Member (SynBinding (None, Normal, false, false, [], - PreXmlDoc ((14,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], [(14,12--14,13)], - [None; None]), None, None, - Pats - [Paren - (Const (Unit, (14,26--14,28)), - (14,26--14,28))], None, (14,11--14,28)), - None, Const (Int32 2, (14,31--14,32)), - (14,11--14,28), NoneAtInvisible, - { LeadingKeyword = Member (14,4--14,10) - InlineKeyword = None - EqualsRange = Some (14,29--14,30) }), - (14,4--14,32)); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((17,4), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), SynValData (Some { IsInstance = true IsDispatchSlot = false @@ -87,30 +55,25 @@ ImplFile SynArgInfo ([], false, None)), None), LongIdent (SynLongIdent - ([_; DocumentedMethod], [(17,12--17,13)], + ([_; AnotherMethod], [(8,12--8,13)], [None; None]), None, None, Pats [Paren - (Const (Unit, (17,29--17,31)), - (17,29--17,31))], None, (17,11--17,31)), - None, Const (Int32 3, (17,34--17,35)), (16,4--17,31), + (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 (17,4--17,10) + { LeadingKeyword = Member (8,4--8,10) InlineKeyword = None - EqualsRange = Some (17,32--17,33) }), - (16,4--17,35))], (6,4--17,35)), [], - Some - (ImplicitCtor - (None, [], Const (Unit, (4,11--4,13)), None, - PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,11), { AsKeyword = None })), (4,5--17,35), + 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,14--4,15) - WithKeyword = None })], (4,0--17,35))], + EqualsRange = Some (4,12--4,13) + WithKeyword = None })], (4,0--8,32))], PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--17,35), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--8,32), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] CodeComments = - [LineComment (1,0--1,58); LineComment (5,4--5,44); - BlockComment (8,4--13,6)] }, set [])) + [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 index fe645b29cf7..993b78b0a0b 100644 --- a/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs @@ -1,12 +1,10 @@ -// Expected: Multiple warnings for nested invalid constructs +// Testing: Invalid constructs in deeply nested type module OuterModule module InnerModule = module DeeplyNested = type IndentedType = - | Case1 - | Case2 - type NestedType = int // Should warn - module NestedModule = // Should warn + type NestedType = int + module NestedModule = let x = 1 - exception NestedExc of string // Should warn + 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 index 3e14dd3d314..10723d4529c 100644 --- a/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Deeply Indented Type 01.fs.bsl @@ -20,92 +20,69 @@ ImplFile ([], None, [], [IndentedType], PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), false, None, (6,13--6,25)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (Case1, None), Fields [], - PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), - None, (7,14--7,19), - { BarRange = Some (7,12--7,13) }); - SynUnionCase - ([], SynIdent (Case2, None), Fields [], - PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), - None, (8,14--8,19), - { BarRange = Some (8,12--8,13) })], - (7,12--8,19)), (7,12--8,19)), [], None, - (6,13--8,19), { LeadingKeyword = Type (6,8--6,12) + 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--8,19)); + WithKeyword = None })], (6,8--6,27)); Types ([SynTypeDefn (SynComponentInfo ([], None, [], [NestedType], - PreXmlDoc ((9,12), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (9,17--9,27)), + PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (7,17--7,27)), Simple (TypeAbbrev (Ok, LongIdent (SynLongIdent ([int], [], [None])), - (9,30--9,33)), (9,30--9,33)), [], None, - (9,17--9,33), { LeadingKeyword = Type (9,12--9,16) - EqualsRange = Some (9,28--9,29) - WithKeyword = None })], (9,12--9,33)); + (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 ((10,12), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (10,12--10,31)), false, + PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,12--8,31)), false, [Let (false, [SynBinding (None, Normal, false, false, [], - PreXmlDoc ((11,16), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((9,16), FSharp.Compiler.Xml.XmlDocCollector), SynValData (None, SynValInfo ([], SynArgInfo ([], false, None)), None), Named - (SynIdent (x, None), false, None, (11,20--11,21)), - None, Const (Int32 1, (11,24--11,25)), - (11,20--11,21), Yes (11,16--11,25), - { LeadingKeyword = Let (11,16--11,19) + (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 (11,22--11,23) })], - (11,16--11,25))], false, (10,12--11,25), - { ModuleKeyword = Some (10,12--10,18) - EqualsRange = Some (10,32--10,33) }); + 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 - [SynField - ([], false, None, - LongIdent - (SynLongIdent ([string], [], [None])), - false, - PreXmlDoc ((12,35), FSharp.Compiler.Xml.XmlDocCollector), - None, (12,35--12,41), - { LeadingKeyword = None - MutableKeyword = None })], PreXmlDocEmpty, - None, (12,22--12,41), { BarRange = None }), None, - PreXmlDoc ((12,12), FSharp.Compiler.Xml.XmlDocCollector), - None, (12,12--12,41)), None, [], (12,12--12,41)), - (12,12--12,41))], false, (5,4--12,41), + ([], 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--12,41), + 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--12,41), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--10,31), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = - [LineComment (1,0--1,60); LineComment (9,35--9,49); - LineComment (10,35--10,49); LineComment (12,43--12,57)] }, set [])) + CodeComments = [LineComment (1,0--1,52)] }, set [])) -(9,12)-(9,16) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. -(10,12)-(10,18) parse error Modules cannot be nested inside types. Define modules at module or namespace level. -(12,12)-(12,21) parse error Exceptions must be defined at module level, not inside types. +(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/Do Binding With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs deleted file mode 100644 index d175e7f26a9..00000000000 --- a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs +++ /dev/null @@ -1,21 +0,0 @@ -// Expected: Multiple warnings for type, module, and open -module Module - -type ClassWithDoBinding() = - let mutable initialized = false - - do - printfn "Starting initialization" - initialized <- true - - type InternalType = int - - do - printfn "More initialization" - - module InternalModule = - let x = 1 - - open System.Collections - - member _.IsInitialized = initialized diff --git a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl deleted file mode 100644 index 7a44a962d47..00000000000 --- a/tests/service/data/SyntaxTree/Type/Do Binding With Invalid Constructs 01.fs.bsl +++ /dev/null @@ -1,91 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Do Binding With Invalid Constructs 01.fs", false, - QualifiedNameOfFile Module, [], - [SynModuleOrNamespace - ([Module], false, NamedModule, - [Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [ClassWithDoBinding], - PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (4,5--4,23)), - ObjectModel - (Unspecified, - [ImplicitCtor - (None, [], Const (Unit, (4,23--4,25)), None, - PreXmlDoc ((4,23), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,23), { AsKeyword = None }); - LetBindings - ([SynBinding - (None, Normal, false, true, [], - PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, - SynValInfo ([], SynArgInfo ([], false, None)), - None), - Named - (SynIdent (initialized, None), false, None, - (5,16--5,27)), None, - Const (Bool false, (5,30--5,35)), (5,16--5,27), - Yes (5,4--5,35), - { LeadingKeyword = Let (5,4--5,7) - InlineKeyword = None - EqualsRange = Some (5,28--5,29) })], false, false, - (5,4--5,35)); - LetBindings - ([SynBinding - (None, Do, false, false, [], PreXmlDocEmpty, - SynValData - (None, - SynValInfo ([], SynArgInfo ([], false, None)), - None), Const (Unit, (7,4--9,27)), None, - Sequential - (SuppressNeither, true, - App - (NonAtomic, false, Ident printfn, - Const - (String - ("Starting initialization", Regular, - (8,16--8,41)), (8,16--8,41)), - (8,8--8,41)), - LongIdentSet - (SynLongIdent ([initialized], [], [None]), - Const (Bool true, (9,23--9,27)), (9,8--9,27)), - (8,8--9,27), { SeparatorRange = None }), - (7,4--9,27), NoneAtDo, - { LeadingKeyword = Do (7,4--7,6) - InlineKeyword = None - EqualsRange = None })], false, false, (7,4--9,27))], - (5,4--9,27)), [], - Some - (ImplicitCtor - (None, [], Const (Unit, (4,23--4,25)), None, - PreXmlDoc ((4,23), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,23), { AsKeyword = None })), (4,5--9,27), - { LeadingKeyword = Type (4,0--4,4) - EqualsRange = Some (4,26--4,27) - WithKeyword = None })], (4,0--9,27)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [InternalType], - PreXmlDoc ((11,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (11,9--11,21)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([int], [], [None])), - (11,24--11,27)), (11,24--11,27)), [], None, - (11,9--11,27), { LeadingKeyword = Type (11,4--11,8) - EqualsRange = Some (11,22--11,23) - WithKeyword = None })], (11,4--11,27))], - PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--11,27), { LeadingKeyword = Module (2,0--2,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [LineComment (1,0--1,57)] }, set [])) - -(11,4)-(11,8) parse error Nested type definitions are not allowed. Types must be defined at module or namespace level. -(13,4)-(13,6) parse error Unexpected keyword 'do' in definition. Expected incomplete structured construct at or before this point or other token. -(16,4)-(16,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. -(19,4)-(19,8) parse error 'open' declarations must appear 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 index 75b768809ad..fe7a5ade2fb 100644 --- a/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs +++ b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs @@ -1,13 +1,7 @@ -// Expected: No warnings - valid in verbose syntax +// Testing: Double semicolon delimiters with invalid constructs module Module type A = - | A;; - type B = A;; - module C = ();; - exception D;; - module E = C;; - let f () = ();; - open System;; - module G = - module H = E;; + 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 index 217a5acb19a..e2bda14132e 100644 --- a/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Double Semicolon Delimiters 01.fs.bsl @@ -10,77 +10,45 @@ ImplFile ([], 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), + 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--5,7)); + WithKeyword = None })], (4,0--4,8)); Types ([SynTypeDefn (SynComponentInfo ([], None, [], [B], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (6,9--6,10)), + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,9--5,10)), Simple (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([A], [], [None])), - (6,13--6,14)), (6,13--6,14)), [], None, (6,9--6,14), - { LeadingKeyword = Type (6,4--6,8) - EqualsRange = Some (6,11--6,12) - WithKeyword = None })], (6,4--6,14)); + (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 ((7,8), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,8--7,16)), false, - [Expr (Const (Unit, (7,19--7,21)), (7,19--7,21))], false, - (7,8--7,21), { ModuleKeyword = Some (7,8--7,14) - EqualsRange = Some (7,17--7,18) }); + 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, - (8,22--8,23), { BarRange = None }), None, - PreXmlDoc ((8,12), FSharp.Compiler.Xml.XmlDocCollector), - None, (8,12--8,23)), None, [], (8,12--8,23)), (8,12--8,23)); - ModuleAbbrev (E, [C], (9,16--9,28)); - Let - (false, - [SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((10,20), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, SynValInfo ([[]], SynArgInfo ([], false, None)), None), - LongIdent - (SynLongIdent ([f], [], [None]), None, None, - Pats [Paren (Const (Unit, (10,26--10,28)), (10,26--10,28))], - None, (10,24--10,28)), None, Const (Unit, (10,31--10,33)), - (10,24--10,28), NoneAtLet, - { LeadingKeyword = Let (10,20--10,23) - InlineKeyword = None - EqualsRange = Some (10,29--10,30) })], (10,20--10,33)); - Open - (ModuleOrNamespace - (SynLongIdent ([System], [], [None]), (11,29--11,35)), - (11,24--11,35)); - NestedModule - (SynComponentInfo - ([], None, [], [G], - PreXmlDoc ((12,28), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (12,28--12,36)), false, - [ModuleAbbrev (H, [E], (13,32--13,44))], false, (12,28--13,44), - { ModuleKeyword = Some (12,28--12,34) - EqualsRange = Some (12,37--12,38) })], + (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--13,44), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--7,15), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,50)] }, set [])) + 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 index b6bde6322af..3f47a6778b8 100644 --- a/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs @@ -1,6 +1,5 @@ -// Expected: Warning for exception inside type +// Testing: Exception inside type module Module type A = - | A - exception MyException of string + 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 index efc29955a5c..887cb099c0c 100644 --- a/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Exception Inside Type 01.fs.bsl @@ -1,13 +1,34 @@ ImplFile (ParsedImplFileInput ("/root/Type/Exception Inside Type 01.fs", false, - QualifiedNameOfFile Exception Inside Type 01, [], + QualifiedNameOfFile Module, [], [SynModuleOrNamespace - ([Exception Inside Type 01], false, AnonModule, [], PreXmlDocEmpty, [], - None, (7,0--7,0), { LeadingKeyword = None })], (true, true), + ([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,46)] }, set [])) + CodeComments = [LineComment (1,0--1,33)] }, set [])) -(6,4)-(6,13) parse error Exceptions must be defined at module level, not inside types. -(6,4)-(6,13) parse error Unexpected keyword 'exception' in member definition +(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/Inherit With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs deleted file mode 100644 index 1ec3319af1c..00000000000 --- a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs +++ /dev/null @@ -1,13 +0,0 @@ -// Expected: Warning for module after inherit -module Module - -type Base() = - member _.BaseMethod() = 1 - -type Derived() = - inherit Base() - - module InvalidModule = - let x = 2 - - override _.ToString() = "Derived" diff --git a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl deleted file mode 100644 index 6a8306c2032..00000000000 --- a/tests/service/data/SyntaxTree/Type/Inherit With Invalid Constructs 01.fs.bsl +++ /dev/null @@ -1,107 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Inherit With Invalid Constructs 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 - (Unspecified, - [ImplicitCtor - (None, [], Const (Unit, (4,9--4,11)), None, - PreXmlDoc ((4,9), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,9), { 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 - ([_; BaseMethod], [(5,12--5,13)], [None; None]), - None, None, - Pats - [Paren - (Const (Unit, (5,23--5,25)), (5,23--5,25))], - None, (5,11--5,25)), None, - Const (Int32 1, (5,28--5,29)), (5,11--5,25), - NoneAtInvisible, - { LeadingKeyword = Member (5,4--5,10) - InlineKeyword = None - EqualsRange = Some (5,26--5,27) }), (5,4--5,29))], - (5,4--5,29)), [], - 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--5,29), - { LeadingKeyword = Type (4,0--4,4) - EqualsRange = Some (4,12--4,13) - WithKeyword = None })], (4,0--5,29)); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [Derived], - PreXmlDoc ((7,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (7,5--7,12)), - ObjectModel - (Unspecified, - [ImplicitCtor - (None, [], Const (Unit, (7,12--7,14)), None, - PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), - (7,5--7,12), { AsKeyword = None }); - ImplicitInherit - (LongIdent (SynLongIdent ([Base], [], [None])), - Const (Unit, (8,16--8,18)), None, (8,4--8,18), - { InheritKeyword = (8,4--8,11) })], (8,4--8,18)), [], - Some - (ImplicitCtor - (None, [], Const (Unit, (7,12--7,14)), None, - PreXmlDoc ((7,12), FSharp.Compiler.Xml.XmlDocCollector), - (7,5--7,12), { AsKeyword = None })), (7,5--8,18), - { LeadingKeyword = Type (7,0--7,4) - EqualsRange = Some (7,15--7,16) - WithKeyword = None })], (7,0--8,18)); - NestedModule - (SynComponentInfo - ([], None, [], [InvalidModule], - PreXmlDoc ((10,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (10,4--10,24)), 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 2, (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,25--10,26) })], - PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--11,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [LineComment (1,0--1,45)] }, set [])) - -(10,4)-(10,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. -(13,4)-(13,12) parse error Unexpected keyword 'override' in definition. Expected incomplete structured construct at or before this point 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 index b455cda954e..5a40ba6d234 100644 --- a/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs +++ b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs @@ -1,12 +1,6 @@ -// Expected: No warning - keywords in strings are not declarations +// Testing: Keywords in strings should be ignored module Module -type MyClass() = - let message = "This string contains type and module keywords" - let code = """ - type Example = int - module Sample = - let x = 1 - """ +type MyClass = + let message = "type and module keywords" member _.GetMessage() = message - member _.GetCode() = code 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 index a8fef977486..f42d3f23ed7 100644 --- a/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Keywords In Strings 01.fs.bsl @@ -12,11 +12,7 @@ ImplFile 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 + [LetBindings ([SynBinding (None, Normal, false, false, [], PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), @@ -29,68 +25,17 @@ ImplFile (5,8--5,15)), None, Const (String - ("This string contains type and module keywords", - Regular, (5,18--5,65)), (5,18--5,65)), - (5,8--5,15), Yes (5,4--5,65), + ("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,65)); - LetBindings - ([SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, - SynValInfo ([], SynArgInfo ([], false, None)), - None), - Named - (SynIdent (code, None), false, None, (6,8--6,12)), - None, - Const - (String - (" - type Example = int - module Sample = - let x = 1 - ", - TripleQuote, (6,15--10,7)), (6,15--10,7)), - (6,8--6,12), Yes (6,4--10,7), - { LeadingKeyword = Let (6,4--6,7) - InlineKeyword = None - EqualsRange = Some (6,13--6,14) })], false, false, - (6,4--10,7)); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((11,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], [(11,12--11,13)], - [None; None]), None, None, - Pats - [Paren - (Const (Unit, (11,23--11,25)), - (11,23--11,25))], None, (11,11--11,25)), - None, Ident message, (11,11--11,25), NoneAtInvisible, - { LeadingKeyword = Member (11,4--11,10) - InlineKeyword = None - EqualsRange = Some (11,26--11,27) }), - (11,4--11,35)); + (5,4--5,44)); Member (SynBinding (None, Normal, false, false, [], - PreXmlDoc ((12,4), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), SynValData (Some { IsInstance = true IsDispatchSlot = false @@ -103,27 +48,22 @@ ImplFile SynArgInfo ([], false, None)), None), LongIdent (SynLongIdent - ([_; GetCode], [(12,12--12,13)], [None; None]), + ([_; GetMessage], [(6,12--6,13)], [None; None]), None, None, Pats [Paren - (Const (Unit, (12,20--12,22)), - (12,20--12,22))], None, (12,11--12,22)), - None, Ident code, (12,11--12,22), NoneAtInvisible, - { LeadingKeyword = Member (12,4--12,10) + (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 (12,23--12,24) }), - (12,4--12,29))], (5,4--12,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--12,29), + 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,15--4,16) - WithKeyword = None })], (4,0--12,29))], + EqualsRange = Some (4,13--4,14) + WithKeyword = None })], (4,0--6,35))], PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--12,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--6,35), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,66)] }, set [])) + 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 index b26f9f3a2ac..a795a3c44a8 100644 --- a/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs +++ b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs @@ -1,9 +1,6 @@ -// Expected: No warning - let bindings are valid in classes +// Testing: Let bindings are valid in classes module Module type MyClass() = - let mutable privateField = 10 - let helper x = x * 2 - - member _.GetValue() = helper privateField - member _.SetValue(v) = privateField <- v + 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 index 0cd0d4ff6c3..b677479348f 100644 --- a/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Let Inside Class 01.fs.bsl @@ -17,7 +17,7 @@ ImplFile (4,5--4,12), { AsKeyword = None }); LetBindings ([SynBinding - (None, Normal, false, true, [], + (None, Normal, false, false, [], PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), SynValData (None, @@ -25,48 +25,17 @@ ImplFile None), Named (SynIdent (privateField, None), false, None, - (5,16--5,28)), None, - Const (Int32 10, (5,31--5,33)), (5,16--5,28), - Yes (5,4--5,33), + (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,29--5,30) })], false, false, - (5,4--5,33)); - LetBindings - ([SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, - SynValInfo - ([[SynArgInfo ([], false, Some x)]], - SynArgInfo ([], false, None)), None), - LongIdent - (SynLongIdent ([helper], [], [None]), None, None, - Pats - [Named - (SynIdent (x, None), false, None, - (6,15--6,16))], None, (6,8--6,16)), None, - App - (NonAtomic, false, - App - (NonAtomic, true, - LongIdent - (false, - SynLongIdent - ([op_Multiply], [], - [Some (OriginalNotation "*")]), None, - (6,21--6,22)), Ident x, (6,19--6,22)), - Const (Int32 2, (6,23--6,24)), (6,19--6,24)), - (6,8--6,16), NoneAtLet, - { LeadingKeyword = Let (6,4--6,7) - InlineKeyword = None - EqualsRange = Some (6,17--6,18) })], false, false, - (6,4--6,24)); + EqualsRange = Some (5,21--5,22) })], false, false, + (5,4--5,25)); Member (SynBinding (None, Normal, false, false, [], - PreXmlDoc ((8,4), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), SynValData (Some { IsInstance = true IsDispatchSlot = false @@ -79,62 +48,27 @@ ImplFile SynArgInfo ([], false, None)), None), LongIdent (SynLongIdent - ([_; GetValue], [(8,12--8,13)], [None; None]), - None, None, - Pats - [Paren - (Const (Unit, (8,21--8,23)), (8,21--8,23))], - None, (8,11--8,23)), None, - App - (NonAtomic, false, Ident helper, - Ident privateField, (8,26--8,45)), (8,11--8,23), - NoneAtInvisible, - { LeadingKeyword = Member (8,4--8,10) - InlineKeyword = None - EqualsRange = Some (8,24--8,25) }), (8,4--8,45)); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((9,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, Some v)]], - SynArgInfo ([], false, None)), None), - LongIdent - (SynLongIdent - ([_; SetValue], [(9,12--9,13)], [None; None]), + ([_; GetValue], [(6,12--6,13)], [None; None]), None, None, Pats [Paren - (Named - (SynIdent (v, None), false, None, - (9,22--9,23)), (9,21--9,24))], None, - (9,11--9,24)), None, - LongIdentSet - (SynLongIdent ([privateField], [], [None]), - Ident v, (9,27--9,44)), (9,11--9,24), - NoneAtInvisible, - { LeadingKeyword = Member (9,4--9,10) + (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 (9,25--9,26) }), (9,4--9,44))], - (5,4--9,44)), [], + 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--9,44), + (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--9,44))], + WithKeyword = None })], (4,0--6,38))], PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--9,44), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--6,38), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,59)] }, set [])) + CodeComments = [LineComment (1,0--1,45)] }, set [])) 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 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/Interleaved Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs similarity index 51% rename from tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs rename to tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs index afbcaadb61f..13c274c3da3 100644 --- a/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs +++ b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs @@ -1,10 +1,10 @@ -// Expected: Multiple warnings for module and exception +// Testing: Module and exception interleaved with members module Module -type Interleaved() = +type Interleaved = member _.X = 1 module M1 = let y = 2 member _.Y = 2 - exception E1 of int + exception E1 member _.Z = 3 diff --git a/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs.bsl similarity index 82% rename from tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl rename to tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs.bsl index d46bff05c3b..807b6497ad1 100644 --- a/tests/service/data/SyntaxTree/Type/Interleaved Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module And Exception Interleaved With Members 01.fs.bsl @@ -1,6 +1,6 @@ ImplFile (ParsedImplFileInput - ("/root/Type/Interleaved Invalid Constructs 01.fs", false, + ("/root/Type/Module And Exception Interleaved With Members 01.fs", false, QualifiedNameOfFile Module, [], [SynModuleOrNamespace ([Module], false, NamedModule, @@ -12,11 +12,7 @@ ImplFile 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 }); - Member + [Member (SynBinding (None, Normal, false, false, [], PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), @@ -39,14 +35,9 @@ ImplFile { LeadingKeyword = Member (5,4--5,10) InlineKeyword = None EqualsRange = Some (5,15--5,16) }), (5,4--5,18))], - (5,4--5,18)), [], - 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--5,18), + (5,4--5,18)), [], None, (4,5--5,18), { LeadingKeyword = Type (4,0--4,4) - EqualsRange = Some (4,19--4,20) + EqualsRange = Some (4,17--4,18) WithKeyword = None })], (4,0--5,18)); NestedModule (SynComponentInfo @@ -73,7 +64,7 @@ ImplFile (2,0--7,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,55)] }, set [])) + 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. 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 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/Multiple Constructors With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs.bsl similarity index 50% rename from tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl rename to tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs.bsl index 7c33267bff4..5034df6344b 100644 --- a/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Between Constructors 01.fs.bsl @@ -1,6 +1,6 @@ ImplFile (ParsedImplFileInput - ("/root/Type/Multiple Constructors With Invalid Constructs 01.fs", false, + ("/root/Type/Module Between Constructors 01.fs", false, QualifiedNameOfFile Module, [], [SynModuleOrNamespace ([Module], false, NamedModule, @@ -17,32 +17,15 @@ ImplFile Paren (Typed (Named - (SynIdent (primary, None), false, None, - (4,13--4,20)), + (SynIdent (x, None), false, None, (4,13--4,14)), LongIdent (SynLongIdent ([int], [], [None])), - (4,13--4,25)), (4,12--4,26)), None, + (4,13--4,19)), (4,12--4,20)), None, PreXmlDoc ((4,12), FSharp.Compiler.Xml.XmlDocCollector), (4,5--4,12), { AsKeyword = None }); - LetBindings - ([SynBinding - (None, Normal, false, true, [], - PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, - SynValInfo ([], SynArgInfo ([], false, None)), - None), - Named - (SynIdent (value, None), false, None, - (5,16--5,21)), None, Ident primary, (5,16--5,21), - Yes (5,4--5,31), - { LeadingKeyword = Let (5,4--5,7) - InlineKeyword = None - EqualsRange = Some (5,22--5,23) })], false, false, - (5,4--5,31)); Member (SynBinding (None, Normal, false, false, [], - PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), SynValData (Some { IsInstance = false IsDispatchSlot = false @@ -56,59 +39,58 @@ ImplFile (SynLongIdent ([new], [], [None]), None, Some (SynValTyparDecls (None, false)), Pats - [Paren (Const (Unit, (7,7--7,9)), (7,7--7,9))], - None, (7,4--7,7)), None, + [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, (7,20--7,21)), (7,19--7,20), - Some (7,21--7,22), (7,19--7,22)), (7,12--7,22)), - (7,4--7,9), NoneAtInvisible, - { LeadingKeyword = New (7,4--7,7) + (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 (7,10--7,11) }), (7,4--7,22))], - (5,4--7,22)), [], + EqualsRange = Some (5,10--5,11) }), (5,4--5,22))], + (5,4--5,22)), [], Some (ImplicitCtor (None, [], Paren (Typed (Named - (SynIdent (primary, None), false, None, - (4,13--4,20)), + (SynIdent (x, None), false, None, (4,13--4,14)), LongIdent (SynLongIdent ([int], [], [None])), - (4,13--4,25)), (4,12--4,26)), 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--7,22), + (4,5--4,12), { AsKeyword = None })), (4,5--5,22), { LeadingKeyword = Type (4,0--4,4) - EqualsRange = Some (4,27--4,28) - WithKeyword = None })], (4,0--7,22)); + EqualsRange = Some (4,21--4,22) + WithKeyword = None })], (4,0--5,22)); NestedModule (SynComponentInfo ([], None, [], [InvalidModule], - PreXmlDoc ((9,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (9,4--9,24)), false, + PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (7,4--7,24)), false, [Let (false, [SynBinding (None, Normal, false, false, [], - PreXmlDoc ((10,8), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((8,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 1, (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) })], + 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--10,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--8,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,52)] }, set [])) + CodeComments = [LineComment (1,0--1,39)] }, set [])) -(9,4)-(9,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. -(12,4)-(12,7) parse error Unexpected keyword 'new' in definition. Expected incomplete structured construct at or before this point or other token. +(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 With Constructor 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Class With Constructor 01.fs index ec2476b7c00..2253f9c1b59 100644 --- 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 @@ -1,8 +1,6 @@ -// Expected: Warning for module inside class with constructor +// Testing: Module inside class with constructor module Module type MyClass(x: int) = - let mutable value = x - member _.Value = value module InternalModule = - let helper() = 42 + 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 index 10f12be832f..b343a4bfd88 100644 --- 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 @@ -21,46 +21,7 @@ ImplFile 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 }); - LetBindings - ([SynBinding - (None, Normal, false, true, [], - PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), - SynValData - (None, - SynValInfo ([], SynArgInfo ([], false, None)), - None), - Named - (SynIdent (value, None), false, None, - (5,16--5,21)), None, Ident x, (5,16--5,21), - Yes (5,4--5,25), - { LeadingKeyword = Let (5,4--5,7) - InlineKeyword = None - EqualsRange = Some (5,22--5,23) })], 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 - ([_; Value], [(6,12--6,13)], [None; None]), - None, None, Pats [], None, (6,11--6,18)), None, - Ident value, (6,11--6,18), NoneAtInvisible, - { LeadingKeyword = Member (6,4--6,10) - InlineKeyword = None - EqualsRange = Some (6,19--6,20) }), (6,4--6,26))], - (5,4--6,26)), [], + (4,5--4,12), { AsKeyword = None })], (4,5--4,22)), [], Some (ImplicitCtor (None, [], @@ -71,37 +32,36 @@ ImplFile 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--6,26), + (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--6,26)); + WithKeyword = None })], (4,0--4,22)); NestedModule (SynComponentInfo ([], None, [], [InternalModule], - PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), false, - None, (7,4--7,25)), false, + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), false, + None, (5,4--5,25)), false, [Let (false, [SynBinding (None, Normal, false, false, [], - PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), SynValData - (None, SynValInfo ([[]], SynArgInfo ([], false, None)), + (None, SynValInfo ([], SynArgInfo ([], false, None)), None), - LongIdent - (SynLongIdent ([helper], [], [None]), None, None, - Pats [Paren (Const (Unit, (8,18--8,20)), (8,18--8,20))], - None, (8,12--8,20)), None, - Const (Int32 42, (8,23--8,25)), (8,12--8,20), NoneAtLet, - { LeadingKeyword = Let (8,8--8,11) - InlineKeyword = None - EqualsRange = Some (8,21--8,22) })], (8,8--8,25))], - false, (7,4--8,25), { ModuleKeyword = Some (7,4--7,10) - EqualsRange = Some (7,26--7,27) })], + 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--8,25), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--6,23), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,61)] }, set [])) + CodeComments = [LineComment (1,0--1,48)] }, set [])) -(7,4)-(7,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(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 Struct 01.fs b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs index 6d15ab44043..0eff7380d47 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs @@ -1,9 +1,8 @@ -// Expected: Warning for module inside struct +// Testing: Module inside struct module Module -[] type MyStruct = - val X: int - val Y: int - module InvalidModule = - let helper = 10 + 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 index 021c379d909..38b44cf5f9f 100644 --- a/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Module Inside Struct 01.fs.bsl @@ -7,62 +7,19 @@ ImplFile [Types ([SynTypeDefn (SynComponentInfo - ([{ Attributes = - [{ TypeName = SynLongIdent ([Struct], [], [None]) - ArgExpr = Const (Unit, (4,2--4,8)) - Target = None - AppliesToGetterAndSetter = false - Range = (4,2--4,8) }] - Range = (4,0--4,10) }], None, [], [MyStruct], + ([], None, [], [MyStruct], PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,5--5,13)), - ObjectModel - (Unspecified, - [ValField - (SynField - ([], false, Some X, - LongIdent (SynLongIdent ([int], [], [None])), false, - PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (6,4--6,14), - { LeadingKeyword = Some (Val (6,4--6,7)) - MutableKeyword = None }), (6,4--6,14)); - ValField - (SynField - ([], false, Some Y, - LongIdent (SynLongIdent ([int], [], [None])), false, - PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), - None, (7,4--7,14), - { LeadingKeyword = Some (Val (7,4--7,7)) - MutableKeyword = None }), (7,4--7,14))], - (6,4--7,14)), [], None, (4,0--7,14), - { LeadingKeyword = Type (5,0--5,4) - EqualsRange = Some (5,14--5,15) - WithKeyword = None })], (4,0--7,14)); - 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) })], + 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--9,23), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--5,10), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,45)] }, set [])) + CodeComments = [LineComment (1,0--1,32)] }, set [])) -(8,4)-(8,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(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/Multiple Constructors With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs deleted file mode 100644 index 2ea7fba463e..00000000000 --- a/tests/service/data/SyntaxTree/Type/Multiple Constructors With Invalid Constructs 01.fs +++ /dev/null @@ -1,14 +0,0 @@ -// Expected: Warning for module between constructors -module Module - -type MyClass(primary: int) = - let mutable value = primary - - new() = MyClass(0) - - module InvalidModule = - let x = 1 - - new(s: string) = MyClass(int s) - - member _.Value = value diff --git a/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs index 75cba2f0d9e..f9ad5ba9673 100644 --- a/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs @@ -1,17 +1,9 @@ -// Expected: Warning for module inside type at deep nesting level +// Testing: Module inside type at deep nesting level module Root module Level1 = - type ValidType1 = int - module Level2 = - type ValidType2 = string - module Level3 = type TypeWithInvalidModule = - | A - | B module InvalidModule = let x = 1 - - type ValidType3 = float 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 index 8faff222172..14fa4838071 100644 --- a/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Type/Nested Module Hierarchy 01.fs.bsl @@ -9,118 +9,63 @@ ImplFile ([], None, [], [Level1], PreXmlDoc ((4,0), FSharp.Compiler.Xml.XmlDocCollector), false, None, (4,0--4,13)), false, - [Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [ValidType1], - PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (5,9--5,19)), - Simple - (TypeAbbrev - (Ok, LongIdent (SynLongIdent ([int], [], [None])), - (5,22--5,25)), (5,22--5,25)), [], None, (5,9--5,25), - { LeadingKeyword = Type (5,4--5,8) - EqualsRange = Some (5,20--5,21) - WithKeyword = None })], (5,4--5,25)); - NestedModule + [NestedModule (SynComponentInfo ([], None, [], [Level2], - PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (7,4--7,17)), false, - [Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [ValidType2], - PreXmlDoc ((8,8), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (8,13--8,23)), - Simple - (TypeAbbrev - (Ok, - LongIdent (SynLongIdent ([string], [], [None])), - (8,26--8,32)), (8,26--8,32)), [], None, - (8,13--8,32), { LeadingKeyword = Type (8,8--8,12) - EqualsRange = Some (8,24--8,25) - WithKeyword = None })], (8,8--8,32)); - NestedModule + PreXmlDoc ((5,4), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (5,4--5,17)), false, + [NestedModule (SynComponentInfo ([], None, [], [Level3], - PreXmlDoc ((10,8), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (10,8--10,21)), false, + PreXmlDoc ((6,8), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (6,8--6,21)), false, [Types ([SynTypeDefn (SynComponentInfo ([], None, [], [TypeWithInvalidModule], - PreXmlDoc ((11,12), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (11,17--11,38)), - Simple - (Union - (None, - [SynUnionCase - ([], SynIdent (A, None), Fields [], - PreXmlDoc ((12,16), FSharp.Compiler.Xml.XmlDocCollector), - None, (12,18--12,19), - { BarRange = Some (12,16--12,17) }); - SynUnionCase - ([], SynIdent (B, None), Fields [], - PreXmlDoc ((13,16), FSharp.Compiler.Xml.XmlDocCollector), - None, (13,18--13,19), - { BarRange = Some (13,16--13,17) })], - (12,16--13,19)), (12,16--13,19)), [], None, - (11,17--13,19), - { LeadingKeyword = Type (11,12--11,16) - EqualsRange = Some (11,39--11,40) - WithKeyword = None })], (11,12--13,19)); + 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 ((14,16), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (14,16--14,36)), false, + PreXmlDoc ((8,16), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (8,16--8,36)), false, [Let (false, [SynBinding (None, Normal, false, false, [], - PreXmlDoc ((15,20), FSharp.Compiler.Xml.XmlDocCollector), + PreXmlDoc ((9,20), FSharp.Compiler.Xml.XmlDocCollector), SynValData (None, SynValInfo ([], SynArgInfo ([], false, None)), None), Named (SynIdent (x, None), false, None, - (15,24--15,25)), None, - Const (Int32 1, (15,28--15,29)), - (15,24--15,25), Yes (15,20--15,29), - { LeadingKeyword = Let (15,20--15,23) + (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 (15,26--15,27) })], - (15,20--15,29))], false, (14,16--15,29), - { ModuleKeyword = Some (14,16--14,22) - EqualsRange = Some (14,37--14,38) }); - Types - ([SynTypeDefn - (SynComponentInfo - ([], None, [], [ValidType3], - PreXmlDoc ((17,12), FSharp.Compiler.Xml.XmlDocCollector), - false, None, (17,17--17,27)), - Simple - (TypeAbbrev - (Ok, - LongIdent - (SynLongIdent ([float], [], [None])), - (17,30--17,35)), (17,30--17,35)), [], None, - (17,17--17,35), - { LeadingKeyword = Type (17,12--17,16) - EqualsRange = Some (17,28--17,29) - WithKeyword = None })], (17,12--17,35))], false, - (10,8--17,35), { ModuleKeyword = Some (10,8--10,14) - EqualsRange = Some (10,22--10,23) })], - false, (7,4--17,35), { ModuleKeyword = Some (7,4--7,10) - EqualsRange = Some (7,18--7,19) })], - false, (4,0--17,35), { ModuleKeyword = Some (4,0--4,6) - EqualsRange = Some (4,14--4,15) })], + 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--17,35), { LeadingKeyword = Module (2,0--2,6) })], (true, true), + (2,0--9,29), { LeadingKeyword = Module (2,0--2,6) })], (true, true), { ConditionalDirectives = [] WarnDirectives = [] - CodeComments = [LineComment (1,0--1,65)] }, set [])) + CodeComments = [LineComment (1,0--1,52)] }, set [])) -(14,16)-(14,22) parse error Modules cannot be nested inside types. Define modules at module or namespace level. +(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/Static Members With Invalid Constructs 01.fs b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs deleted file mode 100644 index 2323679878b..00000000000 --- a/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs +++ /dev/null @@ -1,11 +0,0 @@ -// Expected: Warning for module after static members -module Module - -type MyType() = - static member StaticMethod() = 42 - static member StaticProperty = "hello" - - module InvalidModule = - let x = 1 - - static member AnotherStatic() = true diff --git a/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl b/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl deleted file mode 100644 index f49f7405fd4..00000000000 --- a/tests/service/data/SyntaxTree/Type/Static Members With Invalid Constructs 01.fs.bsl +++ /dev/null @@ -1,105 +0,0 @@ -ImplFile - (ParsedImplFileInput - ("/root/Type/Static Members With Invalid Constructs 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, - [ImplicitCtor - (None, [], Const (Unit, (4,11--4,13)), None, - PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,11), { 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 = 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)); - Member - (SynBinding - (None, Normal, false, false, [], - PreXmlDoc ((6,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 ([StaticProperty], [], [None]), None, - None, Pats [], None, (6,18--6,32)), None, - Const - (String ("hello", Regular, (6,35--6,42)), - (6,35--6,42)), (6,18--6,32), NoneAtInvisible, - { LeadingKeyword = - StaticMember ((6,4--6,10), (6,11--6,17)) - InlineKeyword = None - EqualsRange = Some (6,33--6,34) }), (6,4--6,42))], - (5,4--6,42)), [], - Some - (ImplicitCtor - (None, [], Const (Unit, (4,11--4,13)), None, - PreXmlDoc ((4,11), FSharp.Compiler.Xml.XmlDocCollector), - (4,5--4,11), { AsKeyword = None })), (4,5--6,42), - { LeadingKeyword = Type (4,0--4,4) - EqualsRange = Some (4,14--4,15) - WithKeyword = None })], (4,0--6,42)); - 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 (x, None), false, None, (9,12--9,13)), - None, Const (Int32 1, (9,16--9,17)), (9,12--9,13), - Yes (9,8--9,17), { LeadingKeyword = Let (9,8--9,11) - InlineKeyword = None - EqualsRange = Some (9,14--9,15) })], - (9,8--9,17))], false, (8,4--9,17), - { ModuleKeyword = Some (8,4--8,10) - EqualsRange = Some (8,25--8,26) })], - PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, - (2,0--9,17), { LeadingKeyword = Module (2,0--2,6) })], (true, true), - { ConditionalDirectives = [] - WarnDirectives = [] - CodeComments = [LineComment (1,0--1,52)] }, set [])) - -(8,4)-(8,10) parse error Modules cannot be nested inside types. Define modules at module or namespace level. -(11,4)-(11,10) parse error Unexpected keyword 'static' in definition. Expected incomplete structured construct at or before this point or other token. From 958915816dc42ef6a248a126fa619dab2aa30cd2 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 22:48:20 +0100 Subject: [PATCH 30/36] update baselines --- tests/fsharp/typecheck/sigs/neg17.bsl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/fsharp/typecheck/sigs/neg17.bsl b/tests/fsharp/typecheck/sigs/neg17.bsl index 673e0b7ec78..72208e93c35 100644 --- a/tests/fsharp/typecheck/sigs/neg17.bsl +++ b/tests/fsharp/typecheck/sigs/neg17.bsl @@ -1,4 +1,6 @@ +neg17.fs(70,5,70,9): parse error FS0058: Nested type definitions are not allowed. Types must be defined at module or namespace level. + neg17.fs(84,17,84,33): typecheck error FS0292: The type definitions for type 'PrivateUnionType' in the signature and implementation are not compatible because the accessibility specified in the signature is more than that specified in the implementation neg17b.fs(7,17,7,31): typecheck error FS1094: The value 'privateValue' is not accessible from this code location From efe20da86a4f34ef0343f5171f9dcbbf35cf7799 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 23:28:20 +0100 Subject: [PATCH 31/36] fix indentation issue found thanks to the new error --- tests/fsharp/typecheck/sigs/neg17.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 76426291202c20085af7c5f3bc09e6046230c082 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Thu, 14 Aug 2025 23:28:29 +0100 Subject: [PATCH 32/36] update release notes --- docs/release-notes/.FSharp.Compiler.Service/10.0.100.md | 2 +- docs/release-notes/.Language/preview.md | 2 +- tests/fsharp/typecheck/sigs/neg17.bsl | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) 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 46389322a38..7440c715167 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md @@ -17,7 +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)) -* Warn when a module definition is encountered inside a type definition.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) +* 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 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 6dfc1f5eecf..fcec4b8170e 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -15,6 +15,6 @@ ### Fixed * Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816)) -* Warn when a module definition is encountered inside a type definition.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813)) +* 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/tests/fsharp/typecheck/sigs/neg17.bsl b/tests/fsharp/typecheck/sigs/neg17.bsl index 72208e93c35..673e0b7ec78 100644 --- a/tests/fsharp/typecheck/sigs/neg17.bsl +++ b/tests/fsharp/typecheck/sigs/neg17.bsl @@ -1,6 +1,4 @@ -neg17.fs(70,5,70,9): parse error FS0058: Nested type definitions are not allowed. Types must be defined at module or namespace level. - neg17.fs(84,17,84,33): typecheck error FS0292: The type definitions for type 'PrivateUnionType' in the signature and implementation are not compatible because the accessibility specified in the signature is more than that specified in the implementation neg17b.fs(7,17,7,31): typecheck error FS1094: The value 'privateValue' is not accessible from this code location From a412c6bdd6093979bfbe0c0f8108f546b1a86693 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Fri, 15 Aug 2025 10:00:46 +0100 Subject: [PATCH 33/36] more bsl --- tests/fsharp/typecheck/sigs/neg01.bsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/fsharp/typecheck/sigs/neg01.bsl b/tests/fsharp/typecheck/sigs/neg01.bsl index 80b8b22daf3..a9b96b2f711 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. From adcd37368de16643c080d9d22c3357632630ca5f Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Fri, 15 Aug 2025 16:14:53 +0100 Subject: [PATCH 34/36] more test updates --- .../ErrorOnInvalidDeclsInTypeDefinitions.fs | 42 +++++++++++++++++++ tests/fsharp/typecheck/sigs/neg01.bsl | 6 +++ 2 files changed, 48 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs index 823d46466f3..a9ea57ad5b7 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ErrorOnInvalidDeclsInTypeDefinitions.fs @@ -23,6 +23,48 @@ type IFace = (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 """ diff --git a/tests/fsharp/typecheck/sigs/neg01.bsl b/tests/fsharp/typecheck/sigs/neg01.bsl index a9b96b2f711..cbc82129641 100644 --- a/tests/fsharp/typecheck/sigs/neg01.bsl +++ b/tests/fsharp/typecheck/sigs/neg01.bsl @@ -2,3 +2,9 @@ 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. \ No newline at end of file From 0a9331a48f852f46e6fb710cd36a4f71f9c870d7 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Tue, 19 Aug 2025 10:48:10 +0100 Subject: [PATCH 35/36] update tests --- tests/fsharp/typecheck/sigs/neg01.bsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/fsharp/typecheck/sigs/neg01.bsl b/tests/fsharp/typecheck/sigs/neg01.bsl index cbc82129641..145d0a9f4af 100644 --- a/tests/fsharp/typecheck/sigs/neg01.bsl +++ b/tests/fsharp/typecheck/sigs/neg01.bsl @@ -3,6 +3,10 @@ neg01a.fsi(24,15,24,19): parse error FS0058: Nested type definitions are not all 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,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 From e42398cfd5968b756c9710d91bdf82d045039125 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 20 Aug 2025 07:33:02 +0100 Subject: [PATCH 36/36] fix bsl --- tests/fsharp/typecheck/sigs/neg01.bsl | 12 +----------- tests/fsharp/typecheck/sigs/neg01.vsbsl | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 tests/fsharp/typecheck/sigs/neg01.vsbsl diff --git a/tests/fsharp/typecheck/sigs/neg01.bsl b/tests/fsharp/typecheck/sigs/neg01.bsl index 145d0a9f4af..1ee82bcc91b 100644 --- a/tests/fsharp/typecheck/sigs/neg01.bsl +++ b/tests/fsharp/typecheck/sigs/neg01.bsl @@ -1,14 +1,4 @@ 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,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. \ No newline at end of file +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.