Skip to content

Commit 7220dd8

Browse files
Add more record tests and only run them on java >= 16
Co-authored-by: Guillaume Martres <[email protected]>
1 parent 5bdd4c9 commit 7220dd8

File tree

7 files changed

+88
-18
lines changed

7 files changed

+88
-18
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CompilationTests {
2929

3030
@Test def pos: Unit = {
3131
implicit val testGroup: TestGroup = TestGroup("compilePos")
32-
aggregateTests(
32+
var tests = List(
3333
compileFile("tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")),
3434
compileFile("tests/pos-special/utf8encoded.scala", explicitUTF8),
3535
compileFile("tests/pos-special/utf16encoded.scala", explicitUTF16),
@@ -65,8 +65,13 @@ class CompilationTests {
6565
compileFile("tests/pos-special/extend-java-enum.scala", defaultOptions.and("-source", "3.0-migration")),
6666
compileFile("tests/pos-custom-args/help.scala", defaultOptions.and("-help", "-V", "-W", "-X", "-Y")),
6767
compileFile("tests/pos-custom-args/i13044.scala", defaultOptions.and("-Xmax-inlines:33")),
68-
compileFile("tests/pos-custom-args/jdk-8-app.scala", defaultOptions.and("-release:8")),
69-
).checkCompile()
68+
compileFile("tests/pos-custom-args/jdk-8-app.scala", defaultOptions.and("-release:8"))
69+
)
70+
71+
if scala.util.Properties.isJavaAtLeast("16") then
72+
tests ::= compileFilesInDir("tests/pos-java16+", defaultOptions.and("-Ysafe-init"))
73+
74+
aggregateTests(tests*).checkCompile()
7075
}
7176

7277
@Test def rewrites: Unit = {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
object C:
2+
def useR1: Unit =
3+
// constructor signature
4+
val r = R1(123, "hello")
5+
6+
// accessors
7+
val i: Int = r.i
8+
val s: String = r.s
9+
10+
// methods
11+
val iRes: Int = r.getInt()
12+
val sRes: String = r.getString()
13+
14+
// supertype
15+
val record: java.lang.Record = r
16+
17+
def useR2: Unit =
18+
// constructor signature
19+
val r2 = R2.R(123, "hello")
20+
21+
// accessors signature
22+
val i: Int = r2.i
23+
val s: String = r2.s
24+
25+
// method
26+
val i2: Int = r2.getInt
27+
28+
// supertype
29+
val isIntLike: IntLike = r2
30+
val isRecord: java.lang.Record = r2
31+
32+
def useR3 =
33+
// constructor signature
34+
val r3 = R3(123, 42L, "hi")
35+
new R3("hi", 123)
36+
// accessors signature
37+
val i: Int = r3.i
38+
val l: Long = r3.l
39+
val s: String = r3.s
40+
// method
41+
val l2: Long = r3.l(43L, 44L)
42+
// supertype
43+
val isRecord: java.lang.Record = r3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait IntLike:
2+
def getInt: Int
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class R2 {
2+
final record R(int i, String s) implements IntLike {
3+
public int getInt() {
4+
return i;
5+
}
6+
7+
// Canonical constructor
8+
// public R(int i, java.lang.String s) {
9+
// this.i = i;
10+
// this.s = s.intern();
11+
// }
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public record R3(int i, long l, String s) {
2+
3+
// User-specified accessor
4+
public int i() {
5+
return i + 1; // evil >:)
6+
}
7+
8+
// Not an accessor - too many parameters
9+
public long l(long a1, long a2) {
10+
return a1 + a2;
11+
}
12+
13+
// Secondary constructor
14+
public R3(String s, int i) {
15+
this(i, 42L, s);
16+
}
17+
18+
// Compact constructor
19+
public R3 {
20+
s = s.intern();
21+
}
22+
}

tests/pos/java-records/FromScala.scala

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)