fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

No compiler error when declaring multiple parameters with the same name in abstract methods

Open brianrourkeboll opened this issue 3 years ago • 1 comments

Repro steps

Provide the steps required to reproduce the problem:

  1. Define a type with an abstract member having two parameters with the same name.
  2. It compiles, generating unutterable names for all repeated parameter names after the first.

Examples

type I =
    // Tupled.
    abstract M : i:int * i:int -> int
    // Curried.
    abstract N : i:int -> i:int -> int
    // More than two.
    abstract O : i:int * i: int * i:int -> int
    // Multiple distinct names repeated.
    abstract P : i:int * j:int * i:int * j:int -> int

generates (SharpLab)

[Serializable]
[CompilationMapping(SourceConstructFlags.ObjectType)]
public interface I
{
    override int M(int i, int i@3);

    [CompilationArgumentCounts(new int[] { 1, 1 })]
    override int N(int i, int i@5-1);

    override int O(int i, int i@7-2, int i@7-3);

    override int P(int i, int j, int i@9-4, int j@9);
}

Expected behavior

A compiler error disallowing multiple parameters with the same name in abstract methods.

Actual behavior

The code compiles, but the names of all repeated parameter names are unutterable.

Known workarounds

It is still possible to implement an abstract method so defined, although it is not possible to make the concrete implementation's parameters' names match those of the abstract method being overridden.

Related information

  • .NET SDK 6.0.300.

brianrourkeboll avatar May 17 '22 21:05 brianrourkeboll

Agreed this should be fixed.

dsyme avatar May 23 '22 16:05 dsyme