Skip to content

The reference ambiguous checking is too broad in dotty 0.24 #8930

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
esse-byte opened this issue May 10, 2020 · 4 comments
Closed

The reference ambiguous checking is too broad in dotty 0.24 #8930

esse-byte opened this issue May 10, 2020 · 4 comments
Assignees

Comments

@esse-byte
Copy link

esse-byte commented May 10, 2020

Minimized code

class A(val i: Int)

def a(i: Int): A = new A(i) { println(i) }

Output

Reference to i is ambiguous,
it is both defined in method a
and inherited subsequently in anonymous class A {...}

Expectation

The code compiles in both dotty 0.23 and scala 2.3.1

@smarter
Copy link
Member

smarter commented May 10, 2020

The stricter checks are intentional: #8622, not sure if we could relax them in this particular case.

@odersky
Copy link
Contributor

odersky commented May 11, 2020

The only way to relax them would be to somehow detect that the parameter to A ends up as the initializer of the field a. But we could detect that only after type checking. So, I don't think that would be practical.

@odersky odersky closed this as completed May 11, 2020
@som-snytt
Copy link
Contributor

Even if the aliasing were detected, it's not obvious that the usage is intended without more explicit syntax.

This belongs to the class of "pass-thru" init, class X(_) extends Y(_). Whatever the hypothetical syntax, "apply incoming params directly to a thing." (Without danger of alias.)

@som-snytt
Copy link
Contributor

Fixing code in Scala 2 project, similar example with tree, which is assumed to mean the only possible tree under consideration. Hypothetical syntax new C(tree' = tree) to mean the arg must be aliased to member of that name, and refchecked.

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