-
Notifications
You must be signed in to change notification settings - Fork 816
opt-in warning attribute not valid for union case with fields #18532
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,22 +576,33 @@ module TcRecdUnionAndEnumDeclarations = | |
|
||
let checkXmlDocs = cenv.diagnosticOptions.CheckXmlDocs | ||
let xmlDoc = xmldoc.ToXmlDoc(checkXmlDocs, Some names) | ||
let attrs = | ||
(* | ||
The attributes of a union case decl get attached to the generated "static factory" method. | ||
Enforce union-cases AttributeTargets: | ||
- AttributeTargets.Method | ||
type SomeUnion = | ||
| Case1 of int // Compiles down to a static method | ||
- AttributeTargets.Property | ||
type SomeUnion = | ||
| Case1 // Compiles down to a static property | ||
*) | ||
if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then | ||
let target = if rfields.IsEmpty then AttributeTargets.Property else AttributeTargets.Method | ||
TcAttributes cenv env target synAttrs | ||
else | ||
TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs | ||
let attrs = TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs | ||
(* | ||
The attributes of a union case decl get attached to the generated "static factory" method. | ||
Enforce union-cases AttributeTargets: | ||
- AttributeTargets.Method | ||
type SomeUnion = | ||
| Case1 of int // Compiles down to a static method | ||
- AttributeTargets.Property | ||
type SomeUnion = | ||
| Case1 // Compiles down to a static property | ||
*) | ||
if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then | ||
let attrTargets = | ||
attrs | ||
|> List.collect (fun attr -> | ||
attr.TyconRef.Attribs | ||
|> List.choose (fun attr -> | ||
match attr with | ||
| Attrib(unnamedArgs = [ AttribInt32Arg validOn ]) -> Some validOn | ||
| _ -> None)) | ||
|
||
attrTargets | ||
|> List.iter (fun target -> | ||
// If the union case has fields, and the target is not AttributeTargets.Method || AttributeTargets.All. Then we raise a separate opt-in warning | ||
let targetEnum = enum<AttributeTargets> target | ||
if targetEnum <> AttributeTargets.Method && targetEnum <> AttributeTargets.All then | ||
warning(Error(FSComp.SR.tcAttributeIsNotValidForUnionCaseWithFields(), id.idRange))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will only be raised of the user opts-in for this warning. |
||
|
||
Construct.NewUnionCase id rfields recordTy attrs xmlDoc vis | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we roll back to allow
AttributeTargets.Method ||| AttributeTargets.Property
as valid targets for union cases regardless the layout like before.