Skip to content

Commit

Permalink
Wrong error line for "No enclosing instance of type ___ is accessible…
Browse files Browse the repository at this point in the history
…" when using method reference (#3497)

Fixes #3207
  • Loading branch information
stephan-herrmann authored Dec 30, 2024
1 parent de9cf96 commit 89d2155
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -223,6 +223,8 @@ public void generateImplicitLambda(BlockScope currentScope, CodeStream codeStrea
implicitLambda.setBody(arrayAllocationExpression);
} else {
AllocationExpression allocation = new AllocationExpression();
allocation.sourceStart = this.sourceStart;
allocation.sourceEnd = this.sourceEnd;
if (this.lhs instanceof TypeReference) {
allocation.type = (TypeReference) this.lhs;
} else if (this.lhs instanceof SingleNameReference) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2021 IBM Corporation and others.
* Copyright (c) 2015, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1256,6 +1256,33 @@ private String getString(Runnable r) {
"The local variable buggyLambda may not have been initialized\n" +
"----------\n");
}
public void testGH3207() {
runNegativeTest(new String[] {
"EnclosedInstance.java",
"""
import java.util.List;
public final class EnclosedInstance {
static Runnable c = () -> {
List.of("a", "a").forEach(Indicator::new);
};
private class Indicator {
Indicator(String s) {}
}
}
"""
},
"""
----------
1. ERROR in EnclosedInstance.java (at line 6)
List.of("a", "a").forEach(Indicator::new);
^^^^^^^^^^^^^^
No enclosing instance of type EnclosedInstance is accessible. Must qualify the allocation with an enclosing instance of type EnclosedInstance (e.g. x.new A() where x is an instance of EnclosedInstance).
----------
""");
}
public static Class testClass() {
return LambdaRegressionTest.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6584,9 +6584,9 @@ public void test406588() {
"}\n"
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" interface I {\n" +
" ^\n" +
"1. ERROR in X.java (at line 10)\n" +
" this(Z::new);\n" +
" ^^^^^^\n" +
"No enclosing instance of type X.Y is available due to some intermediate constructor invocation\n" +
"----------\n");
}
Expand All @@ -6607,9 +6607,9 @@ public void test406586() {
"}\n"
},
"----------\n" +
"1. ERROR in X.java (at line 1)\n" +
" interface I {\n" +
" ^\n" +
"1. ERROR in X.java (at line 8)\n" +
" I i = Y::new;\n" +
" ^^^^^^\n" +
"No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instance of type X (e.g. x.new A() where x is an instance of X).\n" +
"----------\n");
}
Expand Down

0 comments on commit 89d2155

Please sign in to comment.