Skip to content

Commit 2bde392

Browse files
committed
Don't generate specialized overrides in traits
The term "specialized override" is used to describe a method in a synthetic specialized subclass that generically substitutes the specialized type args into the siganture of a generic method. For example, `trait T[@SPEC A] { def t(a: A) }` gives rise to `def t(a: Int)` under the type environment `A=Int`. This commit avoids doing this for specialized traits, only classes have these overrides now. The motivation is to make it simpler to use specialized interfaces (like `T$mcI$sp` from the example above) as Java functional interfaces.
1 parent 4c8aab0 commit 2bde392

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,19 +697,19 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
697697
else
698698
debuglog("conflicting env for " + m + " env: " + env)
699699
}
700-
else if (m.isDeferred) { // abstract methods
700+
else if (m.isDeferred && m.isSpecialized) { // abstract methods
701701
val specMember = enterMember(cloneInSpecializedClass(m, _ | DEFERRED))
702702
// debuglog("deferred " + specMember.fullName + " remains abstract")
703703

704704
info(specMember) = new Abstract(specMember)
705705
// was: new Forward(specMember) {
706706
// override def target = m.owner.info.member(specializedName(m, env))
707707
// }
708-
} else if (m.isMethod && !m.hasAccessorFlag) { // other concrete methods
708+
} else if (!sClass.isTrait && m.isMethod && !m.hasAccessorFlag) { // other concrete methods
709709
// log("other concrete " + m)
710710
forwardToOverload(m)
711711

712-
} else if (m.isMethod && m.hasFlag(LAZY)) {
712+
} else if (!sClass.isTrait && m.isMethod && m.hasFlag(LAZY)) {
713713
forwardToOverload(m)
714714

715715
} else if (m.isValue && !m.isMethod && !m.hasFlag(LAZY)) { // concrete value definition
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
public abstract void T$mcI$sp.t(int)
21
public abstract void T.t(java.lang.Object)
32
0
43
0

test/files/run/trait-default-specialize.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
trait T[@specialized A] {
1+
trait T[@specialized(Int) A] {
22
def t(a: A): Unit
33
}
44

0 commit comments

Comments
 (0)