Navigation Menu

Skip to content
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

Lazy modifier on a val causes its name to collide with a method's named arg #6051

Closed
scabug opened this issue Jul 10, 2012 · 4 comments
Closed

Comments

@scabug
Copy link

scabug commented Jul 10, 2012

The following code causes a compilation error:

object Foo {                                                                                                                                                                                                                                                                           
  def foo(x: Int, y: Int = 10) = x*y                                                                                                                                                                                                                                                   
  lazy val y = foo(x = 20)                                                                                                                                                                                                                                                             
}

The error is as follows:

innocuous.scala:3: error: variable definition needs type because 'y' is used as a named argument in its body.
Error occurred in an application involving default arguments.
  lazy val y = foo(x = 20)
           ^
one error found

None of the following fail in the same way:

val y = foo(x = 20)

OR

lazy val y = foo(20)

It appears that combining the lazy modifier on y with a named arg in the application of foo causes it to blow up.

@scabug
Copy link
Author

scabug commented Jul 10, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6051?orig=1
Reporter: Max Afonov (maxaf)
Affected Versions: 2.9.1, 2.10.0-M4

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@hubertp said:
This one is most probably a correct error. There was recently a similar bug report with var instead of lazy val and the problem is that both create getters and setters and the disambiguation mechanism that drives the names defaults expansion is ambiguous in this is situation.
I will see if we can improve on the error message but this is again non trivial due to some of the internal stuff in the compiler (type completers).

@scabug
Copy link
Author

scabug commented May 20, 2013

@JamesIry said:
2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

@scabug
Copy link
Author

scabug commented Nov 4, 2014

@lrytz said:
retronym/scala#7

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

2 participants