Skip to content

Commit b1a3e6d

Browse files
Merge pull request #12255 from dotty-staging/fix-#12253-2
Improve type test error message position
2 parents 8a67e28 + a7b1337 commit b1a3e6d

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ object TypeTestsCasts {
345345
val argType = tree.args.head.tpe
346346
val isTrusted = tree.hasAttachment(PatternMatcher.TrustedTypeTestKey)
347347
if (!isTrusted && !checkable(expr.tpe, argType, tree.span))
348-
report.warning(i"the type test for $argType cannot be checked at runtime", tree.srcPos)
348+
report.warning(i"the type test for $argType cannot be checked at runtime", expr.srcPos)
349349
transformTypeTest(expr, tree.args.head.tpe, flagUnrelated = true)
350350
}
351351
else if (sym.isTypeCast)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg-custom-args/fatal-warnings/i12253.scala:11:10 ------------------------------------------------------
2+
11 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error
3+
| ^
4+
| the type test for extractors.q2.reflect.Term cannot be checked at runtime
5+
-- Error: tests/neg-custom-args/fatal-warnings/i12253.scala:11:38 ------------------------------------------------------
6+
11 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error
7+
| ^
8+
| the type test for q1.reflect.Select cannot be checked at runtime
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import scala.quoted.{given, *}
2+
import deriving.*, compiletime.*
3+
4+
object MacroUtils:
5+
transparent inline def extractNameFromSelector[To, T](inline code: To => T) = ${extractNameFromSelectorImpl('code)}
6+
7+
def extractNameFromSelectorImpl[To: Type, T: Type](code: Expr[To => T])(using q1: Quotes): Expr[String] =
8+
import quotes.reflect.*
9+
val extractors = new Extractors
10+
code.asTerm match
11+
case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error
12+
case t => report.throwError(s"Illegal argument to extractor: ${code.show}, in tasty: $t")
13+
14+
class Extractors(using val q2: Quotes):
15+
//attempt to strip away consecutive inlines in AST and extract only final lambda
16+
import quotes.reflect.*
17+
18+
object InlinedLambda:
19+
def unapply(arg: Term): Option[(List[ValDef], Term)] =
20+
arg match
21+
case Inlined(_, _, Lambda(vals, term)) => Some((vals, term))
22+
case Inlined(_, _, nested) => InlinedLambda.unapply(nested)
23+
case t => None
24+
end InlinedLambda
25+
26+
end Extractors
27+
end MacroUtils
28+

0 commit comments

Comments
 (0)