Skip to content

Compiler does not require System.Attribute for attribute annotation types #4460

@eiriktsarpalis

Description

@eiriktsarpalis

I just came across an interesting behaviour, in which the F# compiler only requires a type to have a parameterless constructor in order to be accepted as an attribute annotation.

Repro steps

The following code compiles without issue:

type Foo () = class end
[<Foo>] type Bar = class end

Reproducible in both F# 4.1 and 4.0.

Expected behavior

Compilation should fail. Compare with C#

public class Foo
{
     public Foo() { }
}

[Foo]
public class Bar { }

which fails with the error

error CS0616: 'Foo' is not an attribute class

This issue actually caused runtime issues for me, because I accidentally inserted a wrong type in attribute annotations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions