From e37a00218155244d5d57c1dca99f1cce7de73d01 Mon Sep 17 00:00:00 2001 From: David Barri Date: Wed, 10 Mar 2021 13:28:10 +1100 Subject: [PATCH] Improve UnableToEmitSwitch warning message Previously it would read: Could not emit switch for @switch annotated match since there are not enough cases Now it reads: Could not emit switch for @switch annotated match since a minimum of 4 cases (including the default) are required --- compiler/src/dotty/tools/dotc/reporting/messages.scala | 5 ++++- compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 6089a70e05e9..6f3bba2a95a8 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -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 @@ -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 = diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 6dac51c427c1..ce5658f77a43 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -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]