Skip to content

Commit 1f69840

Browse files
committed
Fix compile errors for records with custom constructors, update JDT
1 parent 7f556af commit 1f69840

10 files changed

Lines changed: 120 additions & 10 deletions

File tree

.github/workflows/full-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ jobs:
3333
- name: Checkout GWT tools into a sibling directory
3434
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
3535
with:
36-
repository: 'gwtproject/tools'
36+
repository: 'zbynek/tools'
3737
path: 'tools'
38+
ref: 'jdt'
3839
- name: Set up JDK ${{ matrix.java-version }}
3940
# GWT requires Java 17+ to build
4041
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 #v5.4.0

.github/workflows/quick-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
- name: Checkout GWT tools into a sibling directory
2121
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
2222
with:
23-
repository: 'gwtproject/tools'
23+
repository: 'zbynek/tools'
2424
path: 'tools'
25+
ref: 'jdt'
2526
- name: Set up JDK ${{ matrix.java-version }}
2627
# GWT presently requires Java 17+ to build
2728
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 #v5.4.0

dev/build.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<include name="apache/tapestry-util-text-4.0.2.jar"/>
6464
<include name="apache/ant-zipscanner/ant-zipscanner-1.6.5-1-rebased.jar"/>
6565
<include name="colt/colt-1.2.jar"/>
66-
<include name="eclipse/3.33.0/*.jar"/>
66+
<include name="eclipse/3.37.0/*.jar"/>
6767
<include name="objectweb/asm-9.10.1/asm-9.10.1.jar"/>
6868
<include name="objectweb/asm-9.10.1/asm-commons-9.10.1.jar"/>
6969
<include name="objectweb/asm-9.10.1/asm-util-9.10.1.jar"/>
@@ -125,7 +125,7 @@
125125
<zipfileset src="${gwt.tools.lib}/apache/tapestry-util-text-4.0.2.jar"/>
126126
<zipfileset src="${gwt.tools.lib}/apache/ant-zipscanner/ant-zipscanner-1.6.5-1-rebased.jar"/>
127127
<zipfileset src="${gwt.tools.lib}/colt/colt-1.2.jar"/>
128-
<zipgroupfileset dir="${gwt.tools.lib}/eclipse/3.33.0">
128+
<zipgroupfileset dir="${gwt.tools.lib}/eclipse/3.37.0">
129129
<include name="**/*.jar"/>
130130
</zipgroupfileset>
131131
<zipfileset src="${gwt.tools.lib}/guava/guava-33.0/guava-33.0.0-jre-rebased.jar"/>
@@ -222,7 +222,7 @@
222222
<pathelement location="${gwt.tools.lib}/objectweb/asm-9.10.1/asm-util-9.10.1.jar"/>
223223
<pathelement
224224
location="${gwt.tools.lib}/apache/commons/commons-collections-3.2.2.jar"/>
225-
<fileset dir="${gwt.tools.lib}/eclipse/3.33.0">
225+
<fileset dir="${gwt.tools.lib}/eclipse/3.37.0">
226226
<include name="**/*.jar"/>
227227
</fileset>
228228
<pathelement

dev/core/src/com/google/gwt/dev/javac/testing/impl/JavaResourceBase.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,54 @@ public class JavaResourceBase {
248248
"package java.util;",
249249
"public interface Map<K,V> { }");
250250

