Skip to content

Commit 23b02c8

Browse files
srikanth-sankaraniloveeclipse
authored andcommitted
[Records] Generic signature is not preserved for compact constructors by
PR #3928 * Fixes #3951
1 parent 11acaf5 commit 23b02c8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,9 @@ private MethodBinding resolveTypesWithSuspendedTempErrorHandlingPolicy(MethodBin
24002400
method.parameters = new TypeBinding[length];
24012401
for (int i = 0; i < length; i++ ) {
24022402
method.parameters[i] = rcbs[i].type;
2403+
TypeBinding leafType = rcbs[i].type == null ? null : rcbs[i].type.leafComponentType();
2404+
if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0)
2405+
method.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
24032406
}
24042407
}
24052408

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10176,4 +10176,49 @@ public record X (int _) {
1017610176
"As of release 22, '_' is only allowed to declare unnamed patterns, local variables, exception parameters or lambda parameters\n" +
1017710177
"----------\n");
1017810178
}
10179+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3951
10180+
// [Records] Generic signature is not preserved for compact constructors by PR #3928
10181+
public void testIssue3951() throws Exception {
10182+
runConformTest(
10183+
new String[] {
10184+
"X.java",
10185+
"""
10186+
import java.lang.annotation.Annotation;
10187+
import java.util.List;
10188+
10189+
public record X (List<Class<? extends Annotation>> classes) {
10190+
public X {
10191+
10192+
}
10193+
10194+
public static void main(String [] args) {
10195+
System.out.println("Ok!");
10196+
}
10197+
}
10198+
"""
10199+
},
10200+
"Ok!");
10201+
String expectedOutput =
10202+
" // Method descriptor #10 (Ljava/util/List;)V\n" +
10203+
" // Signature: (Ljava/util/List<Ljava/lang/Class<+Ljava/lang/annotation/Annotation;>;>;)V\n" +
10204+
" // Stack: 2, Locals: 2\n" +
10205+
" public X(java.util.List classes);\n" +
10206+
" 0 aload_0 [this]\n" +
10207+
" 1 invokespecial java.lang.Record() [13]\n" +
10208+
" 4 aload_0 [this]\n" +
10209+
" 5 aload_1 [classes]\n" +
10210+
" 6 putfield X.classes : java.util.List [16]\n" +
10211+
" 9 return\n" +
10212+
" Line numbers:\n" +
10213+
" [pc: 0, line: 5]\n" +
10214+
" [pc: 4, line: 7]\n" +
10215+
" Local variable table:\n" +
10216+
" [pc: 0, pc: 10] local: this index: 0 type: X\n" +
10217+
" [pc: 0, pc: 10] local: classes index: 1 type: java.util.List\n" +
10218+
" Local variable type table:\n" +
10219+
" [pc: 0, pc: 10] local: classes index: 1 type: java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>>\n" +
10220+
" Method Parameters:\n" +
10221+
" mandated classes\n";
10222+
verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
10223+
}
1017910224
}

0 commit comments

Comments
 (0)