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.

GADT patmat doesn't narrow class type parameters

See original GitHub issue
scala> 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:closed
  • Created 5 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
LPTKcommented, Apr 20, 2018

So how do you propose to distinguish between the object Expr and the trait Expr in error messages?

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:

   |                                    where: value Expr is an object
   |                                            type Expr is a trait
0reactions
abgruszeckicommented, Mar 24, 2021

Well, this was actually implemented in #11222, we just forgot about this particular issue. Closing now.

Read more comments on GitHub >

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

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