Skip to content

Commit 585c888

Browse files
hansonrhansonr
authored andcommitted
interface extends interface with duplicate default method
1 parent 0507f97 commit 585c888

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

sources/net.sf.j2s.java.core/src/test/Test_Interface.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ public static void main(String[] args) {
5454

5555
}
5656

57+
public default int isTestInterface() {
58+
return 0;
59+
}
5760
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package test;
2+
3+
public interface Test_Interface1 extends Test_Interface {
4+
@Override
5+
public default int isTestInterface() {
6+
return 1;
7+
}
8+
}

sources/net.sf.j2s.java.core/src/test/Test_Interface2.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
package test;
22

3-
public class Test_Interface2 implements Test_Interface {
3+
public class Test_Interface2 extends Test_ implements Test_Interface {
44

55
static int x = 5;
66

7+
public static class I0 implements Test_Interface {
8+
9+
}
10+
11+
public static class I1 implements Test_Interface1 {
12+
13+
}
14+
15+
public int isTestInterface() {return 2;}
16+
717
public static void main(String[] args) {
8-
ClassLoader.getSystemClassLoader().setClassAssertionStatus("test.Test_Interface", true);
18+
919
System.out.println("in the interface " + x + " " + y + " " + s.length);
10-
if (!"5 y".equals(x + " " + y))
11-
throw new AssertionError();
12-
if (Test_Interface3.doTest(3) != 4)
13-
throw new AssertionError();
20+
assert("5 y".equals(x + " " + y));
21+
System.out.println("in the interface " + Test_Interface3.doTest(3));
22+
assert(Test_Interface3.doTest(3) == 4);
23+
24+
// test of public default override
25+
assert(new Test_Interface2().isTestInterface() == 2);
26+
assert(new I0().isTestInterface() == 0);
27+
assert(new I1().isTestInterface() == 1);
28+
29+
1430
System.out.println("Test_Interface2 OK");
1531
}
1632

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 2020.12.11 fixing interface extended override of interface default
1011
// BH 2020.12.06 changing Long maxval to 0x1FFFFFFFFFFFFF from 0x20000000000000
1112
// BH 2020.12.06 better error checking for TYPE.parseTYPE(string)
1213
// BH 2020.07.27 fix for inner class array names
@@ -1577,6 +1578,7 @@ var excludeSuper = function(o) {
15771578
|| o == "$init$"
15781579
|| o == "$init0$"
15791580
|| o == "$static$"
1581+
|| o == "$defaults$"
15801582
|| o == "$clinit$"
15811583
|| o == "$classes$"
15821584
|| o == "$fields$"
@@ -1607,10 +1609,12 @@ var copyStatics = function(clazzFrom, clazzThis, isInterface) {
16071609
clazzThis.prototype[o] = clazzFrom.prototype[o];
16081610
}
16091611
}
1610-
__allowOverwriteClass = false;
1611-
if (clazzFrom.$defaults$)
1612+
if (clazzFrom.$defaults$) {
1613+
__allowOverwriteClass = false;
1614+
clazzThis.$defaults$ && clazzThis.$defaults$(clazzThis);
16121615
clazzFrom.$defaults$(clazzThis);
1613-
__allowOverwriteClass = true;
1616+
__allowOverwriteClass = true;
1617+
}
16141618
}
16151619
}
16161620

@@ -5687,7 +5691,7 @@ var caller = arguments.callee.caller;
56875691
var i = 0;
56885692
while (caller.caller) {
56895693
caller = caller.caller;
5690-
if (++i > 3 && caller.exClazz)
5694+
if (++i > 3 && caller.exClazz || caller == Clazz.load)
56915695
break;
56925696
}
56935697
var superCaller = null;

0 commit comments

Comments
 (0)