Skip to content

Commit fd76449

Browse files
committed
Fix #4006: Avoid ambiguity between SHAREDterm cases and finally
1 parent 18743bf commit fd76449

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Standard-Section: "ASTs" TopLevelStat*
9090
IF Length cond_Term then_Term else_Term
9191
MATCH Length sel_Term CaseDef*
9292
TRY Length expr_Term CaseDef* finalizer_Term?
93+
FINALLY Term
9394
RETURN Length meth_ASTRef expr_Term?
9495
REPEATED Length elem_Type elem_Term*
9596
SELECTouter Length levels_Nat qual_Term underlying_Type
@@ -226,7 +227,7 @@ Standard Section: "Positions" Assoc*
226227
object TastyFormat {
227228

228229
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
229-
val MajorVersion = 4
230+
val MajorVersion = 5
230231
val MinorVersion = 0
231232

232233
/** Tags used to serialize names */
@@ -400,6 +401,7 @@ object TastyFormat {
400401
final val ANNOTATION = 173
401402
final val TERMREFin = 174
402403
final val TYPEREFin = 175
404+
final val FINALLY = 176
403405
final val HOLE = 255
404406

405407
final val firstSimpleTreeTag = UNITconst

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,11 @@ class TreePickler(pickler: TastyPickler) {
423423
withLength { pickleSymRef(from.symbol); pickleTreeUnlessEmpty(expr) }
424424
case Try(block, cases, finalizer) =>
425425
writeByte(TRY)
426-
withLength { pickleTree(block); cases.foreach(pickleTree); pickleTreeUnlessEmpty(finalizer) }
426+
withLength {
427+
pickleTree(block)
428+
cases.foreach(pickleTree)
429+
if (!finalizer.isEmpty) writeByte(FINALLY); pickleTreeUnlessEmpty(finalizer)
430+
}
427431
case SeqLiteral(elems, elemtpt) =>
428432
writeByte(REPEATED)
429433
withLength { pickleTree(elemtpt); elems.foreach(pickleTree) }

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,10 @@ class TreeUnpickler(reader: TastyReader,
10211021
val expr = ifBefore(end)(readTerm(), EmptyTree)
10221022
Return(expr, Ident(from.termRef))
10231023
case TRY =>
1024-
Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree))
1024+
val block = readTerm()
1025+
val cases = readCases(end)
1026+
val finalizer = ifBefore(end)({ assert(readByte() == FINALLY); readTerm() }, EmptyTree)
1027+
Try(block, cases, finalizer)
10251028
case SELECTouter =>
10261029
val levels = readNat()
10271030
readTerm().outerSelect(levels, SkolemType(readType()))

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class CompilationTests extends ParallelTesting {
5858
compileFile("tests/pos-special/i3323.scala", defaultOptions.and("-Xfatal-warnings")) +
5959
compileFile("tests/pos-special/i3323b.scala", defaultOptions.and("-Xfatal-warnings")) +
6060
compileFile("tests/pos-special/i3589-b.scala", defaultOptions.and("-Xfatal-warnings")) +
61+
compileFile("tests/pos-special/i4006.scala", defaultOptions.and("-Ytest-pickler")) +
6162
compileFile("tests/pos-special/completeFromSource/Test.scala", defaultOptions.and("-sourcepath", "tests/pos-special")) +
6263
compileFile("tests/pos-special/completeFromSource/Test2.scala", defaultOptions.and("-sourcepath", "tests/pos-special")) +
6364
compileFile("tests/pos-special/completeFromSource/Test3.scala", defaultOptions.and("-sourcepath", "tests/pos-special", "-scansource")) +

tests/pos-special/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+
}

0 commit comments

Comments
 (0)