-
Notifications
You must be signed in to change notification settings - Fork 823
AttributeTargets better error message #18641
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?
Conversation
923548b
to
379821c
Compare
❗ Release notes required
|
65634b0
to
39b5f4d
Compare
39b5f4d
to
049472b
Compare
Co-authored-by: Brian Rourke Boll <brianrourkeboll@users.noreply.github.com>
75543b9
to
0c55b19
Compare
if Array.isEmpty currentTargets then | ||
os.AppendString(InvalidAttributeTargetForLanguageElement2E().Format) | ||
else | ||
let currentTarget = String.concat ", " currentTargets |
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.
Why is the current target an array and not a single element? That part I find confusing in the error message.
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.
So:
currentTarget
represents the specific targets that the compiler wants to enforce e.g.let FieldDecl = AttributeTargets.Field ||| AttributeTargets.Property
hence the reason been a list.validTargets
all the targets defined in the attribute declaration.
Alternatively we an maybe pass through the type of declaration where this attribute is been used as string. like "functions" etc. But this will differ from what the AttributeTargets naming is using.
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.
Are the currentTargets
a "and" or "or" combination?
i.e. do all of them have to be met, or just one?
(I would like that to be apparent from the naming if possible, also then in the resolution of the error message)
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.
@T-Gro This is an OR
. What about something like e.g. Invalid attribute target. Expected: class, struct, parameter. Actual: method, property, field, return value.
…gp/fsharp into attr-targets-better-error-message
Head branch was pushed to by a user without write access
Description
BEFORE
We had one message to fit all the invalid attribute targets messages.
This attribute is not valid for use on this language element
AFTER
We have now:
This attribute cannot be applied to (<one or more targets>). Valid targets are: (<one or more targets>)
e.g.This attribute cannot be applied to struct. Valid targets are: class
This attribute cannot be applied to property, field, return value. Valid targets are: method
This attribute cannot be applied to class. Valid targets are: interface
This attribute cannot be applied to method, property. Valid targets are: field
For cases here F# does not support attributes or still not a valid analysis for attribute targets that we want to enforce. We will still fallback to
This attribute is not valid for use on this language element
.Checklist