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
Anonymous classes do not produce members when constructed as a function argument #5448
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5448?orig=1
|
@cvogt said: |
@adriaanm said: symptomatic explanation: [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc /Users/adriaan/Desktop/t5448.scala -Xprint:typer
[[syntax trees at end of typer]]// Scala source: t5448.scala
package <empty> {
final object Test extends Object with App with ScalaObject {
def <init>(): object Test = {
Test.super.<init>();
()
};
def getFoo(a: Any): Unit = try {
a.getClass().getMethod("foo");
scala.this.Predef.println("Foo found!")
} catch {
case (e @ (_: NoSuchMethodException)) => scala.this.Predef.println("Foo missing!")
};
Test.this.getFoo({
final class $anon extends scala.AnyRef {
def <init>(): anonymous class $anon = {
$anon.super.<init>();
()
};
private def foo: Int = 1
};
new $anon()
});
Test.this.getFoo({
val a: Object{def foo: Int} = {
final class $anon extends scala.AnyRef {
def <init>(): anonymous class $anon = {
$anon.super.<init>();
()
};
def foo: Int = 1
};
new $anon()
};
a
})
}
}
[adriaan@lampmac13 scala (topic/virtpatmat)]$ qs Test
Foo missing!
Foo found! |
@adriaanm said: def getFoo[T](a: T) |
@Blaisorblade said: |
If an anonymous class is instantiated as an argument to a function call,
its members will not be available unless they have been assigned to a variable.
The text was updated successfully, but these errors were encountered: