Skip to content

Improve error messages for erroneous export statements #21976

Open
@KacperFKorban

Description

@KacperFKorban

Compiler version

3a5e137

Minimized example

def fun1(i: Int): Double = ???
  
def fun2(d: Double): Double = ???

export fun1.apply, fun2.unlift

Output Error/Warning message

-- [E083] Type Error: /home/kpi/bugs/export-better-errors.scala:5:7 ------------
5 |export fun1.apply, fun2.unlift
  |       ^^^^
  |Int => Double is not a valid export prefix, since it is not an immutable path
  |
  | longer explanation available when compiling with `-explain`
-- [E083] Type Error: /home/kpi/bugs/export-better-errors.scala:5:19 -----------
5 |export fun1.apply, fun2.unlift
  |                   ^^^^
  |       Any is not a valid export prefix, since it is not an immutable path
  |
  | longer explanation available when compiling with `-explain`
-- Error: /home/kpi/bugs/export-better-errors.scala:5:24 -----------------------
5 |export fun1.apply, fun2.unlift
  |                        ^^^^^^
  |                        no eligible member unlift at {
  |                          def $anonfun(d: Double): Double = fun2(d)
  |                          closure($anonfun:Any)
  |                        }

Why this Error/Warning was not helpful

The first error message is helpful, but the rest are confusing. Any is inferred for fun2 most likely because of the previous error, and the last error shows some desugared/eta-expanded code, which is also a side effect of the previous error.

Suggested improvement

The last error shouldn't be shown. One possibility is to make the positions the same for the first and last errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:exportarea: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