Skip to content

"Duplicate method ... same signature" error occurs for member names other than op_Implicit #14059

@cmeeren

Description

@cmeeren

Consider this code:

type A =
  | A of int
  static member M(A x) : int = x
  static member M(A x) : string = x.ToString()

This leads to the following compilation error:

Duplicate method. The method 'M' has the same name and signature as another method in type 'A'.

image

I assume "signature" refers to the parameters and ignores the return type. However, using the name op_Implicit works fine:

type A =
  | A of int
  static member op_Implicit(A x) : int = x
  static member op_Implicit(A x) : string = x.ToString()

Why should it depend on the name? Is this a bug?

My use-case is that I am using some SRTP helpers to convert between compatible types, but I'd like to move away from relying on op_Implicit for these helpers in order to force myself to use these helpers. With op_Implicit, I get automatic conversion at method call sites (but I don't want to enable the warning/error for this, since I want that implicit conversion for some built-in .NET APIs/types).

Related information

  • Windows 11
  • Rider 2022.2.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions