-
Notifications
You must be signed in to change notification settings - Fork 854
Description
Using typof<SomeType> can lead to confusing error messages when used as an argument for an attribute.
Repro steps
Try this code:
[<AttributeUsage(AttributeTargets.All)>]
type FooAttribute(t:System.Type) =
inherit System.Attribute()
[<Foo(typeof<OutOfScopeType>)>]
type Vehicle() = class endExpected behavior
Should give the same error as normal use of typeof, i.e. that the type is not defined. The expected error is: "FS0039 The type 'OutOfScopeType' is not defined."
In other words, I'd expect it similar to this:
Actual behavior
A different error is shown and the whole expression is underlined.
FS0267 This is not a valid constant expression or custom attribute value
I should note that if you hover over the type-part, both errors are shown.
Known workarounds
N/A
Related information
This reported has lead to confusion with users. For instance, see this post, where a programmer thought that typeof as a whole was not allowed (and I know I fell for this trap in the past as well): https://stackoverflow.com/questions/18369922/f-attributes-typeof-and-this-is-not-a-constant-expression.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status

