Possible bug in match type reduction
See original GitHub issueCompiler version
[eje@localhost poc-coulomb-scala3]$ ./mill show coulomb.scalaVersion
[1/1] show
"3.0.0-RC2"
Minimized code
the following code also resides here: https://github.com/erikerlandson/poc-coulomb-scala3/blob/match-type-bug/coulomb/src/coulomb/infra/sigops.scala
package repro
trait SNil
trait %:[H, T]
trait Zero
trait Fail
type FilterZ[S] = S match
case SNil => SNil
case Zero %: t => FilterZ[t]
case h %: t => h %: FilterZ[t]
case Any => Fail
Output
Does not traverse the type and remove Zero
as expected:
scala> import repro.*
scala> type T = FilterZ[String %: Zero %: SNil]
// defined alias type T = repro.FilterZ[String %: repro.Zero %: repro.SNil]
Expectation
My reading of the match-type doc led me to hope that it could filter out elements that match the corresponding match-type case:
// ideally, some variation on this, where `Zero` gets filtered out
scala> import repro.*
scala> type T = FilterZ[String %: Zero %: SNil]
// defined alias type T = String %: repro.SNil
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Scala 3 match type reduction - Stack Overflow
Scala 3 match type reduction · 3 · Yeah this feels like a bug in the compiler, it seems extension methods and match...
Read more >Match Types - Scala 3 - EPFL
The scrutinee, bound, and pattern types must all be first-order types. Match Type Reduction. Match type reduction follows the semantics of match expressions, ......
Read more >What are issue types? | Atlassian Support
Issue types distinguish different types of work in unique ways, and help you identify, categorize, and report on your team's work across your...
Read more >Pattern matching and type safety in TypeScript - LogRocket Blog
Often in our programs, we have to handle different cases, and the majority of bugs are caused by handling a particular case incorrectly...
Read more >Solved: Bug with MATCH and COUNT when matching multiple va ...
Bug with MATCH and COUNT when matching multiple variables? ... It's of course possible, that 311472 is just the correct result for the...
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 Free
Top 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
It triggers, it’s just not printed as such in the repl:
I don’t have total control over what kind of types will appear in these expressions, so I think match types will not be a safe solution for my needs here. I can make use of my existing context/implicit based logic instead.
Thanks for explaining the issues with using traits!