Skip to content

Types printed in error messages are dealiased completely for some cases #4565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pweisenburger opened this issue May 22, 2018 · 0 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement

Comments

@pweisenburger
Copy link
Contributor

When compiling the following code:

case class Test[T](v: T)
type LongComplictedType
type B = LongComplictedType

def v: Int = Test(??? : B)

Dotty produces the error message:

1 |def v: Int = Test(??? : B)
  |             ^^^^^^^^^^^^^
  |             found:    Test[LongComplictedType]
  |             required: Int

Note that Dotty completely dealiases the type (i.e., found: Test[LongComplictedType], instead of found: Test[B]). In error messages issued by scalac, you get the type as it is denoted in the code (which is potentially an alias), and you get an "which expands to" line with the dealiased type:

1: error: type mismatch;
 found   : Test[B]
    (which expands to)  Test[LongComplictedType]
 required: Int
       def v: Int = Test(??? : B)

I'd argue that the Scala error messages are better to read since you are also shown the aliased types that do not match (type aliases are often defined to abstract away complexity and thus, it should be easier to interpret the type for the developer reading the error message).

I think the reason is that Dotty infers the type of Test(??? : B) as Test[LongComplictedType] instead of Test[B]. Further, it could also be useful to show both the type as denoted in the code and the expanded type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants