Pattern-matching on Result produces a (spurious?) warning
See original GitHub issueWhen my code tries to match on the result of a parse, such as:
dumpfileP.parse(mySQL) match {
case Result.Success(stmts, _) => stmts
case Result.Failure(parser, index) => displayFailure(...)
}
The Scala compiler consistently kicks out a warning:
[warn] /home/jducoeur/GitHub/Querki/querki/scalajvm/app/querki/imexport/MySQLImport.scala:143: The outer reference in this type test cannot be checked at run time.
[warn] case Result.Success(stmts, _) => stmts
This warning may be correct – I’m honestly unsure – but I don’t care about it, and definitely don’t want to see it. My coding standards are “no warnings”, so this is getting in the way of using FastParse for production code.
This can be worked around by using isInstanceOf + asInstanceOf, but that’s rather boilerplatey. A more idiomatic-Scala solution would be preferable.
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Match Exhaustiveness Testing Ignores Guard Statements #5365
There are cases today when you get a spurious warning: if you know more than the compiler about the possible values that can...
Read more >4. Pattern Matching - Programming Scala, 2nd Edition [Book]
So, it warns that the match isn't exhaustive. Then we see what happens when we try to match on a value for which...
Read more >Warnings for pattern matching - Moscova
We examine the ML pattern-matching anomalies of useless clauses and non-exhaustive matches. We state the definition of these anomalies, building upon pattern ...
Read more >Strange pattern-matching: is it correct? - haskell - Stack Overflow
It always returns True with any values and any types. Is this the correct behavior? The b in b -> True is a...
Read more >Pattern matching using the is and switch expressions.
The compiler generates a warning if a switch expression doesn't handle all possible input values.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In versions 0.2.x I had to use
import fastparse.core.Result
In versions 0.3.x I had to useimport fastparse.core.Parsed
To fix the compiler error: “The outer reference in this type test cannot be checked at run time.”
(This is was using Scala 2.11.7 on the JVM with Java7.)
Had the same problem.
import fastparse.core.Result
fixed it for me.