Fixed #1143 (again).

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@16918 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
phaller 2009-01-14 14:39:31 +00:00
parent bc05b6fcd9
commit 08bea520b3
4 changed files with 74 additions and 1 deletions

View File

@ -49,6 +49,8 @@ abstract class CleanUp extends Transform {
private var localTyper: analyzer.Typer = null
private val serialIFace = definitions.getClass("java.io.Serializable")
private def classConstantMethod(pos: Position, sig: String): Symbol = classConstantMeth.get(sig) match {
case Some(meth) =>
meth
@ -747,7 +749,7 @@ abstract class CleanUp extends Transform {
// reference types must be marked as such.
isValueType(typeSym) ||
typeSym.hasAttribute(SerializableAttr) ||
(m.info.baseClasses exists { bc => bc hasAttribute SerializableAttr })
(m.info.baseClasses exists { bc => (bc hasAttribute SerializableAttr) || (bc == serialIFace) })
}
}

View File

@ -0,0 +1 @@
pass

View File

@ -0,0 +1,4 @@
import java.io.Serializable;
public interface Marker extends Serializable {
}

View File

@ -0,0 +1,66 @@
object Serialize {
@throws(classOf[java.io.IOException])
def write[A](o: A): Array[Byte] = {
val ba = new java.io.ByteArrayOutputStream(512)
val out = new java.io.ObjectOutputStream(ba)
out.writeObject(o)
out.close()
ba.toByteArray()
}
@throws(classOf[java.io.IOException])
@throws(classOf[ClassNotFoundException])
def read[A](buffer: Array[Byte]): A = {
val in =
new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer))
in.readObject().asInstanceOf[A]
}
}
@serializable
@SerialVersionUID(1L)
class VarModel[T]( getter: => T, setter: T => Unit )
{
Serialize.write(getter)
Serialize.write(setter)
def this( getter: => T ) = this( getter, null )
def getObject: AnyRef = getter.asInstanceOf[AnyRef]
def setObject( v: AnyRef ) = {
if( setter==null )
throw new RuntimeException( "Tried to set readonly model!")
setter( v.asInstanceOf[T] )
}
def detach = ()
}
@serializable
@SerialVersionUID(1L)
class Printer( p: VarModel[String] ) {
def print = println( p.getObject );
}
class Component extends Marker { }
class Form extends Component { }
@serializable
@SerialVersionUID(1L)
class Main {
var pass = "pass"
def main(args : Array[String]) : Unit = {
val f = new Form {
val p = new Printer( new VarModel( pass, pass=_ ) );
p.print
}
()
}
}
object Test {
def main(args: Array[String]) {
(new Main).main(Array[String]())
}
}