Skip to content

Commit 2268942

Browse files
committed
Fix #4006: Avoid ambiguity between SHAREDterm cases and finally
Add TRYfinally tag
1 parent 18743bf commit 2268942

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ Standard-Section: "ASTs" TopLevelStat*
8989
LAMBDA Length meth_Term target_Type
9090
IF Length cond_Term then_Term else_Term
9191
MATCH Length sel_Term CaseDef*
92-
TRY Length expr_Term CaseDef* finalizer_Term?
92+
TRY Length expr_Term CaseDef*
93+
TRYfinally Length expr_Term finalizer_Term CaseDef*
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 TRYfinally = 176
403405
final val HOLE = 255
404406

405407
final val firstSimpleTreeTag = UNITconst
@@ -594,6 +596,7 @@ object TastyFormat {
594596
case ANNOTATION => "ANNOTATION"
595597
case PRIVATEqualified => "PRIVATEqualified"
596598
case PROTECTEDqualified => "PROTECTEDqualified"
599+
case TRYfinally => "TRYfinally"
597600
case HOLE => "HOLE"
598601
}
599602

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ class TreePickler(pickler: TastyPickler) {
422422
writeByte(RETURN)
423423
withLength { pickleSymRef(from.symbol); pickleTreeUnlessEmpty(expr) }
424424
case Try(block, cases, finalizer) =>
425-
writeByte(TRY)
426-
withLength { pickleTree(block); cases.foreach(pickleTree); pickleTreeUnlessEmpty(finalizer) }
425+
writeByte(if (finalizer.isEmpty) TRY else TRYfinally)
426+
withLength { pickleTree(block); pickleTreeUnlessEmpty(finalizer); cases.foreach(pickleTree) }
427427
case SeqLiteral(elems, elemtpt) =>
428428
writeByte(REPEATED)
429429
withLength { pickleTree(elemtpt); elems.foreach(pickleTree) }

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,12 @@ 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+
Try(readTerm(), readCases(end), EmptyTree)
1025+
case TRYfinally =>
1026+
val block = readTerm()
1027+
val finalizer = readTerm()
1028+
val cases = readCases(end)
1029+
Try(block, cases, finalizer)
10251030
case SELECTouter =>
10261031
val levels = readNat()
10271032
readTerm().outerSelect(levels, SkolemType(readType()))

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+
}

0 commit comments

Comments
 (0)