Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions java/com/google/turbine/binder/TypeBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,18 @@ private SourceTypeBoundClass bind() {
.build();
}

ImmutableList<FieldInfo> fields =
base.kind().equals(TurbineTyKind.RECORD)
? recordFields(components)
: bindFields(scope, base.decl().members());
ImmutableList<FieldInfo> boundFields = bindFields(scope, base.decl().members());
ImmutableList<FieldInfo> fields;
if (base.kind().equals(TurbineTyKind.RECORD)) {
fields =
ImmutableList.<FieldInfo>builder()
// Implicit record fields will be output before any declared fields.
.addAll(recordFields(components))
.addAll(boundFields)
.build();
} else {
fields = boundFields;
}

return new SourceTypeBoundClass(
interfaceTypes.build(),
Expand Down
2 changes: 2 additions & 0 deletions javatests/com/google/turbine/lower/LowerIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class LowerIntegrationTest {
private static final ImmutableMap<String, Integer> SOURCE_VERSION =
ImmutableMap.ofEntries(
entry("record.test", 16),
entry("record_fields.test", 16),
entry("record2.test", 16),
entry("record_tostring.test", 16),
entry("record_ctor.test", 16),
Expand Down Expand Up @@ -291,6 +292,7 @@ public static Iterable<Object[]> parameters() {
"record.test",
"record2.test",
"record_ctor.test",
"record_fields.test",
"record_getter_override.test",
"record_tostring.test",
"rek.test",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== R.java ===

record R(int x, int y) {
static final int X = 42;
static final R r = new R(0, 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,11 @@ public void recordProcessing() throws IOException {
ImmutableList<Tree.CompUnit> units =
parseUnit(
"=== R.java ===", //
"record R<T>(@Deprecated T x, int... y) {}");
"""
record R<T>(@Deprecated T x, int... y) {
static final int Z = 42;
}
""");
TurbineError e = runProcessors(units, new RecordProcessor());
assertThat(
e.diagnostics().stream()
Expand All @@ -620,14 +624,16 @@ public void recordProcessing() throws IOException {
"RECORD R java.lang.Record",
"RECORD_COMPONENT x",
"RECORD_COMPONENT y",
"CONSTRUCTOR R(T,int[])",
"FIELD x",
"FIELD y",
"FIELD Z",
"CONSTRUCTOR R(T,int[])", // javac puts the constructor before FIELD Z
"METHOD toString()",
"METHOD hashCode()",
"METHOD equals(java.lang.Object)",
"METHOD x()",
"METHOD y()",
"FIELD x",
"FIELD y");
"METHOD y()")
.inOrder();
}

@SupportedAnnotationTypes("*")
Expand Down
Loading