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/typer/Typer.scala | |
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/typer/Typer.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index fdb92a40b..2683b2364 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -836,7 +836,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context): SeqLiteral = track("typedSeqLiteral") { val proto1 = pt.elemType orElse WildcardType val elems1 = tree.elems mapconserve (typed(_, proto1)) - assignType(cpy.SeqLiteral(tree)(elems1), elems1) + val proto2 = // the computed type of the `elemtpt` field + if (!tree.elemtpt.isEmpty) WildcardType + else if (isFullyDefined(proto1, ForceDegree.none)) proto1 + else if (tree.elems.isEmpty && tree.isInstanceOf[Trees.JavaSeqLiteral[_]]) + defn.ObjectType // generic empty Java varargs are of type Object[] + else ctx.typeComparer.lub(elems1.tpes) + val elemtpt1 = typed(tree.elemtpt, proto2) + assignType(cpy.SeqLiteral(tree)(elems1, elemtpt1), elems1, elemtpt1) } def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree = track("typedTypeTree") { |