Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable EnforceAttributeTargets for F# 9.0 #17558

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/core/attributes/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open System.Diagnostics
[<LoaderOptimization(LoaderOptimization.MultiDomainHost)>]
#endif

let main = ()
let main () = ()


(* attribute on a type *)
Expand Down
12 changes: 12 additions & 0 deletions tests/fsharp/typecheck/sigs/neg06.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/fsharp/typecheck/sigs/neg110.bsl
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions tests/fsharp/typecheck/sigs/neg16.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading