diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-08-10 21:32:51 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-08-11 14:26:27 +1000 |
commit | 2bde3928833ae194fc7e2094b8955112b70fd31f (patch) | |
tree | 5a3073459a8dcdb7349a47c032f0f8fa8266401d | |
parent | 4c8aab0abbd8aee05866aae9c866f3e3142c5b85 (diff) | |
download | scala-2bde3928833ae194fc7e2094b8955112b70fd31f.tar.gz scala-2bde3928833ae194fc7e2094b8955112b70fd31f.tar.bz2 scala-2bde3928833ae194fc7e2094b8955112b70fd31f.zip |
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.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala | 6 | ||||
-rw-r--r-- | test/files/run/trait-default-specialize.check | 1 | ||||
-rw-r--r-- | test/files/run/trait-default-specialize.scala | 2 |
3 files changed, 4 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 53a1347a48..998f0b22cb 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -697,7 +697,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { else debuglog("conflicting env for " + m + " env: " + env) } - else if (m.isDeferred) { // abstract methods + else if (m.isDeferred && m.isSpecialized) { // abstract methods val specMember = enterMember(cloneInSpecializedClass(m, _ | DEFERRED)) // debuglog("deferred " + specMember.fullName + " remains abstract") @@ -705,11 +705,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { // was: new Forward(specMember) { // override def target = m.owner.info.member(specializedName(m, env)) // } - } else if (m.isMethod && !m.hasAccessorFlag) { // other concrete methods + } else if (!sClass.isTrait && m.isMethod && !m.hasAccessorFlag) { // other concrete methods // log("other concrete " + m) forwardToOverload(m) - } else if (m.isMethod && m.hasFlag(LAZY)) { + } else if (!sClass.isTrait && m.isMethod && m.hasFlag(LAZY)) { forwardToOverload(m) } else if (m.isValue && !m.isMethod && !m.hasFlag(LAZY)) { // concrete value definition diff --git a/test/files/run/trait-default-specialize.check b/test/files/run/trait-default-specialize.check index aedd8c9538..1034d1c703 100644 --- a/test/files/run/trait-default-specialize.check +++ b/test/files/run/trait-default-specialize.check @@ -1,4 +1,3 @@ -public abstract void T$mcI$sp.t(int) public abstract void T.t(java.lang.Object) 0 0 diff --git a/test/files/run/trait-default-specialize.scala b/test/files/run/trait-default-specialize.scala index 7b57ddc1eb..6faa9d5f47 100644 --- a/test/files/run/trait-default-specialize.scala +++ b/test/files/run/trait-default-specialize.scala @@ -1,4 +1,4 @@ -trait T[@specialized A] { +trait T[@specialized(Int) A] { def t(a: A): Unit } |