diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index cd33fe9cef24..d1ca562a5aba 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1258,8 +1258,6 @@ trait Applications extends Compatibility { def typedUnApply(tree: untpd.Apply, selType: Type)(using Context): Tree = { record("typedUnApply") val Apply(qual, args) = tree - if !ctx.mode.is(Mode.InTypeTest) then - checkMatchable(selType, tree.srcPos, pattern = true) def notAnExtractor(tree: Tree): Tree = // prefer inner errors @@ -1398,12 +1396,13 @@ trait Applications extends Compatibility { val unapplyArgType = mt.paramInfos.head unapp.println(i"unapp arg tpe = $unapplyArgType, pt = $selType") val ownType = - if (selType <:< unapplyArgType) { + if selType <:< unapplyArgType then unapp.println(i"case 1 $unapplyArgType ${ctx.typerState.constraint}") fullyDefinedType(unapplyArgType, "pattern selector", tree.srcPos) selType.dropAnnot(defn.UncheckedAnnot) // need to drop @unchecked. Just because the selector is @unchecked, the pattern isn't. - } - else { + else + if !ctx.mode.is(Mode.InTypeTest) then + checkMatchable(selType, tree.srcPos, pattern = true) // We ignore whether constraining the pattern succeeded. // Constraining only fails if the pattern cannot possibly match, // but useless pattern checks detect more such cases, so we simply rely on them instead. @@ -1412,7 +1411,7 @@ trait Applications extends Compatibility { if (patternBound.nonEmpty) unapplyFn = addBinders(unapplyFn, patternBound) unapp.println(i"case 2 $unapplyArgType ${ctx.typerState.constraint}") unapplyArgType - } + val dummyArg = dummyTreeOfType(ownType) val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil))) def unapplyImplicits(unapp: Tree): List[Tree] = { diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 817fe6f21d24..bff9310dee88 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -1461,7 +1461,6 @@ trait Checking { def checkMatchable(tp: Type, pos: SrcPos, pattern: Boolean)(using Context): Unit = if !tp.derivesFrom(defn.MatchableClass) && sourceVersion.isAtLeast(`future-migration`) then - val kind = if pattern then "pattern selector" else "value" report.warning(MatchableWarning(tp, pattern), pos) /** Check that there is an implicit capability to throw a checked exception diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 2fdebef3f5db..dee65e404da9 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -48,6 +48,7 @@ class CompilationTests { compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)), compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes), compileFilesInDir("tests/pos-custom-args/no-experimental", defaultOptions.and("-Yno-experimental")), + compileFilesInDir("tests/pos-custom-args/strict", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")), compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")), compileFile( // succeeds despite -Xfatal-warnings because of -nowarn @@ -55,8 +56,6 @@ class CompilationTests { defaultOptions.and("-nowarn", "-Xfatal-warnings") ), compileFile("tests/pos-special/typeclass-scaling.scala", defaultOptions.and("-Xmax-inlines", "40")), - compileFile("tests/pos-special/i7296.scala", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")), - compileDir("tests/pos-special/adhoc-extension", defaultOptions.and("-source", "future", "-feature", "-Xfatal-warnings")), compileFile("tests/pos-special/i7575.scala", defaultOptions.andLanguageFeature("dynamics")), compileFile("tests/pos-special/kind-projector.scala", defaultOptions.and("-Ykind-projector")), compileFile("tests/pos-special/kind-projector-underscores.scala", defaultOptions.and("-Ykind-projector:underscores")), @@ -65,7 +64,6 @@ class CompilationTests { compileFile("tests/pos-custom-args/i9267.scala", defaultOptions.and("-Ystop-after:erasure")), compileFile("tests/pos-special/extend-java-enum.scala", defaultOptions.and("-source", "3.0-migration")), compileFile("tests/pos-custom-args/help.scala", defaultOptions.and("-help", "-V", "-W", "-X", "-Y")), - compileFile("tests/pos-custom-args/i10383.scala", defaultOptions.and("-source", "future", "-deprecation", "-Xfatal-warnings")), compileFile("tests/pos-custom-args/i13044.scala", defaultOptions.and("-Xmax-inlines:33")), compileFile("tests/pos-custom-args/jdk-8-app.scala", defaultOptions.and("-release:8")), ).checkCompile() diff --git a/tests/pos-special/adhoc-extension/A.scala b/tests/pos-custom-args/strict/adhoc-extension/A.scala similarity index 100% rename from tests/pos-special/adhoc-extension/A.scala rename to tests/pos-custom-args/strict/adhoc-extension/A.scala diff --git a/tests/pos-special/adhoc-extension/B.scala b/tests/pos-custom-args/strict/adhoc-extension/B.scala similarity index 100% rename from tests/pos-special/adhoc-extension/B.scala rename to tests/pos-custom-args/strict/adhoc-extension/B.scala diff --git a/tests/pos-custom-args/i10383.scala b/tests/pos-custom-args/strict/i10383.scala similarity index 100% rename from tests/pos-custom-args/i10383.scala rename to tests/pos-custom-args/strict/i10383.scala diff --git a/tests/pos-custom-args/strict/i16808.scala b/tests/pos-custom-args/strict/i16808.scala new file mode 100644 index 000000000000..602ceed94161 --- /dev/null +++ b/tests/pos-custom-args/strict/i16808.scala @@ -0,0 +1,2 @@ +def collectKeys[A, B, C](xs: Map[A, B])(f: PartialFunction[A, C]): Map[C, B] = + xs.collect{ case (f(c) , b) => (c, b) } \ No newline at end of file diff --git a/tests/pos-special/i7296.scala b/tests/pos-custom-args/strict/i7296.scala similarity index 100% rename from tests/pos-special/i7296.scala rename to tests/pos-custom-args/strict/i7296.scala