From ad28c3fc7b55527cc9baa559d88cd2d63677cbbd Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 19 Feb 2018 18:30:40 +0100 Subject: [PATCH] Fix #4006: Avoid reading shared terms as cases when they are not --- compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 4 ++-- tests/pickling/i4006.scala | 4 ++++ tests/pickling/i4006b.scala | 4 ++++ tests/pickling/i4006c.scala | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/pickling/i4006.scala create mode 100644 tests/pickling/i4006b.scala create mode 100644 tests/pickling/i4006c.scala diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 3e38a9119fbe..7f64f2cfb941 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -1104,7 +1104,7 @@ class TreeUnpickler(reader: TastyReader, } def readCases(end: Addr)(implicit ctx: Context): List[CaseDef] = - collectWhile((nextByte == CASEDEF || nextByte == SHAREDterm) && currentAddr != end) { + collectWhile((nextUnsharedTag == CASEDEF) && currentAddr != end) { if (nextByte == SHAREDterm) { readByte() forkAt(readAddr()).readCase()(ctx.fresh.setNewScope) @@ -1114,7 +1114,7 @@ class TreeUnpickler(reader: TastyReader, def readCase()(implicit ctx: Context): CaseDef = { val start = currentAddr - readByte() + assert(readByte() == CASEDEF) val end = readEnd() val pat = readTerm() val rhs = readTerm() diff --git a/tests/pickling/i4006.scala b/tests/pickling/i4006.scala new file mode 100644 index 000000000000..ef86dbb052f1 --- /dev/null +++ b/tests/pickling/i4006.scala @@ -0,0 +1,4 @@ +class Foo { + inline def foo: Int = try { 1 } finally println("Hello") + foo +} diff --git a/tests/pickling/i4006b.scala b/tests/pickling/i4006b.scala new file mode 100644 index 000000000000..3c17a6522ac4 --- /dev/null +++ b/tests/pickling/i4006b.scala @@ -0,0 +1,4 @@ +class Foo { + inline def foo: Int = try { 1 } catch { case _ => 4 } finally println("Hello") + foo +} diff --git a/tests/pickling/i4006c.scala b/tests/pickling/i4006c.scala new file mode 100644 index 000000000000..9233ccdfc922 --- /dev/null +++ b/tests/pickling/i4006c.scala @@ -0,0 +1,4 @@ +class Foo { + inline def foo: Int = try { 1 } catch { case _ => 4 } + foo +}