Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

FS3888 on a struct with an [<Extension>] member, while FS0842 rejects the attribute on the struct #21053

Backlog

Description

@nojaf

A struct with an [<Extension>] member gets FS3888 when it has a signature file, and the attribute the warning asks for is then rejected on the struct with FS0842. There is no signature that compiles without a warning. I am not sure whether this is a regression or an intended consequence of #19880 , so I would like to hear what the team thinks.

Repro

Lib.fsi:

module Lib

open System.Runtime.CompilerServices

[<Struct>]
type S =
    val X: int
    [<Extension>]
    static member PlusOne: a: int -> int

Lib.fs:

module Lib

open System.Runtime.CompilerServices

[<Struct>]
type S =
    val X: int
    [<Extension>]
    static member PlusOne(a: int) : int = a + 1

I type checked the pair with FSharpChecker.ParseAndCheckProject, once with the signature above and once with [<Struct; Extension>] on the type in the signature:

FSharp.Compiler.Service Signature as above [<Struct; Extension>] in the signature
43.12.403 no diagnostics FS0842
43.13.404 FS3888 FS0842
warning FS3888: The attribute 'Extension' is present on 'S' in the implementation but not in the signature, which takes precedence for tooling and consumers. Add the attribute to the signature, to ensure the attribute is not ignored by the compiler.
warning FS0842: This attribute cannot be applied to struct. Valid targets are: assembly, class, method

What I think happens

The compiler adds ExtensionAttribute to the type in the implementation because one of its members has it. The new check from #19880 then sees the attribute on the implementation entity and asks for it in the signature, but the attribute target check does not allow it on a struct. The user never wrote the attribute on the type.

With ErrorOnMissingSignatureAttribute moved to F# 11.0 in #20199 , FS3888 becomes an error, so a struct like this would no longer build with a signature file.

Questions

  1. Is a struct with a C# style extension member something that should keep working with a signature file? If so, should the check skip attributes the compiler infers, or at least skip targets the attribute cannot be put on?
  2. The same inference applies to classes and modules: a member or let with [<Extension>] now requires [<Extension>] on the type or module in the signature, although it was never written in the implementation. Is that the intended outcome? It works, but it surprised me.

Found while updating Telplin (a signature file generator) to FCS 43.13.404: nojaf/telplin#402

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions