Skip to content

Confusing C(x) in error message #7634

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

Closed
som-snytt opened this issue Nov 27, 2019 · 3 comments
Closed

Confusing C(x) in error message #7634

som-snytt opened this issue Nov 27, 2019 · 3 comments

Comments

@som-snytt
Copy link
Contributor

minimized code

$ dotr
Starting dotty REPL...
scala> class C { protected val c = 42 }
// defined class C

scala> val x = C() ; x.c
1 |val x = C() ; x.c
  |              ^^^
  |value c in class C cannot be accessed as a member of C(x) from module class rs$line$2$.
  | Access to protected value c not permitted because enclosing object rs$line$2
  | is not a subclass of class C where target is defined

expectation

As a confused beginner, instead of as a member of C(x), I expect a phrase such as, as a member of type C referenced as value x. Obviously, that is unwieldy.

With the new new-less style, C(x) really looks like a constructor invocation.

@odersky
Copy link
Contributor

odersky commented Nov 28, 2019

Can we write (x: C) instead? Or any other idea how to express this in a concise way?

@abgruszecki
Copy link
Contributor

I think for error messages, it makes sense to just print C and disregard that we're actually dealing with a singleton subtype of that type. I don't think I ever saw an error message where the fact that the type was a singleton was relevant.

@odersky odersky closed this as completed in 46c0759 Dec 9, 2019
odersky added a commit that referenced this issue Dec 9, 2019
Fix #7634: Use `(x: C)` instead of `C(x)` for printing singleton types
@som-snytt
Copy link
Contributor Author

I was less confused when I understood that it was actually the familiar Int(42) notation. But people also ask for diagnostics or REPL output printed in a form they can paste. This change looks good. Of course, all dotty diagnostics look good compared side-by-side with scala 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants