Skip to content

unhelpful syntax error when inferred lambda parameters mismatch expected count #18657

Closed
@odersky

Description

@odersky

Compiler version

3.3.1

Minimized example

val f: (Int, Int) => Int = Integer.compare(_ + 1, _)

Output Error/Warning message

-- [E086] Syntax Error: --------------------------------------------------------
1 |val f: (Int, Int) => Int = Integer.compare(_ + 1, _)
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^
  |                           Wrong number of parameters, expected: 2
1 error found

Why this Error/Warning was not helpful

The error message is correct, but I must work hard to realise that actually the first argument to Integer.compare is expanded to a separate nested lambda, so the placeholder is not for f.

Suggested improvement

The error could be improved by an explanation. Under -explain I would like to see:

  • The full expected type
  • The eta expanded argument

This would make it clear which parameter each placeholder refers to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions