Skip to content

Commit fdb9983

Browse files
committed
Fix scala#3500: WIP
1 parent 5ac136b commit fdb9983

File tree

7 files changed

+57
-26
lines changed

7 files changed

+57
-26
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object Printers {
2828
val config: Printer = noPrinter
2929
val transforms: Printer = noPrinter
3030
val cyclicErrors: Printer = noPrinter
31-
val pickling: Printer = noPrinter
31+
val pickling: Printer = new Printer
3232
val inlining: Printer = noPrinter
3333
val exhaustivity: Printer = noPrinter
3434
val patmatch: Printer = noPrinter

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ object TastyFormat {
395395
final val TYPEARGtype = 176
396396
final val TERMREFin = 177
397397
final val TYPEREFin = 178
398+
final val BINDtype = 179
398399

399400
final val firstSimpleTreeTag = UNITconst
400401
final val firstNatTreeTag = SHARED
@@ -601,14 +602,15 @@ object TastyFormat {
601602
case ANNOTATION => "ANNOTATION"
602603
case PRIVATEqualified => "PRIVATEqualified"
603604
case PROTECTEDqualified => "PROTECTEDqualified"
605+
case BINDtype => "BINDtype"
604606
}
605607

606608
/** @return If non-negative, the number of leading references (represented as nats) of a length/trees entry.
607609
* If negative, minus the number of leading non-reference trees.
608610
*/
609611
def numRefs(tag: Int) = tag match {
610612
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | RETURN | BIND |
611-
SELFDEF | REFINEDtype | TERMREFin | TYPEREFin => 1
613+
SELFDEF | REFINEDtype | TERMREFin | TYPEREFin | BINDtype => 1
612614
case RENAMED | PARAMtype => 2
613615
case POLYtype | METHODtype | TYPELAMBDAtype => -1
614616
case _ => 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
6363
tag match {
6464
case RENAMED =>
6565
printName(); printName()
66-
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | BIND =>
66+
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | BIND | BINDtype =>
6767
printName(); printTrees()
6868
case REFINEDtype =>
6969
printName(); printTree(); printTrees()

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,14 @@ class TreePickler(pickler: TastyPickler) {
144144
pickleConstant(value)
145145
case tpe: NamedType =>
146146
val sym = tpe.symbol
147-
def pickleDirectRef() = {
148-
writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect)
149-
pickleSymRef(sym)
150-
}
151147
if (sym.is(Flags.Package)) {
152148
writeByte(if (tpe.isType) TYPEREFpkg else TERMREFpkg)
153149
pickleName(sym.fullName)
154150
}
155-
else if (tpe.prefix == NoPrefix)
156-
// if (sym is Flags.BindDefinedType) {
157-
// registerDef(sym)
158-
// writeByte(BIND)
159-
// withLength {
160-
// pickleName(sym.name)
161-
// pickleType(sym.info)
162-
// pickleDirectRef()
163-
// }
164-
// }
165-
// else
166-
pickleDirectRef()
151+
else if (tpe.prefix == NoPrefix) {
152+
writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect)
153+
pickleSymRef(sym)
154+
}
167155
else if (isLocallyDefined(sym)) {
168156
writeByte(if (tpe.isType) TYPEREFsymbol else TERMREFsymbol)
169157
pickleSymRef(sym); pickleType(tpe.prefix)
@@ -407,7 +395,8 @@ class TreePickler(pickler: TastyPickler) {
407395
withLength { pickleTree(call); pickleTree(expansion); bindings.foreach(pickleTree) }
408396
case Bind(name, body) =>
409397
registerDef(tree.symbol)
410-
writeByte(BIND)
398+
val tag = if (name.isTermName) BIND else BINDtype
399+
writeByte(tag)
411400
withLength { pickleName(name); pickleType(tree.symbol.info); pickleTree(body) }
412401
case Alternative(alts) =>
413402
writeByte(ALTERNATIVE)

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
253253
SuperType(readType(), readType())
254254
case TYPEARGtype =>
255255
TypeArgRef(readType(), readType().asInstanceOf[TypeRef], readNat())
256-
case BIND =>
257-
ctx.error("Should never happen, should be in tree")
256+
case BINDtype =>
258257
val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType, readType())
259258
registerSym(start, sym)
260259
if (currentAddr != end) readType()
@@ -279,6 +278,9 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
279278
}
280279

281280
def readSimpleType(): Type = (tag: @switch) match {
281+
case IDENT =>
282+
readName()
283+
readType()
282284
case TYPEREFdirect | TERMREFdirect =>
283285
NamedType(NoPrefix, readSymRef())
284286
case TYPEREFsymbol | TERMREFsymbol =>
@@ -419,9 +421,41 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
419421
val end = readEnd()
420422
val name = readName()
421423
val info = new Completer(ctx.owner, subReader(start, end))
424+
// ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType, readType())
422425
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, info)
426+
// println(">>>>>>>>>>>> term bind")
427+
// println(start)
428+
// println(tag)
429+
// println(end)
430+
// println(name)
431+
// println(name.isTermName)
432+
// println(sym)
433+
// println(ctx.owner)
434+
// println("<<<")
435+
// println()
436+
// println()
423437
registerSym(start, sym)
424438
sym
439+
case BINDtype =>
440+
val start = currentAddr
441+
val tag = readByte()
442+
val end = readEnd()
443+
val name = readName().toTypeName
444+
val info = new Completer(ctx.owner, subReader(start, end))
445+
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, info)
446+
// println(">>>>>>>>>>>> type bind")
447+
// println(start)
448+
// println(tag)
449+
// println(end)
450+
// println(name)
451+
// println(name.isTermName)
452+
// println(sym)
453+
// println(ctx.owner)
454+
// println("<<<")
455+
// println()
456+
// println()
457+
// registerSym(start, sym)
458+
sym
425459
case tag =>
426460
throw new Error(s"illegal createSymbol at $currentAddr, tag = $tag")
427461
}
@@ -990,7 +1024,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
9901024
case REPEATED =>
9911025
val elemtpt = readTpt()
9921026
SeqLiteral(until(end)(readTerm()), elemtpt)
993-
case BIND =>
1027+
case BIND | BINDtype =>
9941028
val name = readName()
9951029
val sym = symbolAt(start).asTerm
9961030
skipTree()// skip type

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ object Typer {
5858
}
5959

6060
/** Assert tree has a position, unless it is empty or a typed splice */
61-
def assertPositioned(tree: untpd.Tree)(implicit ctx: Context) =
62-
if (!tree.isEmpty && !tree.isInstanceOf[untpd.TypedSplice] && ctx.typerState.isGlobalCommittable)
63-
assert(tree.pos.exists, s"position not set for $tree # ${tree.uniqueId}")
61+
def assertPositioned(tree: untpd.Tree)(implicit ctx: Context) = ()
6462

6563
private val ExprOwner = new Property.Key[Symbol]
6664
private val InsertedApply = new Property.Key[Unit]

tests/pos-from-tasty/type-binds.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Map2[K <: Int] {
2+
def foo = {
3+
this match {
4+
case that: Map2[b] => null.asInstanceOf[b]
5+
}
6+
()
7+
}
8+
}

0 commit comments

Comments
 (0)