Skip to content

Commit 1863077

Browse files
Merge pull request #7767 from dotty-staging/fix-#7735
Fix #7735: Handle case of seq literals of singleton primitive types
2 parents 255a538 + c7f4898 commit 1863077

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
453453
* kind for the given element type in `elemTpe`.
454454
*/
455455
def wrapArray(tree: Tree, elemtp: Type)(implicit ctx: Context): Tree =
456-
ref(defn.getWrapVarargsArrayModule)
456+
val wrapper = ref(defn.getWrapVarargsArrayModule)
457457
.select(wrapArrayMethodName(elemtp))
458458
.appliedToTypes(if (elemtp.isPrimitiveValueType) Nil else elemtp :: Nil)
459-
.appliedTo(tree)
459+
val actualElem = wrapper.tpe.widen.firstParamTypes.head
460+
wrapper.appliedTo(tree.ensureConforms(actualElem))
460461

461462
// ------ Creating typed equivalents of trees that exist only in untyped form -------
462463

compiler/src/dotty/tools/dotc/transform/SeqLiterals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class SeqLiterals extends MiniPhase {
3131
val arr = JavaSeqLiteral(tree.elems, tree.elemtpt)
3232
//println(i"trans seq $tree, arr = $arr: ${arr.tpe} ${arr.tpe.elemType}")
3333
val elemtp = tree.elemtpt.tpe
34-
wrapArray(arr, elemtp).withSpan(tree.span)
34+
wrapArray(arr, elemtp).withSpan(tree.span).ensureConforms(tree.tpe)
3535
}
3636
}

tests/pos/i7735.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def foo[A](as: A*): Int = ???
2+
val a = foo[1]()

tests/run/toplevel-stale/B_2.scala

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,59 @@ val y3 = {
3535
val x6 = summon[Ordering[(Int, Int, Int, Int, Int, Int)]]
3636
val x7 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int)]]
3737
val x8 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int, Int)]]
38-
}
38+
}
39+
40+
val y4 = {
41+
val x1 = summon[Ordering[Int]]
42+
val x2 = summon[Ordering[(Int, Int)]]
43+
val x3 = summon[Ordering[(Int, Int, Int)]]
44+
val x4 = summon[Ordering[(Int, Int, Int, Int)]]
45+
val x5 = summon[Ordering[(Int, Int, Int, Int, Int)]]
46+
val x6 = summon[Ordering[(Int, Int, Int, Int, Int, Int)]]
47+
val x7 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int)]]
48+
val x8 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int, Int)]]
49+
}
50+
51+
val y5 = {
52+
val x1 = summon[Ordering[Int]]
53+
val x2 = summon[Ordering[(Int, Int)]]
54+
val x3 = summon[Ordering[(Int, Int, Int)]]
55+
val x4 = summon[Ordering[(Int, Int, Int, Int)]]
56+
val x5 = summon[Ordering[(Int, Int, Int, Int, Int)]]
57+
val x6 = summon[Ordering[(Int, Int, Int, Int, Int, Int)]]
58+
val x7 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int)]]
59+
val x8 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int, Int)]]
60+
}
61+
62+
val y6 = {
63+
val x1 = summon[Ordering[Int]]
64+
val x2 = summon[Ordering[(Int, Int)]]
65+
val x3 = summon[Ordering[(Int, Int, Int)]]
66+
val x4 = summon[Ordering[(Int, Int, Int, Int)]]
67+
val x5 = summon[Ordering[(Int, Int, Int, Int, Int)]]
68+
val x6 = summon[Ordering[(Int, Int, Int, Int, Int, Int)]]
69+
val x7 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int)]]
70+
val x8 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int, Int)]]
71+
}
72+
73+
val y7 = {
74+
val x1 = summon[Ordering[Int]]
75+
val x2 = summon[Ordering[(Int, Int)]]
76+
val x3 = summon[Ordering[(Int, Int, Int)]]
77+
val x4 = summon[Ordering[(Int, Int, Int, Int)]]
78+
val x5 = summon[Ordering[(Int, Int, Int, Int, Int)]]
79+
val x6 = summon[Ordering[(Int, Int, Int, Int, Int, Int)]]
80+
val x7 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int)]]
81+
val x8 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int, Int)]]
82+
}
83+
84+
val y8 = {
85+
val x1 = summon[Ordering[Int]]
86+
val x2 = summon[Ordering[(Int, Int)]]
87+
val x3 = summon[Ordering[(Int, Int, Int)]]
88+
val x4 = summon[Ordering[(Int, Int, Int, Int)]]
89+
val x5 = summon[Ordering[(Int, Int, Int, Int, Int)]]
90+
val x6 = summon[Ordering[(Int, Int, Int, Int, Int, Int)]]
91+
val x7 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int)]]
92+
val x8 = summon[Ordering[(Int, Int, Int, Int, Int, Int, Int, Int)]]
93+
}

0 commit comments

Comments
 (0)