Skip to content
Permalink
Browse files

GenASM-based fix for SI-4804. Fix of the same for GenJVM pending.

  • Loading branch information
magarciaEPFL committed Jun 1, 2012
1 parent 71006c0 commit fb249b044d2679936c969b16fce9e19646a0b310
Showing with 13 additions and 21 deletions.
  1. +13 −21 src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -1395,7 +1395,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
// typestate: entering mode with valid call sequences:
// ( visitInnerClass | visitField | visitMethod )* visitEnd

if (isStaticModule(c.symbol) || serialVUID != None || isParcelableClass) {
if (isStaticModule(c.symbol) || isParcelableClass) {

if (isStaticModule(c.symbol)) { addModuleInstanceField() }
addStaticInit(c.lookupStaticCtor)
@@ -1423,6 +1423,18 @@ abstract class GenASM extends SubComponent with BytecodeWriters {

}

// add static serialVersionUID field if `clasz` annotated with `@SerialVersionUID(uid: Long)`
serialVUID foreach { value =>
val fieldName = "serialVersionUID"
jclass.visitField(
PublicStaticFinal,
fieldName,
tdesc_long,
null, // no java-generic-signature
value
).visitEnd()
}

clasz.fields foreach genField
clasz.methods foreach { im => genMethod(im, c.symbol.isInterface) }

@@ -1645,15 +1657,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
lastBlock emit CALL_METHOD(m.symbol.enclClass.primaryConstructor, Static(true))
}

// add serialVUID code
serialVUID foreach { value =>
val fieldName = "serialVersionUID"
val fieldSymbol = clasz.symbol.newValue(newTermName(fieldName), NoPosition, Flags.STATIC | Flags.FINAL) setInfo LongClass.tpe
clasz addField new IField(fieldSymbol)
lastBlock emit CONSTANT(Constant(value))
lastBlock emit STORE_FIELD(fieldSymbol, true)
}

if (isParcelableClass) { addCreatorCode(lastBlock) }

lastBlock emit RETURN(UNIT)
@@ -1684,17 +1687,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
thisName, INSTANCE_CONSTRUCTOR_NAME, mdesc_arglessvoid)
}

serialVUID foreach { value =>
val fieldName = "serialVersionUID"
jclass.visitField(
PublicStaticFinal,
fieldName,
tdesc_long,
null, // no java-generic-signature
value // TODO confirm whether initial value here is behaviorally equiv to fjbg's emitPUSH emitPUTSTATIC
).visitEnd()
}

if (isParcelableClass) { legacyAddCreatorCode(clinit) }

clinit.visitInsn(asm.Opcodes.RETURN)

0 comments on commit fb249b0

Please sign in to comment.
You can’t perform that action at this time.