251+
public static final MockJavaResource METHOD_HANDLE =
252+
createMockJavaResource("java.lang.invoke.MethodHandle",
253+
"""
254+
package java.lang.invoke;
255+
public abstract class MethodHandle { }
256+
""");
257+
258+
public static final MockJavaResource METHOD_HANDLES =
259+
createMockJavaResource("java.lang.invoke.MethodHandles",
260+
"""
261+
package java.lang.invoke;
262+
public class MethodHandles {
263+
public static final class Lookup {
264+
public MethodHandle findVirtual(Class<?> refc, String name,
265+
MethodType type) {
266+
return null;
267+
}
268+
269+
public MethodHandle findStatic(Class<?> refc, String name,
270+
MethodType type) {
271+
return null;
272+
}
273+
}
274+
275+
public static Lookup lookup() {
276+
return null;
277+
}
278+
}
279+
""");
280+
281+
public static final MockJavaResource METHOD_TYPE =
282+
createMockJavaResource("java.lang.invoke.MethodType",
283+
"""
284+
package java.lang.invoke;
285+
public final class MethodType {
286+
public static MethodType methodType(Class<?> rtype, Class<?> ptype0,
287+
Class<?>... ptypes) {
288+
return null;
289+
}
290+
public static MethodType methodType(Class<?> rtype) {
291+
return null;
292+
}
293+
public static MethodType genericMethodType(int objectArgCount) {
294+
return null;
295+
}
296+
}
297+
""");
298+
251299
public static final MockJavaResource NO_CLASS_DEF_FOUND_ERROR =
252300
createMockJavaResource("java.lang.NoClassDefFoundError",
253301
"package java.lang;",
@@ -364,6 +412,13 @@ public class JavaResourceBase {
364412
"public final class StringBuilder {",
365413
"}");
366414

415+
public static final MockJavaResource STRING_CONCAT_FACTORY =
416+
createMockJavaResource("java.lang.invoke.StringConcatFactory",
417+
"""
418+
package java.lang.invoke;
419+
public final class StringConcatFactory {}
420+
""");
421+
367422
public static final MockJavaResource SUPPRESS_WARNINGS =
368423
createMockJavaResource("java.lang.SuppressWarnings",
369424
"package java.lang;",
@@ -467,7 +522,8 @@ public static MockJavaResource[] getStandardResources() {
467522
AUTOCLOSEABLE, ANNOTATION, ARRAY_LIST, BYTE, BOOLEAN, CHARACTER, CHAR_SEQUENCE, CLASS,
468523
CLASS_NOT_FOUND_EXCEPTION, CLONEABLE, COLLECTION, COMPARABLE, DOUBLE, ENUM, EXCEPTION,
469524
ERROR, FUNCTIONALINTERFACE, FLOAT, INTEGER, IS_SERIALIZABLE, JAVASCRIPTEXCEPTION,
470-
JAVASCRIPTOBJECT, LIST, LONG, MAP, NO_CLASS_DEF_FOUND_ERROR, NUMBER, OBJECT, OBJECTMETHODS,
525+
JAVASCRIPTOBJECT, LIST, LONG, MAP, METHOD_HANDLES, NO_CLASS_DEF_FOUND_ERROR,
526+
NUMBER, OBJECT, OBJECTMETHODS, METHOD_HANDLE, METHOD_TYPE, STRING_CONCAT_FACTORY,
471527
OBJECTS, RECORD, RUNTIME_EXCEPTION, SERIALIZABLE, SHORT, STRING, STRING_BUILDER,
472528
SUPPRESS_WARNINGS, SYSTEM, THROWABLE, SPECIALIZE_METHOD, DO_NOT_AUTOBOX, JSTYPE,
473529
JSCONSTRUCTOR, JSPACKAGE, JSPROPERTY, JSMETHOD, JSIGNORE, JSFUNCTION, JSOVERLAY,

dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ private TypeBinding getFirstNonObjectInIntersection(IntersectionTypeBinding18 re
711711

712712
@Override
713713
public void endVisit(ConstructorDeclaration x, ClassScope scope) {
714+
if (isOverriddenCanonicalConstructor(x)) {
715+
return;
716+
}
714717
try {
715718
List<JStatement> statements = pop(x.statements);
716719
JStatement constructorCall = pop(x.constructorCall);
@@ -2596,6 +2599,9 @@ public boolean visit(Block x, BlockScope scope) {
25962599

25972600
@Override
25982601
public boolean visit(ConstructorDeclaration x, ClassScope scope) {
2602+
if (isOverriddenCanonicalConstructor(x)) {
2603+
return false;
2604+
}
25992605
try {
26002606
JConstructor method = (JConstructor) typeMap.get(x.binding);
26012607
assert !method.isExternal();
@@ -4331,6 +4337,9 @@ private void createMembers(TypeDeclaration x) {
43314337

43324338
if (x.methods != null) {
43334339
for (AbstractMethodDeclaration method : x.methods) {
4340+
if (isOverriddenCanonicalConstructor(method)) {
4341+
continue;
4342+
}
43344343
createMethod(method);
43354344
}
43364345
}
@@ -4400,6 +4409,9 @@ private void createMethod(AbstractMethodDeclaration x) {
44004409
if (x instanceof Clinit) {
44014410
return;
44024411
}
4412+
if (x.binding == null) {
4413+
throw new IllegalArgumentException("Missing method binding for " + x);
4414+
}
44034415
SourceInfo info = makeSourceInfo(x);
44044416
MethodBinding b = x.binding;
44054417
ReferenceBinding declaringClass = (ReferenceBinding) b.declaringClass.erasure();
@@ -4630,7 +4642,7 @@ private void createTypes(TypeDeclaration x) {
46304642
}
46314643
} catch (Throwable e) {
46324644
InternalCompilerException ice = translateException(null, e);
4633-
StringBuffer sb = new StringBuffer();
4645+
StringBuilder sb = new StringBuilder();
46344646
x.printHeader(0, sb);
46354647
ice.addNode(x.getClass().getName(), sb.toString(), info);
46364648
throw ice;
@@ -4679,7 +4691,7 @@ private void resolveTypeRefs(TypeDeclaration x) {
46794691
private InternalCompilerException getInternalCompilerException(TypeDeclaration x, Throwable e) {
46804692
JDeclaredType type = (JDeclaredType) typeMap.get(x.binding);
46814693
InternalCompilerException ice = translateException(null, e);
4682-
StringBuffer sb = new StringBuffer();
4694+
StringBuilder sb = new StringBuilder();
46834695
x.printHeader(0, sb);
46844696
ice.addNode(x.getClass().getName(), sb.toString(), type.getSourceInfo());
46854697
return ice;
@@ -4724,9 +4736,13 @@ private static boolean isSuperReference(Expression expression) {
47244736
return expression instanceof SuperReference || expression instanceof QualifiedSuperReference;
47254737
}
47264738

4739+
private boolean isOverriddenCanonicalConstructor(AbstractMethodDeclaration method) {
4740+
return method.binding == null && method.isCanonicalConstructor();
4741+
}
4742+
47274743
static class JdtPrivateHacks {
47284744
/**
4729-
* Reflective access to {@link ForeachStatement#collectionElementType}.
4745+
* Reflective access to {@link ForeachStatement}'s {@code collectionElementType} field.
47304746
*/
47314747
private static final Field collectionElementTypeField;
47324748

dev/core/test/com/google/gwt/dev/jjs/impl/SampleBytecodeOnlyMarkerAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
*/
1414
package com.google.gwt.dev.jjs.impl;
1515

16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
1619
/**
1720
* Annotation with no bytecode for GWT, and no members.
1821
*/
22+
@Target({ElementType.METHOD, ElementType.TYPE_USE})
1923
public @interface SampleBytecodeOnlyMarkerAnnotation {
2024
}

dev/core/test/com/google/gwt/dev/jjs/impl/SampleBytecodeOnlyNormalAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
*/
1414
package com.google.gwt.dev.jjs.impl;
1515

16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
1619
/**
1720
* Annotation with no bytecode for GWT, and multiple members.
1821
*/
22+
@Target({ElementType.METHOD, ElementType.TYPE_USE})
1923
public @interface SampleBytecodeOnlyNormalAnnotation {
2024
int a();
2125
int b();

dev/core/test/com/google/gwt/dev/jjs/impl/SampleBytecodeOnlySingleMemberAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
*/
1414
package com.google.gwt.dev.jjs.impl;
1515

16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
1619
/**
1720
* Annotation with no bytecode for GWT, and a single member.
1821
*/
22+
@Target({ElementType.METHOD, ElementType.TYPE_USE})
1923
public @interface SampleBytecodeOnlySingleMemberAnnotation {
2024
String value();
2125
}

maven/poms/gwt/pom-template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
<dependency>
268268
<groupId>org.eclipse.jdt</groupId>
269269
<artifactId>org.eclipse.jdt.core</artifactId>
270-
<version>3.33.0</version>
270+
<version>3.37.0</version>
271271
</dependency>
272272
</dependencies>
273273
</dependencyManagement>

user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java17Test.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.Arrays;
2222
import java.util.List;
23+
import java.util.Objects;
2324
import jsinterop.annotations.JsMethod;
2425
import jsinterop.annotations.JsProperty;
2526
import jsinterop.annotations.JsType;
@@ -140,6 +141,18 @@ record RecordWithStaticField() {
140141
public static String foo = "bar";
141142
}
142143

144+
record RecordWithDefaultConstructor(String foo) {
145+
public RecordWithDefaultConstructor {
146+
Objects.requireNonNull(foo);
147+
}
148+
}
149+
150+
record RecordWithExtraConstructor(String foo) {
151+
RecordWithExtraConstructor(int fooInt) {
152+
this(fooInt + "");
153+
}
154+
}
155+
143156
/**
144157
* Record type that takes a record as a component
145158
*/
@@ -207,6 +220,17 @@ public String toString() {
207220
assertFalse(new TopLevelRecord(null, 3).equals(new TopLevelRecord("abc", 3)));
208221
}
209222

223+
public void testRecordConstructors() {
224+
assertEquals("7", new RecordWithExtraConstructor(7).foo());
225+
assertEquals("7", new RecordWithDefaultConstructor("7").foo());
226+
try {
227+
new RecordWithDefaultConstructor(null).foo();
228+
fail("Should have thrown NPE");
229+
} catch (RuntimeException expected) {
230+
// expected
231+
}
232+
}
233+
210234
/**
211235
* Simple record with one property accessor, one default method accessor
212236
*/

0 commit comments

Comments
 (0)