GADT patmat doesn't narrow class type parameters
See original GitHub issuescala> enum Expr[T] {
case IExpr(value: Int) extends Expr[Int]
case BExpr(value: Boolean) extends Expr[Boolean]
def join(other: Expr[T]): Expr[T] = (this, other) match {
case (IExpr(i1), IExpr(i2)) => IExpr(i1 + i2)
case (BExpr(b1), BExpr(b2)) => BExpr(b1 & b2)
}
}
6 | case (IExpr(i1), IExpr(i2)) => IExpr(i1 + i2)
| ^^^^^^^^^^^^^^
| found: Expr[Int]
| required: Expr[T]
|
7 | case (BExpr(b1), BExpr(b2)) => BExpr(b1 & b2)
| ^^^^^^^^^^^^^^
| found: Expr[Boolean]
| required: Expr[T]
|
This is similar to an old issue where class/trait parameters aren’t narrowed.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Understanding the limits of Scala GADT support - Stack Overflow
Addendum: in a comment the questioner says "The question is simple on why it doesn't works with type parameter at class level but...
Read more >dotty.tools.dotc.core - javadoc.io
A lazy type that completes itself by calling parameter doComplete. Any linked modules/classes or module classes are also initialized. A lazy type that...
Read more >CSC324 Assignment 2
Haskell will let us formally encode Option types in the type system; in this question we will do so "informally" in Racket. Question...
Read more >A SCORE TEST FOR LINKAGE USING IDENTITY BY ...
This paper concerns a class of score tests which arise ... for sibships of a given size does not depend on the nuisance...
Read more >Scala example - Typers.scala - list, tree, type - Alvin Alexander
r private final val InterpolatorIdentRegex = """\$[$\w]+""".r // note that \w doesn't include $ abstract class Typer(context0: Context) extends ...
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
Why would the compiler’s error messages not follow the Scala fact that a value and a type sharing the same name are not ambiguous? (They live in different namespaces.) At the very least it should not have to introduce a difference between the name of a class and its companion object.
I propose:
Well, this was actually implemented in #11222, we just forgot about this particular issue. Closing now.