Skip to content

Commit 8b9b455

Browse files
committed
Avoid creating BindDefinedType symbols
1 parent 57b61d2 commit 8b9b455

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,16 @@ class TreePickler(pickler: TastyPickler) {
443443
bindings.foreach(preRegister)
444444
withLength { pickleTree(call); pickleTree(expansion); bindings.foreach(pickleTree) }
445445
case Bind(name, body) =>
446-
registerDef(tree.symbol)
446+
val sym = tree.symbol
447+
// If name is a type wildcard, symbol was removed by Typer#indexPattern.
448+
// Use the type(-bounds) of the body instead as type of the Bind
449+
if (sym.exists) registerDef(sym) else assert(name == tpnme.WILDCARD)
447450
writeByte(BIND)
448-
withLength { pickleName(name); pickleType(tree.symbol.info); pickleTree(body) }
451+
withLength {
452+
pickleName(name)
453+
pickleType(if (sym.exists) sym.info else body.tpe)
454+
pickleTree(body)
455+
}
449456
case Alternative(alts) =>
450457
writeByte(ALTERNATIVE)
451458
withLength { alts.foreach(pickleTree) }

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,9 @@ class TreeUnpickler(reader: TastyReader,
10321032
val sym = symAtAddr.getOrElse(start, forkAt(start).createSymbol())
10331033
readName()
10341034
readType()
1035-
Bind(sym, readTerm())
1035+
val body = readTerm()
1036+
if (sym.name == tpnme.WILDCARD) untpd.Bind(sym.name, body).withType(body.tpe)
1037+
else Bind(sym, body)
10361038
case ALTERNATIVE =>
10371039
Alternative(until(end)(readTerm()))
10381040
case UNAPPLY =>
@@ -1187,7 +1189,7 @@ class TreeUnpickler(reader: TastyReader,
11871189
class OwnerTree(val addr: Addr, tag: Int, reader: TreeReader, val end: Addr) {
11881190

11891191
private var myChildren: List[OwnerTree] = null
1190-
1192+
11911193
/** All definitions that have the definition at `addr` as closest enclosing definition */
11921194
def children: List[OwnerTree] = {
11931195
if (myChildren == null) myChildren = {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ class Typer extends Namer
12521252
assignType(cpy.ByNameTypeTree(tree)(result1), result1)
12531253
}
12541254

1255-
def typedTypeBoundsTree(tree: untpd.TypeBoundsTree)(implicit ctx: Context): TypeBoundsTree = track("typedTypeBoundsTree") {
1255+
def typedTypeBoundsTree(tree: untpd.TypeBoundsTree)(implicit ctx: Context): Tree = track("typedTypeBoundsTree") {
12561256
val TypeBoundsTree(lo, hi) = tree
12571257
val lo1 = typed(lo)
12581258
val hi1 = typed(hi)
@@ -1267,8 +1267,7 @@ class Typer extends Namer
12671267
// with an expected type in typedTyped. The type symbol is eliminated once
12681268
// the enclosing pattern has been typechecked; see `indexPattern` in `typedCase`.
12691269
val wildcardSym = ctx.newPatternBoundSymbol(tpnme.WILDCARD, tree1.tpe, tree.pos)
1270-
wildcardSym.setFlag(BindDefinedType) // can we get rid of this?
1271-
tree1.withType(wildcardSym.typeRef)
1270+
untpd.Bind(name, tree1).withType(wildcardSym.typeRef)
12721271
}
12731272
else tree1
12741273
}

0 commit comments

Comments
 (0)