@@ -362,7 +362,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
362
362
if (inlinedMethod == defn.Typelevel_constValue ) {
363
363
val constVal = tryConstValue
364
364
if (! constVal.isEmpty) return constVal
365
- ctx.error(i " not a constant type: ${callTypeArgs.head}; cannot take constValue " )
365
+ ctx.error(i " not a constant type: ${callTypeArgs.head}; cannot take constValue " , call.pos )
366
366
}
367
367
else if (inlinedMethod == defn.Typelevel_constValueOpt ) {
368
368
val constVal = tryConstValue
@@ -450,7 +450,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
450
450
case (msgArg :: Nil ) :: Nil =>
451
451
msgArg.tpe match {
452
452
case ConstantType (Constant (msg : String )) =>
453
- ctx.error(msg, call.pos)
453
+ // Usually `error` is called from within a rewrite method. In this
454
+ // case we need to report the error at the point of the outermost enclosing inline
455
+ // call. This way, a defensively written rewrite methid can always
456
+ // report bad inputs at the point of call instead of revealing its internals.
457
+ val callToReport = if (enclosingInlineds.nonEmpty) enclosingInlineds.last else call
458
+ val ctxToReport = ctx.outersIterator.dropWhile(enclosingInlineds(_).nonEmpty).next
459
+ def issueInCtx (implicit ctx : Context ) = ctx.error(msg, callToReport.pos)
460
+ issueInCtx(ctxToReport)
454
461
case _ =>
455
462
}
456
463
case _ =>
0 commit comments