File tree 2 files changed +34
-1
lines changed
compiler/src/main/scala/org/scalajs/nscplugin
test-suite/shared/src/test/scala/org/scalajs/testsuite/compiler 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -3903,7 +3903,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
3903
3903
assert(guard == EmptyTree , s " found a case guard at ${caze.pos}" )
3904
3904
3905
3905
def genBody (body : Tree ): js.Tree = body match {
3906
- case app @ Apply (_, Nil ) if app.symbol == defaultLabelSym =>
3906
+ case MaybeAsInstanceOf ( app @ Apply (_, Nil ) ) if app.symbol == defaultLabelSym =>
3907
3907
genJumpToElseClause
3908
3908
case Block (List (app @ Apply (_, Nil )), _) if app.symbol == defaultLabelSym =>
3909
3909
genJumpToElseClause
Original file line number Diff line number Diff line change @@ -427,6 +427,20 @@ class RegressionTest {
427
427
assertEquals(- 1 , bug.result)
428
428
}
429
429
430
+ @ Test def switchMatchWithGuardAndResultTypeOfBoxedUnitWithTailrec_Issue5112 (): Unit = {
431
+ val bug = new Bug5112
432
+ bug.bug('d' , true )
433
+ assertEquals(44 , bug.result)
434
+ bug.bug('a' , true )
435
+ assertEquals(11 , bug.result)
436
+ bug.bug('E' , true )
437
+ assertEquals(22 , bug.result)
438
+ bug.bug('e' , false )
439
+ assertEquals(44 , bug.result)
440
+ bug.bug('G' , false )
441
+ assertEquals(33 , bug.result)
442
+ }
443
+
430
444
@ Test def switchMatchWithGuardInStatementPosButWithNonUnitBranches_Issue4105 (): Unit = {
431
445
def encodeString (string : String , isKey : Boolean ): String = {
432
446
val buffer = new java.lang.StringBuilder ()
@@ -1002,6 +1016,25 @@ object RegressionTest {
1002
1016
}
1003
1017
}
1004
1018
1019
+ class Bug5112 {
1020
+ var result : Int = 0
1021
+
1022
+ // The tail-recursive transformation is required to trigger the bug
1023
+ @ tailrec
1024
+ final def bug (ch : Char , guard : Boolean ): Unit = {
1025
+ if (ch >= 'A' && ch <= 'Z' ) {
1026
+ bug((ch + 'a' - 'A' ).toChar, guard)
1027
+ } else {
1028
+ (ch : @ switch) match {
1029
+ case 'a' => result = 11
1030
+ case 'c' | 'e' if guard => result = 22
1031
+ case 'g' => result = 33
1032
+ case _ => result = 44
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+
1005
1038
object Bug3013 {
1006
1039
trait A1 {
1007
1040
private val s = " A1"
You can’t perform that action at this time.
0 commit comments