Skip to content

Commit c6fd150

Browse files
committed
Make Binds forward-referencable
Make bind-defined symbols forward-referencable. This is necessary to support more interesting patterns of Binds. E.g. in case (bla: List[t]) the bound symbol `bla` refers to the bound type `t` in its info. Previously we used BindDefinedType for that, but that cannot work in general, because it does not distinguish between a reference and a binding.
1 parent 9ea9ef4 commit c6fd150

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class TreeUnpickler(reader: TastyReader,
115115
val start = currentAddr
116116
val tag = readByte()
117117
tag match {
118-
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | TEMPLATE =>
118+
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | TEMPLATE | BIND =>
119119
val end = readEnd()
120120
for (i <- 0 until numRefs(tag)) readNat()
121121
if (tag == TEMPLATE) scanTrees(buf, end, MemberDefsOnly)
@@ -431,6 +431,8 @@ class TreeUnpickler(reader: TastyReader,
431431
def createSymbol()(implicit ctx: Context): Symbol = nextByte match {
432432
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM =>
433433
createMemberSymbol()
434+
case BIND =>
435+
createBindSymbol()
434436
case TEMPLATE =>
435437
val localDummy = ctx.newLocalDummy(ctx.owner)
436438
registerSym(currentAddr, localDummy)
@@ -439,6 +441,25 @@ class TreeUnpickler(reader: TastyReader,
439441
throw new Error(s"illegal createSymbol at $currentAddr, tag = $tag")
440442
}
441443

444+
private def createBindSymbol()(implicit ctx: Context): Symbol = {
445+
val start = currentAddr
446+
val tag = readByte()
447+
val end = readEnd()
448+
var name: Name = readName()
449+
nextUnsharedTag match {
450+
case TYPEBOUNDS | TYPEALIAS => name = name.toTypeName
451+
case _ =>
452+
}
453+
val typeReader = fork
454+
val completer = new LazyType {
455+
def complete(denot: SymDenotation)(implicit ctx: Context) =
456+
denot.info = typeReader.readType()
457+
}
458+
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, completer, coord = coordAt(start))
459+
registerSym(start, sym)
460+
sym
461+
}
462+
442463
/** Create symbol of member definition or parameter node and enter in symAtAddr map
443464
* @return the created symbol
444465
*/
@@ -994,11 +1015,9 @@ class TreeUnpickler(reader: TastyReader,
9941015
val elemtpt = readTpt()
9951016
SeqLiteral(until(end)(readTerm()), elemtpt)
9961017
case BIND =>
997-
var name: Name = readName()
998-
val info = readType()
999-
if (info.isInstanceOf[TypeType]) name = name.toTypeName
1000-
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, info, coord = coordAt(start))
1001-
registerSym(start, sym)
1018+
val sym = symAtAddr.getOrElse(start, forkAt(start).createSymbol())
1019+
readName()
1020+
readType()
10021021
Bind(sym, readTerm())
10031022
case ALTERNATIVE =>
10041023
Alternative(until(end)(readTerm()))

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,6 @@ class Typer extends Namer
12881288
if (tree.name == nme.WILDCARD) body1
12891289
else {
12901290
val sym = ctx.newPatternBoundSymbol(tree.name, body1.tpe.underlyingIfRepeated(isJava = false), tree.pos)
1291-
if (sym.isType) sym.setFlag(BindDefinedType) // can we get rid of this?
12921291
if (ctx.mode.is(Mode.InPatternAlternative))
12931292
ctx.error(i"Illegal variable ${sym.name} in pattern alternative", tree.pos)
12941293
assignType(cpy.Bind(tree)(tree.name, body1), sym)

tests/neg-tailcall/t1672b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object Test1772B {
4646
else 1 + (try {
4747
throw new RuntimeException
4848
} catch {
49-
case _: Throwable => bar(i - 1) // error: cannot rewrite recursive call
49+
case _: Throwable => bar(i - 1) // old error: cannot rewrite recursive call
5050
})
5151
}
5252
}

tests/patmat/gadt-nontrivial2.check

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)