File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,11 @@ class ExpandSAMs extends MiniPhase:
180180
181181 def isDefinedAtRhs (paramRefss : List [List [Tree ]])(using Context ) =
182182 val tru = Literal (Constant (true ))
183- def translateCase (cdef : CaseDef ) = cpy.CaseDef (cdef)(body = tru)
183+ def translateCase (cdef : CaseDef ): CaseDef =
184+ val body1 = cdef.body match
185+ case b : SubMatch => cpy.Match (b)(b.selector, b.cases.map(translateCase))
186+ case _ => tru
187+ cpy.CaseDef (cdef)(body = body1)
184188 val paramRef = paramRefss.head.head
185189 val defaultValue = Literal (Constant (false ))
186190 translateMatch(isDefinedAtFn)(paramRef.symbol, pfRHS.cases.map(translateCase), defaultValue)
Original file line number Diff line number Diff line change 1+ import scala .language .experimental .matchWithSubCases
2+
3+ val pf : PartialFunction [Option [Option [Int ]], String ] =
4+ case Some (x2) with x2 match
5+ case Some (x3) with x3 match
6+ case 1 => " a"
7+ case 2 => " b"
8+ case Some (None ) => " c"
9+
10+ @ main def Test =
11+ assert(pf(Some (Some (2 ))) == " b" )
12+ assert(pf(Some (None )) == " c" )
13+ assert(! pf.isDefinedAt(None ))
14+ assert(! pf.isDefinedAt(Some (Some (3 ))))
You can’t perform that action at this time.
0 commit comments