diff options
author | Martin Odersky <odersky@gmail.com> | 2016-03-10 17:15:20 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-03-10 18:50:59 +0100 |
commit | 65639176ce59fd64cbecd90bf5680e64e471938f (patch) | |
tree | 2b7ebeebaa8b54bb228e6c571b8536fe4d5809bc /src/dotty/tools/dotc/core | |
parent | 9a624b9249024eec4e165b47e22fe3f029a9ae81 (diff) | |
download | dotty-65639176ce59fd64cbecd90bf5680e64e471938f.tar.gz dotty-65639176ce59fd64cbecd90bf5680e64e471938f.tar.bz2 dotty-65639176ce59fd64cbecd90bf5680e64e471938f.zip |
Add second field to SeqLiteral
The field keeps track of the element type. This is necessary
because JavaSeqLiteral is nonvariant and the elements might
be empty, so we cannot always compute the type from the
element types.
Diffstat (limited to 'src/dotty/tools/dotc/core')
4 files changed, 16 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 9ea24324b..25558a79a 100644 --- a/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -438,7 +438,14 @@ class ClassfileParser( case None => hasError = true } if (hasError) None - else if (skip) None else Some(JavaSeqLiteral(arr.toList)) + else if (skip) None + else { + val elems = arr.toList + val elemType = + if (elems.isEmpty) defn.ObjectType + else ctx.typeComparer.lub(elems.tpes).widen + Some(JavaSeqLiteral(elems, TypeTree(elemType))) + } case ANNOTATION_TAG => parseAnnotation(index, skip) map (_.tree) } diff --git a/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/src/dotty/tools/dotc/core/tasty/TreePickler.scala index bb6c3cd2e..d7fc62a16 100644 --- a/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -407,9 +407,9 @@ class TreePickler(pickler: TastyPickler) { case Try(block, cases, finalizer) => writeByte(TRY) withLength { pickleTree(block); cases.foreach(pickleTree); pickleTreeUnlessEmpty(finalizer) } - case SeqLiteral(elems) => + case SeqLiteral(elems, elemtpt) => writeByte(REPEATED) - withLength { elems.foreach(pickleTree) } + withLength { pickleTree(elemtpt); elems.foreach(pickleTree) } case TypeTree(original) => pickleTpt(tree) case Bind(name, body) => diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 16caac02e..9d692cc93 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -801,7 +801,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { val fn = readTerm() val isJava = fn.tpe.isInstanceOf[JavaMethodType] def readArg() = readTerm() match { - case SeqLiteral(elems) if isJava => JavaSeqLiteral(elems) + case SeqLiteral(elems, elemtpt) if isJava => JavaSeqLiteral(elems, elemtpt) case arg => arg } tpd.Apply(fn, until(end)(readArg())) @@ -837,7 +837,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { case TRY => Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree)) case REPEATED => - SeqLiteral(until(end)(readTerm())) + val elemtpt = readTpt() + SeqLiteral(until(end)(readTerm()), elemtpt) case BIND => val name = readName() val info = readType() diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 7a13388ae..2831de3e0 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -850,8 +850,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val end = readNat() + readIndex // array elements are trees representing instances of scala.annotation.Annotation SeqLiteral( - defn.SeqType.appliedTo(defn.AnnotationType :: Nil), - until(end, () => readClassfileAnnotArg(readNat()))) + until(end, () => readClassfileAnnotArg(readNat())), + TypeTree(defn.AnnotationType)) } private def readAnnotInfoArg()(implicit ctx: Context): Tree = { @@ -1063,7 +1063,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas case ARRAYVALUEtree => val elemtpt = readTreeRef() val trees = until(end, readTreeRef) - SeqLiteral(defn.SeqType.appliedTo(elemtpt.tpe :: Nil), trees) + SeqLiteral(trees, elemtpt) // note can't deal with trees passed to Java methods as arrays here case FUNCTIONtree => |