Skip to content

Fix exhaustivity warning #16168

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
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: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ object TypeOps:
}

def instantiate(): Type = {
// if there's a change in variance in type parameters (between subtype tp1 and supertype tp2)
// then we don't want to maximise the type variables in the wrong direction.
// For instance 15967, A[-Z] and B[Y] extends A[Y], we don't want to maximise Y to Any
maximizeType(protoTp1.baseType(tp2.classSymbol), NoSpan)
maximizeType(protoTp1, NoSpan)
wildApprox(protoTp1)
}
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i15967.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// scalac: -Werror
sealed trait A[-Z]
final case class B[Y]() extends A[Y]

class Test:
def t1[X](a: A[X]) = a match // was inexhaustive
case _: B[X] @unchecked =>

//def t2[X](a: A[X]) = a match // was inexhaustive
// case _: B[X] => // expected unchecked warning