Skip to content

Commit 10cfca3

Browse files
committed
Fix regression in specialization of traits
Introduced in 2bde392 The previous commit defends the intended part of the change, which was discussed in scala/scala-dev#36
1 parent 18d2a9b commit 10cfca3

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
763763
// was: new Forward(specMember) {
764764
// override def target = m.owner.info.member(specializedName(m, env))
765765
// }
766-
} else if (!sClass.isTrait && m.isMethod && !m.hasAccessorFlag) { // other concrete methods
766+
} else if (!(sClass.isTrait && m.isDeferred) && m.isMethod && !m.hasAccessorFlag) { // other concrete methods
767767
// log("other concrete " + m)
768768
forwardToOverload(m)
769769

770-
} else if (!sClass.isTrait && m.isMethod && m.hasFlag(LAZY)) {
770+
} else if (!(sClass.isTrait && m.isDeferred) && m.isMethod && m.hasFlag(LAZY)) {
771771
forwardToOverload(m)
772772

773773
} else if (m.isValue && !m.isMethod) { // concrete value definition

test/files/run/t10277.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
put$mcJ$sp
2+
fillRange$mcJ$sp
3+
fillRange$mcJ$sp$
4+
fillRange$mcJ$sp

test/files/run/t10277.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
trait Column {}
2+
3+
trait TypedColumn[@specialized(Long, Double) T] extends Column {
4+
def put(idx: Int, value: T): Unit
5+
6+
def fillRange(start: Int, len: Int, value: T): Unit = {
7+
var idx = start
8+
val end = start + len
9+
while (idx < end) {
10+
put(idx, value)
11+
idx += 1
12+
}
13+
}
14+
}
15+
16+
final class LongColumn extends TypedColumn[Long] {
17+
override def put(idx: Int, value: Long): Unit = {
18+
val frames = Thread.currentThread().getStackTrace.toList.drop(1).takeWhile(_.getMethodName != "main")
19+
println(frames.map(_.getMethodName).mkString("\n"))
20+
}
21+
}
22+
23+
object Test {
24+
def main(args: Array[String]): Unit = {
25+
val c = new LongColumn
26+
c.fillRange(0, 1, 10L)
27+
}
28+
}

test/files/run/t10277b.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
g$mcI$sp
2+
g$mcI$sp$
3+
g$mcI$sp
4+
f$mcI$sp

test/files/run/t10277b.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
trait A[@specialized(Int) T] {
2+
def f(x: T): Unit
3+
}
4+
5+
trait B[@specialized(Int) T] {
6+
def g(x: T): Unit = {
7+
val frames = Thread.currentThread().getStackTrace.toList.drop(1).takeWhile(_.getMethodName != "main")
8+
println(frames.map(_.getMethodName).mkString("\n"))
9+
}
10+
}
11+
12+
class C[@specialized(Int) T] extends A[T] with B[T] {
13+
def f(x: T): Unit = g(x)
14+
}
15+
16+
object Test {
17+
def main(args: Array[String]): Unit = {
18+
new C[Int].f(0)
19+
}
20+
}

0 commit comments

Comments
 (0)