Skip to content

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

Open
@kpodsiad

Description

@kpodsiad

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions