Skip to content

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

Closed
@scabug

Description

@scabug

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions