From b6987cccbd84ddb53de4b7616be8bbec31d187ac Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 16 Jul 2022 16:38:19 +0100 Subject: [PATCH] Fix constraining against HKTypeLambda arguments --- .../dotty/tools/dotc/core/PatternTypeConstrainer.scala | 5 +++-- tests/pos/i15677.scala | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i15677.scala diff --git a/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala b/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala index 5cd8d4f50eeb..c5f126580df5 100644 --- a/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala +++ b/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala @@ -275,9 +275,10 @@ trait PatternTypeConstrainer { self: TypeComparer => argP.typeSymbol.isPatternBound && patternTp.classSymbol == scrutineeTp.classSymbol then val TypeBounds(loS, hiS) = argS.bounds + val TypeBounds(loP, hiP) = argP.bounds var res = true - if variance < 1 then res &&= isSubType(loS, argP) - if variance > -1 then res &&= isSubType(argP, hiS) + if variance < 1 then res &&= isSubType(loS, hiP) + if variance > -1 then res &&= isSubType(loP, hiS) res else true } diff --git a/tests/pos/i15677.scala b/tests/pos/i15677.scala new file mode 100644 index 000000000000..2ad2b5283057 --- /dev/null +++ b/tests/pos/i15677.scala @@ -0,0 +1,10 @@ +class Inv[A] + +class Foo[B, M[_]] + +class Bar[C, N[_]] extends Foo[C, N]: + def inv: Inv[C] = null + +def test(foo: Foo[Int, Option]): Inv[Int] = foo match + case bar: Bar[_, _] => bar.inv + case _ => null