Skip to content

Commit 424c719

Browse files
committed
Fix rechecking of SeqLiterals
1 parent 78d40de commit 424c719

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

compiler/src/dotty/tools/dotc/transform/Recheck.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ package transform
55
import core.*
66
import Symbols.*, Contexts.*, Types.*, ContextOps.*, Decorators.*, SymDenotations.*
77
import Flags.*, SymUtils.*, NameKinds.*
8+
import ast.*
89
import Phases.Phase
910
import DenotTransformers.IdentityDenotTransformer
1011
import NamerOps.{methodType, linkConstructorParams}
1112
import NullOpsDecorator.stripNull
1213
import typer.ErrorReporting.err
13-
import ast.*
1414
import typer.ProtoTypes.*
15+
import typer.TypeAssigner.seqLitType
1516
import config.Printers.recheckr
1617
import util.Property
1718
import StdNames.nme
@@ -218,7 +219,7 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
218219
case elemtp => elemtp
219220
val declaredElemType = recheck(tree.elemtpt)
220221
val elemTypes = tree.elems.map(recheck(_, elemProto))
221-
TypeComparer.lub(declaredElemType :: elemTypes)
222+
seqLitType(tree, TypeComparer.lub(declaredElemType :: elemTypes))
222223

223224
def recheckTypeTree(tree: TypeTree)(using Context): Type = tree match
224225
case tree: InferredTypeTree => reinfer(tree.tpe)

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import reporting._
1717
import Checking.{checkNoPrivateLeaks, checkNoWildcard}
1818

1919
trait TypeAssigner {
20-
import tpd._
20+
import tpd.*
21+
import TypeAssigner.*
2122

2223
/** The qualifying class of a this or super with prefix `qual` (which might be empty).
2324
* @param packageOk The qualifier may refer to a package.
@@ -435,13 +436,8 @@ trait TypeAssigner {
435436
if (cases.isEmpty) tree.withType(expr.tpe)
436437
else tree.withType(TypeComparer.lub(expr.tpe :: cases.tpes))
437438

438-
def assignType(tree: untpd.SeqLiteral, elems: List[Tree], elemtpt: Tree)(using Context): SeqLiteral = {
439-
val ownType = tree match {
440-
case tree: untpd.JavaSeqLiteral => defn.ArrayOf(elemtpt.tpe)
441-
case _ => if (ctx.erasedTypes) defn.SeqType else defn.SeqType.appliedTo(elemtpt.tpe)
442-
}
443-
tree.withType(ownType)
444-
}
439+
def assignType(tree: untpd.SeqLiteral, elems: List[Tree], elemtpt: Tree)(using Context): SeqLiteral =
440+
tree.withType(seqLitType(tree, elemtpt.tpe))
445441

446442
def assignType(tree: untpd.SingletonTypeTree, ref: Tree)(using Context): SingletonTypeTree =
447443
tree.withType(ref.tpe)
@@ -527,5 +523,9 @@ trait TypeAssigner {
527523
tree.withType(pid.symbol.termRef)
528524
}
529525

526+
object TypeAssigner extends TypeAssigner:
527+
def seqLitType(tree: untpd.SeqLiteral, elemType: Type)(using Context) = tree match
528+
case tree: untpd.JavaSeqLiteral => defn.ArrayOf(elemType)
529+
case _ => if ctx.erasedTypes then defn.SeqType else defn.SeqType.appliedTo(elemType)
530+
530531

531-
object TypeAssigner extends TypeAssigner

0 commit comments

Comments
 (0)