Skip to content

Commit 30ec34f

Browse files
committed
Fix Binds being read from tasty as if they were type trees.
binds are "shared" as type trees would be shared, see #2510 But they are not type trees, as you can't have them inside TypeApply. See i2944a.scala.
1 parent 821ca4c commit 30ec34f

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ object TastyFormat {
436436
| ANDtpt
437437
| ORtpt
438438
| BYNAMEtpt
439-
| BIND => true
439+
| BIND => true // Dmitry: binds are "shared" as type trees would be shared, see https://github.com/lampepfl/dotty/pull/2510
440+
// But they are not type trees, as you can't have them inside TypeApply. See i2944a.scala
440441
case _ => false
441442
}
442443

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,15 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
10311031
}
10321032

10331033
def readTpt()(implicit ctx: Context) =
1034-
if (isTypeTreeTag(nextUnsharedTag)) readTerm()
1034+
if (isTypeTreeTag(nextUnsharedTag)) {
1035+
val isShared = nextByte == SHARED
1036+
val term = readTerm()
1037+
term match {
1038+
case a: DefTree if isShared =>
1039+
ref(a.namedType)
1040+
case _ => term
1041+
}
1042+
}
10351043
else {
10361044
val start = currentAddr
10371045
val tp = readType()

tests/pos/i2944.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ trait Map2[K] {
33
def foo: K = {
44
this match {
55
case that: Map2[b] => that.get(3.asInstanceOf[b])
6-
//case that: Map2[c] => that.get(4.asInstanceOf[K])
76
case _ => get(5.asInstanceOf[K])
87
}
98
}

tests/pos/i2944a.scala

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

0 commit comments

Comments
 (0)