Skip to content

Compiler is overly secretive when it fails to infer the type of parameters #18042

Closed
@Sporarum

Description

@Sporarum

Compiler version

Scala 3.3.0

Minimized code & Output

def foo(x: Int) = 0

foo(x => x) // error:
// Missing parameter type
// I could not infer the type of the parameter x.

https://scastie.scala-lang.org/Te6OUPEKTnmMn304qWsPew

Expectation

The fact the inference fails hides a more essential issue:

There is no type such that this succeeds.

(Except if there are implicit conversions, with the following, inferring Int would work:

given Conversion[Int => Int, Int] = f => f(42)

)

Even considering this point, a better error would be something like:

Found: T1 => T1
Expected: Int

Where T1 could not be inferred

It displays more information, naturally leading the user to realize x => x would not work in any case

Metadata

Metadata

Assignees

Labels

SpreeSuitable for a future Spreearea:inferarea:reportingError reporting including formatting, implicit suggestions, etcarea:typer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions