mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 18:14:38 +02:00
8261006: 'super' qualified method references cannot occur in a static context
Reviewed-by: sadayapalam
This commit is contained in:
parent
99d7f9a772
commit
c962e6ec0b
3 changed files with 36 additions and 3 deletions
|
@ -4339,11 +4339,14 @@ public class Attr extends JCTree.Visitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isType(sitesym)) {
|
if (isType(sitesym)) {
|
||||||
if (sym.name == names._this) {
|
if (sym.name == names._this || sym.name == names._super) {
|
||||||
// If `C' is the currently compiled class, check that
|
// If `C' is the currently compiled class, check that
|
||||||
// C.this' does not appear in a call to a super(...)
|
// `C.this' does not appear in an explicit call to a constructor
|
||||||
|
// also make sure that `super` is not used in constructor invocations
|
||||||
if (env.info.isSelfCall &&
|
if (env.info.isSelfCall &&
|
||||||
site.tsym == env.enclClass.sym) {
|
((sym.name == names._this &&
|
||||||
|
site.tsym == env.enclClass.sym) ||
|
||||||
|
sym.name == names._super)) {
|
||||||
chk.earlyRefError(tree.pos(), sym);
|
chk.earlyRefError(tree.pos(), sym);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8261006
|
||||||
|
* @summary 'super' qualified method references cannot occur in a static context
|
||||||
|
* @compile/fail/ref=MethodReferenceInConstructorInvocation.out -XDrawDiagnostics MethodReferenceInConstructorInvocation.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class MethodReferenceInConstructorInvocation {
|
||||||
|
interface Bar {
|
||||||
|
default String getString() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Foo implements Bar {
|
||||||
|
|
||||||
|
Foo() {
|
||||||
|
this(Bar.super::getString);
|
||||||
|
}
|
||||||
|
Foo(Supplier<String> sString) {}
|
||||||
|
|
||||||
|
Foo(int i) { this(Bar.super.getString()); }
|
||||||
|
Foo(String s) {}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
MethodReferenceInConstructorInvocation.java:20:21: compiler.err.cant.ref.before.ctor.called: super
|
||||||
|
MethodReferenceInConstructorInvocation.java:24:30: compiler.err.cant.ref.before.ctor.called: super
|
||||||
|
2 errors
|
Loading…
Add table
Add a link
Reference in a new issue