Skip to content

Commit 4f39123

Browse files
author
Oron Port
committed
fix: Improve enum pattern matching type checking and error handling (prevent crash)
1 parent d9fd452 commit 4f39123

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

plugin/src/main/scala/plugin/CustomControlPhase.scala

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,23 @@ class CustomControlPhase(setting: Setting) extends CommonPhase:
688688
FromCore.patternSingleton(selectorTree, lit)
689689
// hacked unapply for enum enumerations
690690
case Pattern.Enum(arg) =>
691-
val DFEnum(enumTpe) = dfTypeTpe: @unchecked
692-
if (arg.tpe <:< enumTpe) FromCore.patternSingleton(selectorTree, arg)
693-
else
694-
report.error(
695-
s"""Wrong enum entry type.
696-
|Expecting: ${enumTpe.show}
697-
|Found: ${arg.tpe.show}""".stripMargin,
698-
arg.srcPos
699-
)
700-
EmptyTree
691+
dfTypeTpe match
692+
case DFEnum(enumTpe) =>
693+
if (arg.tpe <:< enumTpe) FromCore.patternSingleton(selectorTree, arg)
694+
else
695+
report.error(
696+
s"""Wrong enum entry type.
697+
|Expecting: ${enumTpe.show}
698+
|Found: ${arg.tpe.show}""".stripMargin,
699+
arg.srcPos
700+
)
701+
EmptyTree
702+
case _ =>
703+
report.error(
704+
s"Found an enum pattern but the match selector is not an enum.",
705+
patternTree.srcPos
706+
)
707+
EmptyTree
701708
// constant string interpolation
702709
case Pattern.SI(block, binds, rhs) =>
703710
dfTypeTpe match

0 commit comments

Comments
 (0)