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

Fixes #3207
  • Loading branch information
stephan-herrmann committed Dec 30, 2024
1 parent de9cf96 commit 3bc85de
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 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

0 comments on commit 3bc85de

Please sign in to comment.