Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bjornregnell opened this issue Jan 27, 2022 · 2 comments

Comments

@bjornregnell
Copy link
Contributor

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.

@bjornregnell bjornregnell added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 27, 2022
@bjornregnell
Copy link
Contributor Author

Related to #14367

@anatoliykmetyuk anatoliykmetyuk added area:extension-methods and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 28, 2022
@odersky odersky self-assigned this Feb 21, 2022
@odersky
Copy link
Contributor

odersky commented Feb 21, 2022

Works in current main. I think the fix to #13437 also fixed this one.

@odersky odersky closed this as completed Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants