Skip to content

Commit c45a3bc

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

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
@@ -434,7 +434,8 @@ object TastyFormat {
434434
| ANDtpt
435435
| ORtpt
436436
| BYNAMEtpt
437-
| BIND => true
437+
| BIND => true // Dmitry: binds are "shared" as type trees would be shared, see https://github.com/lampepfl/dotty/pull/2510
438+
// But they are not type trees, as you can't have them inside TypeApply. See i2944a.scala
438439
case _ => false
439440
}
440441

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

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

10311031
def readTpt()(implicit ctx: Context) =
1032-
if (isTypeTreeTag(nextUnsharedTag)) readTerm()
1032+
if (isTypeTreeTag(nextUnsharedTag)) {
1033+
val isShared = nextByte == SHARED
1034+
val term = readTerm()
1035+
term match {
1036+
case a: DefTree if isShared =>
1037+
ref(a.namedType)
1038+
case _ => term
1039+
}
1040+
}
10331041
else {
10341042
val start = currentAddr
10351043
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)