Skip to content

Fix multiversal equality checks for pattern matching #9991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,9 @@ object Trees {

def resolveConstructor(atp: Type, args: List[Tree])(using Context): tpd.Tree = {
val targs = atp.argTypes
applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
withoutMode(Mode.PatternOrTypeBits) {
applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
}
}
}
}
12 changes: 5 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3608,20 +3608,18 @@ class Typer extends Namer
* Overwritten to no-op in ReTyper.
*/
protected def checkEqualityEvidence(tree: tpd.Tree, pt: Type)(using Context) : Unit =
tree match {
tree match
case _: RefTree | _: Literal
if !isVarPattern(tree)
&& !(pt <:< tree.tpe)
&& !withMode(Mode.GadtConstraintInference) {
TypeComparer.constrainPatternType(tree.tpe, pt)
} =>
if !isVarPattern(tree) && !(pt <:< tree.tpe) =>
withMode(Mode.GadtConstraintInference) {
TypeComparer.constrainPatternType(tree.tpe, pt)
}
val cmp =
untpd.Apply(
untpd.Select(untpd.TypedSplice(tree), nme.EQ),
untpd.TypedSplice(dummyTreeOfType(pt)))
typedExpr(cmp, defn.BooleanType)
case _ =>
}

private def checkStatementPurity(tree: tpd.Tree)(original: untpd.Tree, exprOwner: Symbol)(using Context): Unit =
if !tree.tpe.isErroneous
Expand Down
25 changes: 25 additions & 0 deletions tests/neg/eql.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
object lst:
opaque type Lst[+T] = Any
object Lst:
given lstEql[T, U] as Eql[Lst[T], Lst[U]] = Eql.derived
val Empty: Lst[Nothing] = ???
end lst

import lst.Lst

val xs: Lst[Int] = ???
val ys: List[Int] = ???

def test =
xs == ys // error: cannot be compared
ys == xs // error
xs == Nil // error
Nil == xs // error
ys == Lst.Empty // error
Lst.Empty == ys // error
xs match
case Nil => ??? // error, used to pass
ys match
case Lst.Empty => ??? // error, used to pass