Skip to content

Commit

Permalink
Merge pull request #14871 from dotty-staging/fix-8967
Browse files Browse the repository at this point in the history
Don't issue unreachable error messages for inlined code
  • Loading branch information
odersky authored Apr 8, 2022
2 parents e1ce523 + f0012e9 commit 63da64f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions project/scripts/cmdTests
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions tests/neg-macros/i6371/A_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted.*
object A {
inline def foo(a: Any): Unit = ${ crashOnInline }
def crashOnInline(using Quotes): Expr[Unit] = ???
}
File renamed without changes.
6 changes: 0 additions & 6 deletions tests/neg/i6371/A_1.scala

This file was deleted.

6 changes: 6 additions & 0 deletions tests/pos/i8967.scala
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 63da64f

Please sign in to comment.