Skip to content

Commit 63da64f

Browse files
authored
Merge pull request #14871 from dotty-staging/fix-8967
Don't issue unreachable error messages for inlined code
2 parents e1ce523 + f0012e9 commit 63da64f

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ object TypeTestsCasts {
354354
val isTrusted = tree.hasAttachment(PatternMatcher.TrustedTypeTestKey)
355355
if (!isTrusted && !checkable(expr.tpe, argType, tree.span))
356356
report.uncheckedWarning(i"the type test for $argType cannot be checked at runtime", expr.srcPos)
357-
transformTypeTest(expr, tree.args.head.tpe, flagUnrelated = true)
357+
transformTypeTest(expr, tree.args.head.tpe,
358+
flagUnrelated = enclosingInlineds.isEmpty) // if test comes from inlined code, dont't flag it even if it always false
358359
}
359360
else if (sym.isTypeCast)
360361
transformAsInstanceOf(erasure(tree.args.head.tpe))

project/scripts/cmdTests

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ fi
5151
echo "testing that missing source file does not crash message rendering"
5252
clear_out "$OUT"
5353
clear_out "$OUT1"
54-
cp tests/neg/i6371/A_1.scala $OUT/A.scala
55-
cp tests/neg/i6371/B_2.scala $OUT/B.scala
54+
cp tests/neg-macros/i6371/A_1.scala $OUT/A.scala
55+
cp tests/neg-macros/i6371/B_2.scala $OUT/B.scala
5656
"$SBT" "scalac $OUT/A.scala -d $OUT1"
5757
rm $OUT/A.scala
5858
"$SBT" "scalac -classpath $OUT1 -d $OUT1 $OUT/B.scala" > "$tmp" 2>&1 || echo "ok"
59-
cat "$tmp" # for debugging
59+
# cat "$tmp" # for debugging
6060
grep -qe "B.scala:2:7" "$tmp"
6161
grep -qe "This location contains code that was inlined from A.scala:3" "$tmp"
6262

tests/neg-macros/i6371/A_1.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted.*
2+
object A {
3+
inline def foo(a: Any): Unit = ${ crashOnInline }
4+
def crashOnInline(using Quotes): Expr[Unit] = ???
5+
}
File renamed without changes.

tests/neg/i6371/A_1.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/pos/i8967.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
inline def aToB[T,A,B](t:T,b:B): T|B = t match {
2+
case _:A => b
3+
case _:T => t
4+
}
5+
6+
@main def main() = aToB[Int, Double, String](1,"x")

0 commit comments

Comments
 (0)