mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
new overload resolution: reject complete normally when last instruction is return (IDEA-134808)
This commit is contained in:
@@ -726,9 +726,15 @@ public class ControlFlowUtil {
|
||||
if (nextOffset > flow.getSize()) nextOffset = flow.getSize();
|
||||
if (offset > endOffset) return;
|
||||
int throwToOffset = instruction.offset;
|
||||
boolean isNormal;
|
||||
boolean isNormal = false;
|
||||
if (throwToOffset == nextOffset) {
|
||||
isNormal = nextOffset == endOffset || throwToOffset <= endOffset && !isLeaf(nextOffset) && canCompleteNormally[nextOffset];
|
||||
|
||||
if (nextOffset == endOffset) {
|
||||
final Instruction lastInstruction = flow.getInstructions().get(endOffset - 1);
|
||||
isNormal = !(lastInstruction instanceof GoToInstruction && ((GoToInstruction)lastInstruction).isReturn);
|
||||
}
|
||||
|
||||
isNormal |= throwToOffset <= endOffset && !isLeaf(nextOffset) && canCompleteNormally[nextOffset];
|
||||
}
|
||||
else {
|
||||
isNormal = canCompleteNormally[nextOffset];
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
class Test {
|
||||
public interface A<E extends Throwable> {
|
||||
Object call() throws E;
|
||||
}
|
||||
|
||||
public interface B<E extends Throwable> {
|
||||
void call() throws E;
|
||||
}
|
||||
|
||||
static Object method(A lambda) {
|
||||
System.out.println("A::");
|
||||
try {
|
||||
lambda.call();
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static void method(B lambda) {
|
||||
System.out.println("B::");
|
||||
try {
|
||||
lambda.call();
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static Object returns(String s) throws Exception {
|
||||
System.out.println(s); return null;
|
||||
}
|
||||
|
||||
static void voids(String s) throws Exception {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
method(() -> {
|
||||
voids("-> B");
|
||||
});
|
||||
|
||||
|
||||
method(() -> voids("-> B"));
|
||||
|
||||
method(() -> {
|
||||
return returns("-> A");
|
||||
});
|
||||
|
||||
method(() -> returns("-> A") );
|
||||
|
||||
method(() -> {
|
||||
returns("-> B");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+4
@@ -47,6 +47,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVoidValueCompatibilityCantCompleteNormallyWithCallWithExceptionAsLastReturnStatement() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIDEA102800() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user