Open
Description
Scala 3.3.1
class MyClass(int: Int = fooInt) { //no error, expected "Not found: fooInt"
println(fooInt) //error: "Not found: fooInt" (as expected)
}
object MyClass {
def fooInt: Int = ???
}
The code should produce an error at the first line as fooInt
is not in the scope.
The correct way to use it is to import MyClass.fooInt
or use qualified name.
The same issue is for case classes and ordinary classes.
I guess it's a leaked implementation detail of "universal apply" feature + a bug in handling apply methods with default parameter values.
Now even non-case classes have synthetic apply methods.
It seams during compilation the default arguments are simply moved to the apply method of companion object (potentially synthetic), where object members are accessible.