File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
compiler/src/dotty/tools/dotc/typer
tests/neg-custom-args/fatal-warnings Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -771,13 +771,17 @@ class Typer extends Namer
771
771
def typedTpt = checkSimpleKinded(typedType(tree.tpt))
772
772
def handlePattern : Tree = {
773
773
val tpt1 = typedTpt
774
- if (! ctx.isAfterTyper && pt != defn.ImplicitScrutineeTypeRef )
775
- checkMatchable(pt, tree.srcPos, pattern = true )
774
+ if ! ctx.isAfterTyper && pt != defn.ImplicitScrutineeTypeRef then
776
775
withMode(Mode .GadtConstraintInference ) {
777
776
TypeComparer .constrainPatternType(tpt1.tpe, pt)
778
777
}
778
+ val matched = ascription(tpt1, isWildcard = true )
779
779
// special case for an abstract type that comes with a class tag
780
- tryWithTypeTest(ascription(tpt1, isWildcard = true ), pt)
780
+ val result = tryWithTypeTest(ascribed, pt)
781
+ if (result eq matched) && pt != defn.ImplicitScrutineeTypeRef then
782
+ // no check for matchability if TestTest was applied
783
+ checkMatchable(pt, tree.srcPos, pattern = true )
784
+ result
781
785
}
782
786
cases(
783
787
ifPat = handlePattern,
Original file line number Diff line number Diff line change
1
+ import scala .language .`3.1-migration`
2
+ import scala .reflect .TypeTest
3
+
4
+ trait Foo :
5
+ type X
6
+ type Y <: X
7
+ def x : X
8
+ given TypeTest [X , Y ] = ???
9
+
10
+ object Test :
11
+ def test (foo : Foo ): Unit =
12
+ foo.x match
13
+ case x : foo.Y =>
You can’t perform that action at this time.
0 commit comments