Skip to content

confusing suggestion when non-Unit expression is adapted to Unit (expression discarded in statement position) #18408

Closed
@scf37

Description

@scf37

Compiler version

3.3.0

Minimized code

def fa(f: String ?=> Unit): Unit = f(using "hello")
fa(42) // compiles with warning but does nothing

Output

[warn] -- [E129] Potential Issue Warning: /Test.scala:13:11 
[warn] 13 |        fa(42) // compiles but does nothing
[warn]    |           ^^
[warn]    |A pure expression does nothing in statement position; you may be omitting necessary parentheses
[warn]    |
[warn]    | longer explanation available when compiling with `-explain`

Expectation

Compilation error. I expect this because 42 seems to not match the type String ?=> Unit

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