From 6cd4d598f6ab714e7598c886ccb44cbfae187de6 Mon Sep 17 00:00:00 2001 From: "Kevin Ransom (msft)" Date: Thu, 22 Aug 2024 04:36:19 -0700 Subject: [PATCH] Enable EnforceAttributeTargets for F# 9.0 (#17558) * Fix 17514: https://github.com/dotnet/fsharp/issues/17514 * LoaderOptimization thingy --- .../.FSharp.Compiler.Service/9.0.100.md | 3 ++- .../Checking/Expressions/CheckExpressions.fs | 2 +- src/Compiler/Facilities/LanguageFeatures.fs | 2 +- tests/fsharp/core/attributes/test.fsx | 2 +- tests/fsharp/typecheck/sigs/neg06.bsl | 12 ++++++++++++ tests/fsharp/typecheck/sigs/neg110.bsl | 1 + tests/fsharp/typecheck/sigs/neg16.bsl | 8 ++++++++ 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md index 8b5f79b3be7..d3e795bf8b7 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md @@ -22,6 +22,8 @@ * Allow access modifies to auto properties getters and setters ([Language suggestion #430](https://github.com/fsharp/fslang-suggestions/issues/430), [PR 16687](https://github.com/dotnet/fsharp/pull/16687), [PR 16861](https://github.com/dotnet/fsharp/pull/16861), [PR 17522](https://github.com/dotnet/fsharp/pull/17522)) * Render C# nullable-analysis attributes in tooltips ([PR #17485](https://github.com/dotnet/fsharp/pull/17485)) * Allow object expression without overrides. ([Language suggestion #632](https://github.com/fsharp/fslang-suggestions/issues/632), [PR #17387](https://github.com/dotnet/fsharp/pull/17387)) +* Enable FSharp 9.0 Language Version ([Issue #17497](https://github.com/dotnet/fsharp/issues/17438)), [PR](https://github.com/dotnet/fsharp/pull/17500))) +* Enable LanguageFeature.EnforceAttributeTargets in F# 9.0. ([Issue #17514](https://github.com/dotnet/fsharp/issues/17558), [PR #17516](https://github.com/dotnet/fsharp/pull/17558)) ### Changed @@ -32,6 +34,5 @@ * Enforce `AttributeTargets` on unions. ([PR #17389](https://github.com/dotnet/fsharp/pull/17389)) * Applied nullable reference types to FSharp.Compiler.Service itself ([PR #15310](https://github.com/dotnet/fsharp/pull/15310)) * Ensure that isinteractive multi-emit backing fields are not public. ([Issue #17439](https://github.com/dotnet/fsharp/issues/17438)), ([PR #17439](https://github.com/dotnet/fsharp/pull/17439)) -* Enable FSharp 9.0 Language Version ([Issue #17497](https://github.com/dotnet/fsharp/issues/17438)), [PR](https://github.com/dotnet/fsharp/pull/17500))) * Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521)) ### Breaking Changes diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 1b1f70a7277..8d6e26140e1 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -11087,7 +11087,7 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt errorR(Error(FSComp.SR.tcLiteralCannotHaveGenericParameters(), mBinding)) if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && memberFlagsOpt.IsNone && not attrs.IsEmpty then - TcAttributeTargetsOnLetBindings cenv env attrs overallPatTy overallExprTy (not declaredTypars.IsEmpty) isClassLetBinding + TcAttributeTargetsOnLetBindings { cenv with tcSink = TcResultsSink.NoSink } env attrs overallPatTy overallExprTy (not declaredTypars.IsEmpty) isClassLetBinding CheckedBindingInfo(inlineFlag, valAttribs, xmlDoc, tcPatPhase2, explicitTyparInfo, nameToPrelimValSchemeMap, rhsExprChecked, argAndRetAttribs, overallPatTy, mBinding, debugPoint, isCompGen, literalValue, isFixed), tpenv diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index ccf2796ca90..5c311237594 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -212,10 +212,10 @@ type LanguageVersion(versionText) = LanguageFeature.LowerSimpleMappingsInComprehensionsToFastLoops, languageVersion90 LanguageFeature.ParsedHashDirectiveArgumentNonQuotes, languageVersion90 LanguageFeature.EmptyBodiedComputationExpressions, languageVersion90 + LanguageFeature.EnforceAttributeTargets, languageVersion90 // F# preview LanguageFeature.UnmanagedConstraintCsharpInterop, previewVersion // not enabled because: https://github.com/dotnet/fsharp/issues/17509 - LanguageFeature.EnforceAttributeTargets, previewVersion // not enabled because: https://github.com/dotnet/fsharp/issues/17514 LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, previewVersion LanguageFeature.AllowObjectExpressionWithoutOverrides, previewVersion diff --git a/tests/fsharp/core/attributes/test.fsx b/tests/fsharp/core/attributes/test.fsx index ac8e504115b..30509f450fd 100644 --- a/tests/fsharp/core/attributes/test.fsx +++ b/tests/fsharp/core/attributes/test.fsx @@ -42,7 +42,7 @@ open System.Diagnostics [] #endif -let main = () +let main () = () (* attribute on a type *) diff --git a/tests/fsharp/typecheck/sigs/neg06.bsl b/tests/fsharp/typecheck/sigs/neg06.bsl index d55e3e948d2..fae7a14c1fc 100644 --- a/tests/fsharp/typecheck/sigs/neg06.bsl +++ b/tests/fsharp/typecheck/sigs/neg06.bsl @@ -2,12 +2,18 @@ neg06.fs(3,40,3,45): typecheck error FS0039: The type 'Encoding' does not define the field, constructor or member 'Ascii'. Maybe you want one of the following: ASCII +neg06.fs(11,3,11,9): typecheck error FS0842: This attribute is not valid for use on this language element + neg06.fs(12,6,12,31): typecheck error FS0942: Struct types are always sealed +neg06.fs(17,3,17,9): typecheck error FS0842: This attribute is not valid for use on this language element + neg06.fs(18,6,18,24): typecheck error FS0948: Interface types cannot be sealed neg06.fs(24,6,24,30): typecheck error FS0944: Abbreviated types cannot be given the 'Sealed' attribute +neg06.fs(26,3,26,9): typecheck error FS0842: This attribute is not valid for use on this language element + neg06.fs(27,6,27,33): typecheck error FS0942: Delegate types are always sealed neg06.fs(31,9,31,29): typecheck error FS0945: Cannot inherit a sealed type @@ -88,14 +94,20 @@ neg06.fs(223,13,223,21): typecheck error FS0800: Invalid use of a type name neg06.fs(300,10,300,12): typecheck error FS0009: Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'. +neg06.fs(303,7,303,104): typecheck error FS0842: This attribute is not valid for use on this language element + neg06.fs(304,10,304,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute neg06.fs(310,10,310,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute neg06.fs(314,10,314,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute +neg06.fs(316,7,316,104): typecheck error FS0842: This attribute is not valid for use on this language element + neg06.fs(317,10,317,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute +neg06.fs(319,7,319,104): typecheck error FS0842: This attribute is not valid for use on this language element + neg06.fs(320,10,320,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute neg06.fs(326,10,326,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation diff --git a/tests/fsharp/typecheck/sigs/neg110.bsl b/tests/fsharp/typecheck/sigs/neg110.bsl index 60cae991283..7df68004899 100644 --- a/tests/fsharp/typecheck/sigs/neg110.bsl +++ b/tests/fsharp/typecheck/sigs/neg110.bsl @@ -1,2 +1,3 @@ +neg110.fs(5,3,5,15): typecheck error FS1133: No constructors are available for the type 'NotAttribute' neg110.fs(5,3,5,15): typecheck error FS3242: This type does not inherit Attribute, it will not work correctly with other .NET languages. diff --git a/tests/fsharp/typecheck/sigs/neg16.bsl b/tests/fsharp/typecheck/sigs/neg16.bsl index 9cb22ec9c0a..4a6dde0f034 100644 --- a/tests/fsharp/typecheck/sigs/neg16.bsl +++ b/tests/fsharp/typecheck/sigs/neg16.bsl @@ -3,14 +3,20 @@ neg16.fs(7,13,7,16): typecheck error FS0644: Namespaces cannot contain extension neg16.fs(23,10,23,11): typecheck error FS0935: Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal +neg16.fs(34,7,34,23): typecheck error FS0842: This attribute is not valid for use on this language element + neg16.fs(35,10,35,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute neg16.fs(38,10,38,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute neg16.fs(41,10,41,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute +neg16.fs(43,7,43,23): typecheck error FS0842: This attribute is not valid for use on this language element + neg16.fs(44,10,44,11): typecheck error FS0934: Records, union, abbreviations and struct types cannot have the 'AllowNullLiteral' attribute +neg16.fs(46,7,46,23): typecheck error FS0842: This attribute is not valid for use on this language element + 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 @@ -73,6 +79,8 @@ neg16.fs(90,7,90,22): typecheck error FS0025: Incomplete pattern matches on this neg16.fs(96,3,97,16): typecheck error FS0823: The 'VolatileField' attribute may only be used on 'let' bindings in classes +neg16.fs(99,5,99,18): typecheck error FS0842: This attribute is not valid for use on this language element + neg16.fs(99,3,100,14): typecheck error FS0823: The 'VolatileField' attribute may only be used on 'let' bindings in classes neg16.fs(99,3,100,14): typecheck error FS0879: Volatile fields must be marked 'mutable' and cannot be thread-static