Skip to content

can't infer proper type when using extension method as a function #18558

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

Open
kpodsiad opened this issue Sep 15, 2023 · 1 comment
Open

can't infer proper type when using extension method as a function #18558

kpodsiad opened this issue Sep 15, 2023 · 1 comment

Comments

@kpodsiad
Copy link

Compiler version

3.3.1

Minimized code

//> using scala "3.3.1"

trait Food[+A]
trait Animal
object Animal {
  extension (animal: Animal) def consume[A](weights: Food[A]): A = ???
}

val animal: Animal = ???
val choices: List[Food[Int]] = ???
val result0: List[Any] = choices.map(animal.consume) // compiles
// val result1: List[Int] = choices.map(animal.consume) // does not compile
val result2: List[Int] = choices.map(food => animal.consume(food))
val result3: List[Int] = choices.map(animal.consume(_))

Output

Found:    Food[Any] => Any
Required: Food[Int] => Int

Expectation

result1 either compiles or raises a clear error message that such usage is forbidden.

@kpodsiad kpodsiad added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 15, 2023
@som-snytt
Copy link
Contributor

val result4: List[Int] = choices.map(food => Animal.consume(animal)(food))
val result5: List[Int] = choices.map(Animal.consume(animal))

for completeness

@mbovel mbovel added area:typer area:infer and removed stat:needs triage Every issue needs to have an "area" and "itype" label area:typer labels Sep 18, 2023
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 13, 2024
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