Skip to content

Fix #8319: Survive bad parameters in compareCaptured #8320

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
Feb 17, 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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
if (leftRoot.isStable || (ctx.isAfterTyper || ctx.mode.is(Mode.TypevarsMissContext))
&& leftRoot.member(tparam.name).exists) {
val captured = TypeRef(leftRoot, tparam)
isSubArg(captured, arg2)
try isSubArg(captured, arg2)
catch case ex: TypeError =>
// The captured reference could be illegal and cause a
// TypeError to be thrown in argDenot
false
}
else if (v > 0)
isSubType(paramBounds(tparam).hi, arg2)
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i8319.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example

sealed abstract class Tree[T]
case class Lam[T,U]() extends Tree[Any]
case class App[T,U]() extends Tree[Any]
case class Var() extends Tree[Any]

object Branch:
def unapply(branch: Lam[?,?] | App[?,?]): true = true

private def foo(s: Option[Tree[?]]) = s match // seems to only occur in a nested pattern
case Some(_: Var) => true // must come first
case Some(Branch()) => true // must be unapply and not direct type check
case _ => false