Skip to content

compiler is confused by extension methods in combination with vararg method eta expansion #14368

Closed
@bjornregnell

Description

@bjornregnell

Compiler version

3.1.1

Minimized code and output

The compiler gives a long and strange message in this situation:

Welcome to Scala 3.1.1 (11.0.13, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                               
scala> extension (s: String) def m(i: Int*) = i.sum
def m(s: String)(i: Int*): Int
                                                                                                                               
scala> "hello".m
-- [E008] Not Found Error: ----------------------------------------------------------------------------------------------------
1 |"hello".m
  |^^^^^^^^^
  |value m is not a member of String.
  |An extension method was tried, but could not be fully constructed:
  |
  |    {
  |      def $anonfun(i: <error Missing parameter type
  |    
  |    I could not infer the type of the parameter i.>): Int = 
  |        m("hello")(i:<error Missing parameter type
  |    
  |    I could not infer the type of the parameter i.>)
  |      closure($anonfun)
  |    }    failed with
  |
  |        Missing parameter type
  |        
  |        I could not infer the type of the parameter i.
1 error found

It works if the type is explicitly given:

scala> val f: Seq[Int] => Int = "hello".m
val f: Seq[Int] => Int = Lambda$1499/0x000000080079b040@6e90cec8

Expectation

It should work and give me a function from Seq[Int] or at least give a better error message.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions