Skip to content

Compiler does not compile a function with a default argument initialized using an expression with the same name field #9413

@scabug

Description

@scabug

The following trivial example produces a compiler error:

class A {
  val b = ""
  def f(b: Option[String] = Some(b))
}

The error is

Error:(3, 34) type mismatch;
 found   : Option[String]
 required: String
  def f(b: Option[String] = Some(b))
                                 ^

The error seems to suggest the compiler is trying to initialize b argument with itself, not with the b field, when the b field should be the only possible valid interpretation in this context, as b argument is not visible in the parameter list itself.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions