From e88eb5b55d7734c91b827c774b9e9a162ad4d3f0 Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 7 Apr 2022 12:02:47 +0200 Subject: [PATCH 1/2] Don't issue unreachable error messages for inlined code Fixes #8967 --- .../src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 3 ++- tests/pos/i8967.scala | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i8967.scala diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 371982a8b442..c2367e6bfde0 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -354,7 +354,8 @@ object TypeTestsCasts { val isTrusted = tree.hasAttachment(PatternMatcher.TrustedTypeTestKey) if (!isTrusted && !checkable(expr.tpe, argType, tree.span)) report.uncheckedWarning(i"the type test for $argType cannot be checked at runtime", expr.srcPos) - transformTypeTest(expr, tree.args.head.tpe, flagUnrelated = true) + transformTypeTest(expr, tree.args.head.tpe, + flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false } else if (sym.isTypeCast) transformAsInstanceOf(erasure(tree.args.head.tpe)) diff --git a/tests/pos/i8967.scala b/tests/pos/i8967.scala new file mode 100644 index 000000000000..8b612118621c --- /dev/null +++ b/tests/pos/i8967.scala @@ -0,0 +1,6 @@ +inline def aToB[T,A,B](t:T,b:B): T|B = t match { + case _:A => b + case _:T => t +} + +@main def main() = aToB[Int, Double, String](1,"x") From f0012e930ce0ccabce0530c4233c27d555a1b2ac Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 8 Apr 2022 11:02:12 +0200 Subject: [PATCH 2/2] Update test for #6371 --- project/scripts/cmdTests | 6 +++--- tests/neg-macros/i6371/A_1.scala | 5 +++++ tests/{neg => neg-macros}/i6371/B_2.scala | 0 tests/neg/i6371/A_1.scala | 6 ------ 4 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 tests/neg-macros/i6371/A_1.scala rename tests/{neg => neg-macros}/i6371/B_2.scala (100%) delete mode 100644 tests/neg/i6371/A_1.scala diff --git a/project/scripts/cmdTests b/project/scripts/cmdTests index 6a175db23e99..3405c06b056f 100755 --- a/project/scripts/cmdTests +++ b/project/scripts/cmdTests @@ -51,12 +51,12 @@ fi echo "testing that missing source file does not crash message rendering" clear_out "$OUT" clear_out "$OUT1" -cp tests/neg/i6371/A_1.scala $OUT/A.scala -cp tests/neg/i6371/B_2.scala $OUT/B.scala +cp tests/neg-macros/i6371/A_1.scala $OUT/A.scala +cp tests/neg-macros/i6371/B_2.scala $OUT/B.scala "$SBT" "scalac $OUT/A.scala -d $OUT1" rm $OUT/A.scala "$SBT" "scalac -classpath $OUT1 -d $OUT1 $OUT/B.scala" > "$tmp" 2>&1 || echo "ok" -cat "$tmp" # for debugging +# cat "$tmp" # for debugging grep -qe "B.scala:2:7" "$tmp" grep -qe "This location contains code that was inlined from A.scala:3" "$tmp" diff --git a/tests/neg-macros/i6371/A_1.scala b/tests/neg-macros/i6371/A_1.scala new file mode 100644 index 000000000000..bf94545c595e --- /dev/null +++ b/tests/neg-macros/i6371/A_1.scala @@ -0,0 +1,5 @@ +import scala.quoted.* +object A { + inline def foo(a: Any): Unit = ${ crashOnInline } + def crashOnInline(using Quotes): Expr[Unit] = ??? +} diff --git a/tests/neg/i6371/B_2.scala b/tests/neg-macros/i6371/B_2.scala similarity index 100% rename from tests/neg/i6371/B_2.scala rename to tests/neg-macros/i6371/B_2.scala diff --git a/tests/neg/i6371/A_1.scala b/tests/neg/i6371/A_1.scala deleted file mode 100644 index 186ee85f6ed4..000000000000 --- a/tests/neg/i6371/A_1.scala +++ /dev/null @@ -1,6 +0,0 @@ -object A { - inline def foo(a: Any): Unit = a match { - case _: Int => - case _ => - } -}