Skip to content

Overloaded extension methods with varargs used as infix operator failed the compilation #16125

Closed
@guofengzh

Description

@guofengzh

Compiler version

3.2.0

Minimized code

Change the code in #12133, add 'infix'. it works. but if the extension clause has more than one method defintion, it fails the compilation.

class B

class A:
  infix def foo(b: B) = ???
  infix def foo(str: String) = ???

extension (x: A) 
  infix def foo(s: Int*) = s.size
  infix def foo(l: Boolean) = ???

val a = new A

val res = a foo (1, 2)  // ERROR!!

The error message is

None of the overloaded alternatives of method foo in class A with types
 (str: String): Nothing
 (b: sample.B): Nothing
match arguments ((Int, Int))

if I moved all methods in A to the extension clause, that is

extension (x: A) 
  infix def foo(b: B) = ???
  infix def foo(str: String) = ???
  infix def foo(s: Int*) = s.size
  infix def foo(l: Boolean) = ???

the messages changed to

value foo is not a member of sample.A.
An extension method was tried, but could not be fully constructed:

    sample.foo()    failed with

        value foo: <overloaded sample.foo> does not take parameters

In these two cases, if the dot selection is used for the function application, the codes pass the compilation.

Output

N/A

Expectation

Is it a bug of the Scala 3 compiler, or is there any syntax limition with the infix modifier?

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions