Skip to content

Commit 02725c6

Browse files
Merge pull request #4017 from dotty-staging/fix-#4006
Fix #4006: Avoid ambiguity between SHAREDterm cases and finally
2 parents 8d07271 + ad28c3f commit 02725c6

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ class TreeUnpickler(reader: TastyReader,
11041104
}
11051105

11061106
def readCases(end: Addr)(implicit ctx: Context): List[CaseDef] =
1107-
collectWhile((nextByte == CASEDEF || nextByte == SHAREDterm) && currentAddr != end) {
1107+
collectWhile((nextUnsharedTag == CASEDEF) && currentAddr != end) {
11081108
if (nextByte == SHAREDterm) {
11091109
readByte()
11101110
forkAt(readAddr()).readCase()(ctx.fresh.setNewScope)
@@ -1114,7 +1114,7 @@ class TreeUnpickler(reader: TastyReader,
11141114

11151115
def readCase()(implicit ctx: Context): CaseDef = {
11161116
val start = currentAddr
1117-
readByte()
1117+
assert(readByte() == CASEDEF)
11181118
val end = readEnd()
11191119
val pat = readTerm()
11201120
val rhs = readTerm()

tests/pickling/i4006.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Foo {
2+
inline def foo: Int = try { 1 } finally println("Hello")
3+
foo
4+
}

tests/pickling/i4006b.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Foo {
2+
inline def foo: Int = try { 1 } catch { case _ => 4 } finally println("Hello")
3+
foo
4+
}

tests/pickling/i4006c.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Foo {
2+
inline def foo: Int = try { 1 } catch { case _ => 4 }
3+
foo
4+
}

0 commit comments

Comments
 (0)