From 1799aaf29034f01357684c7716b6eed8fc76468a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 23 Apr 2025 15:27:24 +0100 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 fbb5679c95a10b23fbaea14be744f4fc531a4586 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Fri, 6 Jun 2025 15:54:12 +0100 Subject: [PATCH 7/8] Add error recovery tests --- .../ErrorMessages/AbbreviationTests.fs | 197 ++++++++++++++++++ .../ErrorMessages/NamespaceTests.fs | 67 ++++++ .../ErrorMessages/UnitOfMeasureTests.fs | 197 ++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 2 + 4 files changed, 463 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs new file mode 100644 index 00000000000..062caa72571 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs @@ -0,0 +1,197 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module ErrorMessages.AbbreviationTests + +open Xunit +open FSharp.Test.Compiler + +[] +let ``Type abbreviations with members should report all member errors`` () = + Fsx """ +type StringAlias = string + +type StringAlias with + member x.Length = x.Length + member x.ToUpper() = x.ToUpper() + static member Parse(s) = s + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 4, Col 6, Line 4, Col 17, "Type abbreviations cannot have augmentations") + (Error 895, Line 5, Col 5, Line 5, Col 31, "Type abbreviations cannot have members") + (Error 895, Line 6, Col 5, Line 6, Col 37, "Type abbreviations cannot have members") + (Error 895, Line 7, Col 5, Line 7, Col 31, "Type abbreviations cannot have members") + ] + +[] +let ``Type abbreviations with interface declarations should report all errors`` () = + Fsx """ +type IntAlias = int + +type IntAlias with + interface System.IComparable with + member x.CompareTo(obj) = 0 + interface System.IFormattable with + member x.ToString(format, provider) = "" + member x.Value = x + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 4, Col 6, Line 4, Col 14, "Type abbreviations cannot have augmentations") + (Error 906, Line 5, Col 15, Line 5, Col 33, "Type abbreviations cannot have interface declarations") + (Error 909, Line 5, Col 15, Line 5, Col 33, "All implemented interfaces should be declared on the initial declaration of the type") + ] + +[] +let ``Type abbreviations with mixed members and interfaces should report all errors`` () = + Fsx """ +type FloatAlias = float + +type FloatAlias with + member x.IsNaN = System.Double.IsNaN(x) + interface System.IConvertible + static member Zero = 0.0 + member x.Sqrt() = sqrt x + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 4, Col 6, Line 4, Col 16, "Type abbreviations cannot have augmentations") + (Error 906, Line 6, Col 15, Line 6, Col 34, "Type abbreviations cannot have interface declarations") + (Error 909, Line 6, Col 15, Line 6, Col 34, "All implemented interfaces should be declared on the initial declaration of the type") + ] + +[] +let ``Multiple type abbreviations with errors should all be reported`` () = + Fsx """ +type ListAlias = int list +type ArrayAlias = string[] +type OptionAlias = int option + +type ListAlias with + member x.Head = x.Head + member x.Tail = x.Tail + +type ArrayAlias with + member x.Length = x.Length + interface System.Collections.IEnumerable with + member x.GetEnumerator() = null + +type OptionAlias with + member x.IsSome = x.IsSome + member x.IsNone = x.IsNone + static member None = None + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 6, Col 6, Line 6, Col 15, "Type abbreviations cannot have augmentations") + (Error 895, Line 7, Col 5, Line 7, Col 27, "Type abbreviations cannot have members") + (Error 895, Line 8, Col 5, Line 8, Col 27, "Type abbreviations cannot have members") + (Error 964, Line 10, Col 6, Line 10, Col 16, "Type abbreviations cannot have augmentations") + (Error 906, Line 12, Col 15, Line 12, Col 45, "Type abbreviations cannot have interface declarations") + (Error 909, Line 12, Col 15, Line 12, Col 45, "All implemented interfaces should be declared on the initial declaration of the type") + (Error 964, Line 15, Col 6, Line 15, Col 17, "Type abbreviations cannot have augmentations") + (Error 895, Line 16, Col 5, Line 16, Col 31, "Type abbreviations cannot have members") + (Error 895, Line 17, Col 5, Line 17, Col 31, "Type abbreviations cannot have members") + (Error 895, Line 18, Col 5, Line 18, Col 30, "Type abbreviations cannot have members") + (Error 1198, Line 18, Col 19, Line 18, Col 23, "The generic member 'None' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.") + + ] + +[] +let ``Nested type abbreviations with augmentations should all report errors`` () = + Fsx """ +namespace Test + +type Alias1 = int + +module Nested = + type Alias2 = string + + type Alias1 with + member x.Value = x // Error + + type Alias2 with + member x.Length = x.Length // Error + interface System.IComparable with // Error + member x.CompareTo(obj) = 0 + +open Nested + +type Alias2 with + member x.ToUpper() = x.ToUpper() // Error + static member Empty = "" // Error + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 9, Col 10, Line 9, Col 16, "Type abbreviations cannot have augmentations"); + (Error 895, Line 10, Col 9, Line 10, Col 27, "Type abbreviations cannot have members"); + (Error 964, Line 12, Col 10, Line 12, Col 16, "Type abbreviations cannot have augmentations"); + (Error 906, Line 14, Col 19, Line 14, Col 37, "Type abbreviations cannot have interface declarations"); + (Error 909, Line 14, Col 19, Line 14, Col 37, "All implemented interfaces should be declared on the initial declaration of the type"); + (Error 964, Line 19, Col 6, Line 19, Col 12, "Type abbreviations cannot have augmentations"); + (Error 895, Line 20, Col 5, Line 20, Col 37, "Type abbreviations cannot have members"); + (Error 644, Line 20, Col 14, Line 20, Col 21, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members."); + (Error 895, Line 21, Col 5, Line 21, Col 29, "Type abbreviations cannot have members"); + (Error 644, Line 21, Col 19, Line 21, Col 24, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members.") + ] + +[] +let ``Generic type abbreviations with augmentations should report all errors`` () = + Fsx """ +type Result<'T> = Result<'T, string> +type MyList<'a> = 'a list + +type Result<'T> with + member x.IsOk = match x with Ok _ -> true | Error _ -> false + member x.IsError = not x.IsOk + static member Ok(value) = Ok value + +type MyList<'a> with + member x.Head = List.head x + member x.Tail = List.tail x + interface seq<'a> with + member x.GetEnumerator() = (x :> seq<'a>).GetEnumerator() + interface System.Collections.IEnumerable with + member x.GetEnumerator() = (x :> System.Collections.IEnumerable).GetEnumerator() + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 5, Col 6, Line 5, Col 12, "Type abbreviations cannot have augmentations"); + (Error 895, Line 6, Col 5, Line 6, Col 65, "Type abbreviations cannot have members"); + (Error 895, Line 7, Col 5, Line 7, Col 34, "Type abbreviations cannot have members"); + (Error 895, Line 8, Col 5, Line 8, Col 39, "Type abbreviations cannot have members"); + (Error 1198, Line 8, Col 19, Line 8, Col 21, "The generic member 'Ok' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints."); + (Error 964, Line 10, Col 6, Line 10, Col 12, "Type abbreviations cannot have augmentations"); + (Error 906, Line 13, Col 15, Line 13, Col 22, "Type abbreviations cannot have interface declarations"); + (Error 909, Line 13, Col 15, Line 13, Col 22, "All implemented interfaces should be declared on the initial declaration of the type") + ] + +[] +let ``Type abbreviations with property getters and setters should report all errors`` () = + Fsx """ +type IntRef = int ref + +type IntRef with + member x.Value + with get() = !x + and set(v) = x := v + member x.Increment() = x := !x + 1 + member x.Decrement() = x := !x - 1 + static member Zero = ref 0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 4, Col 6, Line 4, Col 12, "Type abbreviations cannot have augmentations") + (Error 895, Line 5, Col 5, Line 6, Col 1, "Type abbreviations cannot have members") + (Error 895, Line 8, Col 5, Line 8, Col 39, "Type abbreviations cannot have members") + (Error 895, Line 9, Col 5, Line 9, Col 39, "Type abbreviations cannot have members") + (Error 895, Line 10, Col 5, Line 10, Col 31, "Type abbreviations cannot have members") + (Error 1198, Line 10, Col 19, Line 10, Col 23, "The generic member 'Zero' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs new file mode 100644 index 00000000000..4336b23bd4f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module ErrorMessages.NamespaceTests + +open Xunit +open FSharp.Test.Compiler + +[] +let ``Namespace cannot contain value bindings - multiple let bindings`` () = + Fsx """ +namespace TestNamespace + +let x = 1 +let y = 2 +let z = 3 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 5, Col 5, Line 5, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 6, Col 5, Line 6, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + ] + +[] +let ``Namespace cannot contain function bindings`` () = + Fsx """ +namespace TestNamespace + +let add x y = x + y +let multiply x y = x * y +let divide x y = x / y + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 201, Line 4, Col 5, Line 4, Col 12, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 5, Col 5, Line 5, Col 17, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 6, Col 5, Line 6, Col 15, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + ] + +[] +let ``Multiple namespaces with value bindings should all report errors`` () = + Fsx """ +namespace Namespace1 + +let x = 1 + +namespace Namespace2 + +let y = 2 +do printfn "test" + +namespace Namespace3 + +let z = 3 +let w = 4 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 8, Col 5, Line 8, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 9, Col 1, Line 9, Col 18, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 13, Col 5, Line 13, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 14, Col 5, Line 14, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs index 36ef76e772d..9f2f8ad47e6 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs @@ -50,3 +50,200 @@ type FooExt = |> typecheck |> shouldSucceed + +[] +let ``Measure types with instance members should report multiple errors`` () = + Fsx """ +[] +type kg = + member x.Value = 1.0 + member x.GetWeight() = 2.0 + member x.Property = 3.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 897, Line 4, Col 5, Line 4, Col 25, "Measure declarations may have only static members") + (Error 897, Line 5, Col 5, Line 5, Col 31, "Measure declarations may have only static members") + (Error 897, Line 6, Col 5, Line 6, Col 28, "Measure declarations may have only static members") + ] + +[] +let ``Measure types with constructors should report all constructor errors`` () = + Fsx """ +[] +type meter = + new() = { } + new(x: int) = { } + member x.Value = 1.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 904, Line 4, Col 5, Line 4, Col 16, "Measure declarations may have only static members: constructors are not available") + (Error 904, Line 5, Col 5, Line 5, Col 22, "Measure declarations may have only static members: constructors are not available") + (Error 897, Line 6, Col 5, Line 6, Col 25, "Measure declarations may have only static members") + ] + +[] +let ``Measure types with type parameters should report error`` () = + Fsx """ +[] +type meter<'a> = + class end + +[] +type second<'a, 'b> = + class end + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 928, Line 3, Col 6, Line 3, Col 11, "Measure definitions cannot have type parameters"); + (Error 928, Line 7, Col 6, Line 7, Col 12, "Measure definitions cannot have type parameters") + ] + +[] +let ``Measure types with inherit declarations should report error`` () = + Fsx """ +[] +type Fahrenheit = + inherit Foo() + member x.Value = 1.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 962, Line 4, Col 5, Line 4, Col 18, "This 'inherit' declaration has arguments, but is not in a type with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.") + (Error 39, Line 4, Col 13, Line 4, Col 16, "The type 'Foo' is not defined.") + (Error 897, Line 4, Col 5, Line 4, Col 18, "Measure declarations may have only static members") + (Error 897, Line 5, Col 5, Line 5, Col 25, "Measure declarations may have only static members") + ] + +[] +let ``Measure types with instance let bindings should report multiple errors`` () = + Fsx """ +[] +type Celsius = + let instanceValue = 10 + let mutable mut = 20 + do printfn "init" + static member Valid = 30 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 963, Line 4, Col 5, Line 4, Col 27, "This definition may only be used in a type with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.") + (Error 897, Line 4, Col 5, Line 4, Col 27, "Measure declarations may have only static members") + (Error 897, Line 5, Col 5, Line 5, Col 25, "Measure declarations may have only static members") + (Error 897, Line 6, Col 5, Line 6, Col 22, "Measure declarations may have only static members") + ] + +[] +let ``Measure types with mixed valid and invalid members should report only errors`` () = + Fsx """ +[] +type Kelvin = + static member AbsoluteZero = -273.15 // OK + member x.Value = 0.0 // Error: instance member + static member Convert(c: float) = c + 273.15 // OK + new() = { } // Error: constructor + static let cache = System.Collections.Generic.Dictionary() // OK + member x.GetKelvin() = x.Value // Error: instance member +and [] Celsius + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 897, Line 5, Col 5, Line 5, Col 25, "Measure declarations may have only static members") + (Error 904, Line 7, Col 5, Line 7, Col 16, "Measure declarations may have only static members: constructors are not available") + (Error 897, Line 9, Col 5, Line 9, Col 35, "Measure declarations may have only static members") + (Error 1, Line 6, Col 52, Line 6, Col 66, "The unit of measure 'Kelvin' does not match the unit of measure 'Celsius'") + (Error 43, Line 6, Col 50, Line 6, Col 51, "The unit of measure 'Kelvin' does not match the unit of measure 'Celsius'") + ] + +[] +let ``Measure type in class with implicit constructor should report all errors`` () = + Fsx """ +[] +type newton() = + let force = 10.0 + member x.Force = force + static member Valid = 1.0 // OK + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 897, Line 3, Col 6, Line 3, Col 12, "Measure declarations may have only static members") + (Error 897, Line 4, Col 5, Line 4, Col 21, "Measure declarations may have only static members") + (Error 897, Line 5, Col 5, Line 5, Col 27, "Measure declarations may have only static members") + ] + +[] +let ``Measure type augmentations with invalid members should report all errors`` () = + Fsx """ +[] +type joule + +type joule with + member x.Energy = 1.0 + new() = { } + member x.GetEnergy() = 2.0 + static member Valid = 3.0 // OK + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 897, Line 6, Col 5, Line 6, Col 26, "Measure declarations may have only static members") + (Error 904, Line 7, Col 5, Line 7, Col 16, "Measure declarations may have only static members: constructors are not available") + (Error 897, Line 8, Col 5, Line 8, Col 31, "Measure declarations may have only static members") + ] + +[] +let ``Complex measure type with multiple error types should report all`` () = + Fsx """ +[] +type pascal<'a> = + inherit System.Object() + new() = { } + new(x: int) = { } + member x.Pressure = pressure + member x.SetPressure(p) = pressure <- p + interface System.IComparable with + member x.CompareTo(obj) = 0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 962, Line 4, Col 5, Line 4, Col 28, "This 'inherit' declaration has arguments, but is not in a type with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.") + (Error 928, Line 3, Col 6, Line 3, Col 12, "Measure definitions cannot have type parameters") + (Error 897, Line 4, Col 5, Line 4, Col 28, "Measure declarations may have only static members") + (Error 904, Line 5, Col 5, Line 5, Col 16, "Measure declarations may have only static members: constructors are not available") + (Error 904, Line 6, Col 5, Line 6, Col 22, "Measure declarations may have only static members: constructors are not available") + (Error 897, Line 7, Col 5, Line 7, Col 33, "Measure declarations may have only static members") + (Error 897, Line 8, Col 5, Line 8, Col 44, "Measure declarations may have only static members") + (Error 897, Line 10, Col 9, Line 10, Col 36, "Measure declarations may have only static members") + (Error 39, Line 7, Col 25, Line 7, Col 33, "The value or constructor 'pressure' is not defined.") + (Error 39, Line 8, Col 31, Line 8, Col 39, "The value or constructor 'pressure' is not defined.") + ] + +[] +let ``Measure type with static and instance let bindings in wrong order`` () = + Fsx """ +[] +type volt = + static let y = 2 // OK + let z = 3 + member this.Voltage = 0.0 + static member Current = 1.0 // OK + do printfn "hello" + static do printfn "world" // OK + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 960, Line 8, Col 5, Line 8, Col 23, "'let' and 'do' bindings must come before member and interface definitions in type definitions") + (Error 897, Line 5, Col 5, Line 5, Col 14, "Measure declarations may have only static members") + (Error 897, Line 8, Col 5, Line 8, Col 23, "Measure declarations may have only static members") + (Error 897, Line 6, Col 5, Line 6, Col 30, "Measure declarations may have only static members") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 952624f9fcd..f0cb13ea71e 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -226,6 +226,8 @@ + + From 623a70cd14c36c97ec3f58183d569bd0a7376cc6 Mon Sep 17 00:00:00 2001 From: edgargonzalez Date: Mon, 9 Jun 2025 15:42:01 +0100 Subject: [PATCH 8/8] Simplify testsL names and content --- .../ErrorMessages/AbbreviationTests.fs | 142 +++++++++--------- .../ErrorMessages/NamespaceTests.fs | 44 ++++-- .../ErrorMessages/UnitOfMeasureTests.fs | 116 +++++++------- 3 files changed, 152 insertions(+), 150 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs index 062caa72571..26966e72782 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs @@ -6,35 +6,28 @@ open Xunit open FSharp.Test.Compiler [] -let ``Type abbreviations with members should report all member errors`` () = +let ``Members 01`` () = Fsx """ type StringAlias = string type StringAlias with member x.Length = x.Length - member x.ToUpper() = x.ToUpper() - static member Parse(s) = s """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 964, Line 4, Col 6, Line 4, Col 17, "Type abbreviations cannot have augmentations") (Error 895, Line 5, Col 5, Line 5, Col 31, "Type abbreviations cannot have members") - (Error 895, Line 6, Col 5, Line 6, Col 37, "Type abbreviations cannot have members") - (Error 895, Line 7, Col 5, Line 7, Col 31, "Type abbreviations cannot have members") ] [] -let ``Type abbreviations with interface declarations should report all errors`` () = +let ``Members 02 - Interface impl`` () = Fsx """ type IntAlias = int type IntAlias with interface System.IComparable with member x.CompareTo(obj) = 0 - interface System.IFormattable with - member x.ToString(format, provider) = "" - member x.Value = x """ |> typecheck |> shouldFail @@ -45,15 +38,13 @@ type IntAlias with ] [] -let ``Type abbreviations with mixed members and interfaces should report all errors`` () = +let ``Members 03 - Members and interface`` () = Fsx """ type FloatAlias = float type FloatAlias with member x.IsNaN = System.Double.IsNaN(x) interface System.IConvertible - static member Zero = 0.0 - member x.Sqrt() = sqrt x """ |> typecheck |> shouldFail @@ -64,45 +55,44 @@ type FloatAlias with ] [] -let ``Multiple type abbreviations with errors should all be reported`` () = +let ``Multiple types 01`` () = Fsx """ type ListAlias = int list type ArrayAlias = string[] -type OptionAlias = int option type ListAlias with member x.Head = x.Head - member x.Tail = x.Tail type ArrayAlias with member x.Length = x.Length + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 5, Col 6, Line 5, Col 15, "Type abbreviations cannot have augmentations") + (Error 895, Line 6, Col 5, Line 6, Col 27, "Type abbreviations cannot have members") + (Error 964, Line 8, Col 6, Line 8, Col 16, "Type abbreviations cannot have augmentations") + (Error 895, Line 9, Col 5, Line 9, Col 31, "Type abbreviations cannot have members") + ] + +[] +let ``Multiple types 02 - With interface`` () = + Fsx """ +type ArrayAlias = string[] + +type ArrayAlias with interface System.Collections.IEnumerable with member x.GetEnumerator() = null - -type OptionAlias with - member x.IsSome = x.IsSome - member x.IsNone = x.IsNone - static member None = None """ |> typecheck |> shouldFail |> withDiagnostics [ - (Error 964, Line 6, Col 6, Line 6, Col 15, "Type abbreviations cannot have augmentations") - (Error 895, Line 7, Col 5, Line 7, Col 27, "Type abbreviations cannot have members") - (Error 895, Line 8, Col 5, Line 8, Col 27, "Type abbreviations cannot have members") - (Error 964, Line 10, Col 6, Line 10, Col 16, "Type abbreviations cannot have augmentations") - (Error 906, Line 12, Col 15, Line 12, Col 45, "Type abbreviations cannot have interface declarations") - (Error 909, Line 12, Col 15, Line 12, Col 45, "All implemented interfaces should be declared on the initial declaration of the type") - (Error 964, Line 15, Col 6, Line 15, Col 17, "Type abbreviations cannot have augmentations") - (Error 895, Line 16, Col 5, Line 16, Col 31, "Type abbreviations cannot have members") - (Error 895, Line 17, Col 5, Line 17, Col 31, "Type abbreviations cannot have members") - (Error 895, Line 18, Col 5, Line 18, Col 30, "Type abbreviations cannot have members") - (Error 1198, Line 18, Col 19, Line 18, Col 23, "The generic member 'None' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.") - + (Error 964, Line 4, Col 6, Line 4, Col 16, "Type abbreviations cannot have augmentations") + (Error 906, Line 5, Col 15, Line 5, Col 45, "Type abbreviations cannot have interface declarations") + (Error 909, Line 5, Col 15, Line 5, Col 45, "All implemented interfaces should be declared on the initial declaration of the type") ] - [] -let ``Nested type abbreviations with augmentations should all report errors`` () = +let ``Nested 01`` () = Fsx """ namespace Test @@ -112,68 +102,77 @@ module Nested = type Alias2 = string type Alias1 with - member x.Value = x // Error - + member x.Value = x + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 9, Col 10, Line 9, Col 16, "Type abbreviations cannot have augmentations"); + (Error 895, Line 10, Col 9, Line 10, Col 27, "Type abbreviations cannot have members"); + ] + +[] +let ``Nested 02 - Different namespace`` () = + Fsx """ +namespace Test + +module Nested = + type Alias2 = string + type Alias2 with - member x.Length = x.Length // Error - interface System.IComparable with // Error + interface System.IComparable with member x.CompareTo(obj) = 0 open Nested type Alias2 with - member x.ToUpper() = x.ToUpper() // Error - static member Empty = "" // Error + member x.ToUpper() = x.ToUpper() """ |> typecheck |> shouldFail |> withDiagnostics [ - (Error 964, Line 9, Col 10, Line 9, Col 16, "Type abbreviations cannot have augmentations"); - (Error 895, Line 10, Col 9, Line 10, Col 27, "Type abbreviations cannot have members"); - (Error 964, Line 12, Col 10, Line 12, Col 16, "Type abbreviations cannot have augmentations"); - (Error 906, Line 14, Col 19, Line 14, Col 37, "Type abbreviations cannot have interface declarations"); - (Error 909, Line 14, Col 19, Line 14, Col 37, "All implemented interfaces should be declared on the initial declaration of the type"); - (Error 964, Line 19, Col 6, Line 19, Col 12, "Type abbreviations cannot have augmentations"); - (Error 895, Line 20, Col 5, Line 20, Col 37, "Type abbreviations cannot have members"); - (Error 644, Line 20, Col 14, Line 20, Col 21, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members."); - (Error 895, Line 21, Col 5, Line 21, Col 29, "Type abbreviations cannot have members"); - (Error 644, Line 21, Col 19, Line 21, Col 24, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members.") + (Error 964, Line 7, Col 10, Line 7, Col 16, "Type abbreviations cannot have augmentations"); + (Error 906, Line 8, Col 19, Line 8, Col 37, "Type abbreviations cannot have interface declarations"); + (Error 909, Line 8, Col 19, Line 8, Col 37, "All implemented interfaces should be declared on the initial declaration of the type"); + (Error 964, Line 13, Col 6, Line 13, Col 12, "Type abbreviations cannot have augmentations"); + (Error 895, Line 14, Col 5, Line 14, Col 37, "Type abbreviations cannot have members"); + (Error 644, Line 14, Col 14, Line 14, Col 21, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members."); ] [] -let ``Generic type abbreviations with augmentations should report all errors`` () = +let ``Generic 01`` () = Fsx """ type Result<'T> = Result<'T, string> -type MyList<'a> = 'a list type Result<'T> with member x.IsOk = match x with Ok _ -> true | Error _ -> false - member x.IsError = not x.IsOk - static member Ok(value) = Ok value + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 964, Line 4, Col 6, Line 4, Col 12, "Type abbreviations cannot have augmentations"); + (Error 895, Line 5, Col 5, Line 5, Col 65, "Type abbreviations cannot have members"); + ] + +[] +let ``Generic 02 - Interface`` () = + Fsx """ +type MyList<'a> = 'a list type MyList<'a> with - member x.Head = List.head x - member x.Tail = List.tail x interface seq<'a> with member x.GetEnumerator() = (x :> seq<'a>).GetEnumerator() - interface System.Collections.IEnumerable with - member x.GetEnumerator() = (x :> System.Collections.IEnumerable).GetEnumerator() """ |> typecheck |> shouldFail |> withDiagnostics [ - (Error 964, Line 5, Col 6, Line 5, Col 12, "Type abbreviations cannot have augmentations"); - (Error 895, Line 6, Col 5, Line 6, Col 65, "Type abbreviations cannot have members"); - (Error 895, Line 7, Col 5, Line 7, Col 34, "Type abbreviations cannot have members"); - (Error 895, Line 8, Col 5, Line 8, Col 39, "Type abbreviations cannot have members"); - (Error 1198, Line 8, Col 19, Line 8, Col 21, "The generic member 'Ok' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints."); - (Error 964, Line 10, Col 6, Line 10, Col 12, "Type abbreviations cannot have augmentations"); - (Error 906, Line 13, Col 15, Line 13, Col 22, "Type abbreviations cannot have interface declarations"); - (Error 909, Line 13, Col 15, Line 13, Col 22, "All implemented interfaces should be declared on the initial declaration of the type") + (Error 964, Line 4, Col 6, Line 4, Col 12, "Type abbreviations cannot have augmentations"); + (Error 906, Line 5, Col 15, Line 5, Col 22, "Type abbreviations cannot have interface declarations"); + (Error 909, Line 5, Col 15, Line 5, Col 22, "All implemented interfaces should be declared on the initial declaration of the type") ] [] -let ``Type abbreviations with property getters and setters should report all errors`` () = +let ``Property getters and setters`` () = Fsx """ type IntRef = int ref @@ -181,17 +180,10 @@ type IntRef with member x.Value with get() = !x and set(v) = x := v - member x.Increment() = x := !x + 1 - member x.Decrement() = x := !x - 1 - static member Zero = ref 0 """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 964, Line 4, Col 6, Line 4, Col 12, "Type abbreviations cannot have augmentations") (Error 895, Line 5, Col 5, Line 6, Col 1, "Type abbreviations cannot have members") - (Error 895, Line 8, Col 5, Line 8, Col 39, "Type abbreviations cannot have members") - (Error 895, Line 9, Col 5, Line 9, Col 39, "Type abbreviations cannot have members") - (Error 895, Line 10, Col 5, Line 10, Col 31, "Type abbreviations cannot have members") - (Error 1198, Line 10, Col 19, Line 10, Col 23, "The generic member 'Zero' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.") - ] + ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs index 4336b23bd4f..f989220189e 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs @@ -6,41 +6,48 @@ open Xunit open FSharp.Test.Compiler [] -let ``Namespace cannot contain value bindings - multiple let bindings`` () = +let ``Value bindings 01`` () = + Fsx """ +namespace TestNamespace + +let x = 1 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + ] + +[] +let ``Value bindings 02 - Multiple`` () = Fsx """ namespace TestNamespace let x = 1 let y = 2 -let z = 3 """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") (Error 201, Line 5, Col 5, Line 5, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - (Error 201, Line 6, Col 5, Line 6, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") ] [] -let ``Namespace cannot contain function bindings`` () = +let ``Function bindings`` () = Fsx """ namespace TestNamespace let add x y = x + y -let multiply x y = x * y -let divide x y = x / y """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 201, Line 4, Col 5, Line 4, Col 12, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - (Error 201, Line 5, Col 5, Line 5, Col 17, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - (Error 201, Line 6, Col 5, Line 6, Col 15, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") ] [] -let ``Multiple namespaces with value bindings should all report errors`` () = +let ``Multiple namespaces`` () = Fsx """ namespace Namespace1 @@ -49,19 +56,28 @@ let x = 1 namespace Namespace2 let y = 2 -do printfn "test" namespace Namespace3 let z = 3 -let w = 4 """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") (Error 201, Line 8, Col 5, Line 8, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - (Error 201, Line 9, Col 1, Line 9, Col 18, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - (Error 201, Line 13, Col 5, Line 13, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - (Error 201, Line 14, Col 5, Line 14, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + (Error 201, Line 12, Col 5, Line 12, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") + ] + +[] +let ``Do expressions`` () = + Fsx """ +namespace TestNamespace + +do printfn "test" + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 201, Line 4, Col 1, Line 4, Col 18, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs index 9f2f8ad47e6..8e49da35fbd 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnitOfMeasureTests.fs @@ -6,7 +6,7 @@ open Xunit open FSharp.Test.Compiler [] -let ``Error - Expected unit-of-measure type parameter must be marked with the [] attribute.`` () = +let ``Missing Measure attribute on type parameter`` () = Fsx """ type A<[]'u>(x : int<'u>) = member this.X = x @@ -33,7 +33,7 @@ type FooExt = ] [] -let ``Expected unit-of-measure type parameter must be marked with the [] attribute.`` () = +let ``With Measure attribute on type parameter`` () = Fsx """ type A<[]'u>(x : int<'u>) = member this.X = x @@ -50,66 +50,66 @@ type FooExt = |> typecheck |> shouldSucceed +[] +let ``Instance members 01`` () = + Fsx """ +[] +type kg = + member x.Value = 1.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 897, Line 4, Col 5, Line 4, Col 25, "Measure declarations may have only static members") + ] [] -let ``Measure types with instance members should report multiple errors`` () = +let ``Instance members 02 - Multiple`` () = Fsx """ [] type kg = member x.Value = 1.0 member x.GetWeight() = 2.0 - member x.Property = 3.0 """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 897, Line 4, Col 5, Line 4, Col 25, "Measure declarations may have only static members") (Error 897, Line 5, Col 5, Line 5, Col 31, "Measure declarations may have only static members") - (Error 897, Line 6, Col 5, Line 6, Col 28, "Measure declarations may have only static members") ] [] -let ``Measure types with constructors should report all constructor errors`` () = +let ``Constructors`` () = Fsx """ [] type meter = new() = { } - new(x: int) = { } - member x.Value = 1.0 """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 904, Line 4, Col 5, Line 4, Col 16, "Measure declarations may have only static members: constructors are not available") - (Error 904, Line 5, Col 5, Line 5, Col 22, "Measure declarations may have only static members: constructors are not available") - (Error 897, Line 6, Col 5, Line 6, Col 25, "Measure declarations may have only static members") ] [] -let ``Measure types with type parameters should report error`` () = +let ``Type parameters`` () = Fsx """ [] type meter<'a> = class end - -[] -type second<'a, 'b> = - class end """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 928, Line 3, Col 6, Line 3, Col 11, "Measure definitions cannot have type parameters"); - (Error 928, Line 7, Col 6, Line 7, Col 12, "Measure definitions cannot have type parameters") ] [] -let ``Measure types with inherit declarations should report error`` () = +let ``Inherit declarations`` () = Fsx """ [] type Fahrenheit = inherit Foo() - member x.Value = 1.0 """ |> typecheck |> shouldFail @@ -117,70 +117,82 @@ type Fahrenheit = (Error 962, Line 4, Col 5, Line 4, Col 18, "This 'inherit' declaration has arguments, but is not in a type with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.") (Error 39, Line 4, Col 13, Line 4, Col 16, "The type 'Foo' is not defined.") (Error 897, Line 4, Col 5, Line 4, Col 18, "Measure declarations may have only static members") - (Error 897, Line 5, Col 5, Line 5, Col 25, "Measure declarations may have only static members") ] [] -let ``Measure types with instance let bindings should report multiple errors`` () = +let ``Instance let bindings`` () = Fsx """ [] type Celsius = let instanceValue = 10 - let mutable mut = 20 do printfn "init" - static member Valid = 30 """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 963, Line 4, Col 5, Line 4, Col 27, "This definition may only be used in a type with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.") (Error 897, Line 4, Col 5, Line 4, Col 27, "Measure declarations may have only static members") - (Error 897, Line 5, Col 5, Line 5, Col 25, "Measure declarations may have only static members") - (Error 897, Line 6, Col 5, Line 6, Col 22, "Measure declarations may have only static members") + (Error 897, Line 5, Col 5, Line 5, Col 22, "Measure declarations may have only static members") ] [] -let ``Measure types with mixed valid and invalid members should report only errors`` () = +let ``Mixed valid and invalid 01`` () = Fsx """ [] type Kelvin = static member AbsoluteZero = -273.15 // OK member x.Value = 0.0 // Error: instance member - static member Convert(c: float) = c + 273.15 // OK - new() = { } // Error: constructor - static let cache = System.Collections.Generic.Dictionary() // OK - member x.GetKelvin() = x.Value // Error: instance member -and [] Celsius """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 897, Line 5, Col 5, Line 5, Col 25, "Measure declarations may have only static members") - (Error 904, Line 7, Col 5, Line 7, Col 16, "Measure declarations may have only static members: constructors are not available") - (Error 897, Line 9, Col 5, Line 9, Col 35, "Measure declarations may have only static members") - (Error 1, Line 6, Col 52, Line 6, Col 66, "The unit of measure 'Kelvin' does not match the unit of measure 'Celsius'") - (Error 43, Line 6, Col 50, Line 6, Col 51, "The unit of measure 'Kelvin' does not match the unit of measure 'Celsius'") ] [] -let ``Measure type in class with implicit constructor should report all errors`` () = +let ``Mixed valid and invalid 02 - Constructor`` () = + Fsx """ +[] +type Kelvin = + static member AbsoluteZero = -273.15 // OK + new() = { } // Error: constructor + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 904, Line 5, Col 5, Line 5, Col 16, "Measure declarations may have only static members: constructors are not available") + ] +[] +let ``Implicit constructor`` () = Fsx """ [] type newton() = let force = 10.0 - member x.Force = force - static member Valid = 1.0 // OK """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 897, Line 3, Col 6, Line 3, Col 12, "Measure declarations may have only static members") (Error 897, Line 4, Col 5, Line 4, Col 21, "Measure declarations may have only static members") - (Error 897, Line 5, Col 5, Line 5, Col 27, "Measure declarations may have only static members") ] [] -let ``Measure type augmentations with invalid members should report all errors`` () = +let ``Augmentations 01`` () = + Fsx """ +[] +type joule + +type joule with + member x.Energy = 1.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 897, Line 6, Col 5, Line 6, Col 26, "Measure declarations may have only static members") + ] + +[] +let ``Augmentations 02 - Multiple errors`` () = Fsx """ [] type joule @@ -188,47 +200,30 @@ type joule type joule with member x.Energy = 1.0 new() = { } - member x.GetEnergy() = 2.0 - static member Valid = 3.0 // OK """ |> typecheck |> shouldFail |> withDiagnostics [ (Error 897, Line 6, Col 5, Line 6, Col 26, "Measure declarations may have only static members") (Error 904, Line 7, Col 5, Line 7, Col 16, "Measure declarations may have only static members: constructors are not available") - (Error 897, Line 8, Col 5, Line 8, Col 31, "Measure declarations may have only static members") ] [] -let ``Complex measure type with multiple error types should report all`` () = +let ``Complex with type parameters`` () = Fsx """ [] type pascal<'a> = - inherit System.Object() new() = { } - new(x: int) = { } - member x.Pressure = pressure - member x.SetPressure(p) = pressure <- p - interface System.IComparable with - member x.CompareTo(obj) = 0 """ |> typecheck |> shouldFail |> withDiagnostics [ - (Error 962, Line 4, Col 5, Line 4, Col 28, "This 'inherit' declaration has arguments, but is not in a type with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.") (Error 928, Line 3, Col 6, Line 3, Col 12, "Measure definitions cannot have type parameters") - (Error 897, Line 4, Col 5, Line 4, Col 28, "Measure declarations may have only static members") - (Error 904, Line 5, Col 5, Line 5, Col 16, "Measure declarations may have only static members: constructors are not available") - (Error 904, Line 6, Col 5, Line 6, Col 22, "Measure declarations may have only static members: constructors are not available") - (Error 897, Line 7, Col 5, Line 7, Col 33, "Measure declarations may have only static members") - (Error 897, Line 8, Col 5, Line 8, Col 44, "Measure declarations may have only static members") - (Error 897, Line 10, Col 9, Line 10, Col 36, "Measure declarations may have only static members") - (Error 39, Line 7, Col 25, Line 7, Col 33, "The value or constructor 'pressure' is not defined.") - (Error 39, Line 8, Col 31, Line 8, Col 39, "The value or constructor 'pressure' is not defined.") + (Error 904, Line 4, Col 5, Line 4, Col 16, "Measure declarations may have only static members: constructors are not available") ] [] -let ``Measure type with static and instance let bindings in wrong order`` () = +let ``Let binding order`` () = Fsx """ [] type volt = @@ -237,7 +232,6 @@ type volt = member this.Voltage = 0.0 static member Current = 1.0 // OK do printfn "hello" - static do printfn "world" // OK """ |> typecheck |> shouldFail @@ -246,4 +240,4 @@ type volt = (Error 897, Line 5, Col 5, Line 5, Col 14, "Measure declarations may have only static members") (Error 897, Line 8, Col 5, Line 8, Col 23, "Measure declarations may have only static members") (Error 897, Line 6, Col 5, Line 6, Col 30, "Measure declarations may have only static members") - ] + ] \ No newline at end of file