diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 5209f71e5dd1..2679fbeaf94d 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -345,7 +345,7 @@ object TypeTestsCasts { val argType = tree.args.head.tpe val isTrusted = tree.hasAttachment(PatternMatcher.TrustedTypeTestKey) if (!isTrusted && !checkable(expr.tpe, argType, tree.span)) - report.warning(i"the type test for $argType cannot be checked at runtime", tree.srcPos) + report.warning(i"the type test for $argType cannot be checked at runtime", expr.srcPos) transformTypeTest(expr, tree.args.head.tpe, flagUnrelated = true) } else if (sym.isTypeCast) diff --git a/tests/neg-custom-args/fatal-warnings/i12253.check b/tests/neg-custom-args/fatal-warnings/i12253.check new file mode 100644 index 000000000000..1cda504511af --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i12253.check @@ -0,0 +1,8 @@ +-- Error: tests/neg-custom-args/fatal-warnings/i12253.scala:11:10 ------------------------------------------------------ +11 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error + | ^ + | the type test for extractors.q2.reflect.Term cannot be checked at runtime +-- Error: tests/neg-custom-args/fatal-warnings/i12253.scala:11:38 ------------------------------------------------------ +11 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error + | ^ + | the type test for q1.reflect.Select cannot be checked at runtime diff --git a/tests/neg-custom-args/fatal-warnings/i12253.scala b/tests/neg-custom-args/fatal-warnings/i12253.scala new file mode 100644 index 000000000000..5fdf1c83504d --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i12253.scala @@ -0,0 +1,28 @@ +import scala.quoted.{given, *} +import deriving.*, compiletime.* + +object MacroUtils: + transparent inline def extractNameFromSelector[To, T](inline code: To => T) = ${extractNameFromSelectorImpl('code)} + + def extractNameFromSelectorImpl[To: Type, T: Type](code: Expr[To => T])(using q1: Quotes): Expr[String] = + import quotes.reflect.* + val extractors = new Extractors + code.asTerm match + case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error + case t => report.throwError(s"Illegal argument to extractor: ${code.show}, in tasty: $t") + + class Extractors(using val q2: Quotes): + //attempt to strip away consecutive inlines in AST and extract only final lambda + import quotes.reflect.* + + object InlinedLambda: + def unapply(arg: Term): Option[(List[ValDef], Term)] = + arg match + case Inlined(_, _, Lambda(vals, term)) => Some((vals, term)) + case Inlined(_, _, nested) => InlinedLambda.unapply(nested) + case t => None + end InlinedLambda + + end Extractors +end MacroUtils +