Skip to content

Commit 7872ea4

Browse files
committed
Merge pull request #3738 from retronym/ticket/8574
SI-8574 Copy @serialversionuid, etc, to specialized subclasses
2 parents c763d84 + f9abdce commit 7872ea4

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
538538
bytecodeClazz.info
539539

540540
val sClass = clazz.owner.newClass(clazzName, clazz.pos, (clazz.flags | SPECIALIZED) & ~CASE)
541+
sClass.setAnnotations(clazz.annotations) // SI-8574 important that the subclass picks up @SerialVersionUID, @strictfp, etc.
541542

542543
def cloneInSpecializedClass(member: Symbol, flagFn: Long => Long, newName: Name = null) =
543544
member.cloneSymbol(sClass, flagFn(member.flags | SPECIALIZED), newName)

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
16871687

16881688
val sameSourceFile = context.unit.source.file == psym.sourceFile
16891689

1690-
if (psym.hasDeprecatedInheritanceAnnotation && !sameSourceFile) {
1690+
if (!isPastTyper && psym.hasDeprecatedInheritanceAnnotation && !sameSourceFile) {
16911691
val suffix = psym.deprecatedInheritanceMessage map (": " + _) getOrElse ""
16921692
val msg = s"inheritance from ${psym.fullLocationString} is deprecated$suffix"
16931693
unit.deprecationWarning(parent.pos, msg)

test/files/neg/t6162-inheritance.check

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ object SubT extends T
77
usage.scala:8: warning: inheritance from trait S in package t6126 is deprecated
88
new S {
99
^
10-
usage.scala:3: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version.
11-
class SubFoo extends Foo
12-
^
13-
usage.scala:5: warning: inheritance from trait T in package t6126 is deprecated
14-
object SubT extends T
15-
^
1610
error: No warnings can be incurred under -Xfatal-warnings.
17-
5 warnings found
11+
three warnings found
1812
one error found

test/files/run/t8574.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import annotation._
2+
3+
@SerialVersionUID(42) @strictfp class Foo[@specialized(Int) T] extends Serializable {
4+
def foo(t: T) = t
5+
}
6+
7+
object Test extends App {
8+
def checkUID(cls: Class[_], expected: Long) = {
9+
val actual = java.io.ObjectStreamClass.lookup(cls).getSerialVersionUID
10+
assert(actual == expected, s"$actual != expected for ${cls}")
11+
}
12+
def checkStrictFp(cls: Class[_]) = {
13+
import java.lang.reflect._
14+
for (m <- cls.getDeclaredMethods) {
15+
val isStrict = Modifier.isStrict(m.getModifiers)
16+
assert(isStrict, cls)
17+
}
18+
}
19+
def check(x: AnyRef) {
20+
checkUID(x.getClass, 42)
21+
checkStrictFp(x.getClass)
22+
}
23+
24+
check(new Foo[String])
25+
check(new Foo[Int])
26+
}
27+

0 commit comments

Comments
 (0)