Skip to content

Improve UnableToEmitSwitch warning message #11680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import printing.Formatting.hl
import ast.Trees._
import ast.untpd
import ast.tpd
import transform.PatternMatcher.MinSwitchCases
import transform.SymUtils._

/** Messages
Expand Down Expand Up @@ -2006,7 +2007,9 @@ import transform.SymUtils._

class UnableToEmitSwitch(tooFewCases: Boolean)(using Context)
extends SyntaxMsg(UnableToEmitSwitchID) {
def tooFewStr: String = if (tooFewCases) " since there are not enough cases" else ""
def tooFewStr: String =
if (tooFewCases) " since a minimum of " + MinSwitchCases + " cases (including the default) are required"
else ""
def msg = em"Could not emit switch for ${hl("@switch")} annotated match$tooFewStr"
def explain = {
val codeExample =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object PatternMatcher {
final val selfCheck = false // debug option, if on we check that no case gets generated twice

/** Minimal number of cases to emit a switch */
final val MinSwitchCases = 4
inline val MinSwitchCases = 4

val TrustedTypeTestKey: Key[Unit] = new StickyKey[Unit]

Expand Down