question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible bug in match type reduction

See original GitHub issue

Compiler 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:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
OlivierBlanvillaincommented, Apr 1, 2021

It triggers, it’s just not printed as such in the repl:

object Test {
  type T = FilterZ[String %: Zero %: SNil]
  implicitly[T =:= String %: SNil] // compiles
}
0reactions
erikerlandsoncommented, Apr 1, 2021

I suppose, unless you ever want to use FilterZ with non final elements, in which case I would also make Zero final or the compiler might not be able able to conclude that your elements are disjoint from Zero

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found