Skip to content

Commit 8cc9ba3

Browse files
committed
Only set needsInlining if not transforming the inlined call.
1 parent d1d6c2e commit 8cc9ba3

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/core/Mode.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,7 @@ object Mode {
141141
* Type `Null` becomes a subtype of non-primitive value types in TypeComparer.
142142
*/
143143
val RelaxedOverriding: Mode = newMode(30, "RelaxedOverriding")
144+
145+
/** We are checking the original call of an Inlined node */
146+
val InlinedCall: Mode = newMode(31, "InlinedCall")
144147
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
283283
if tree.isType then
284284
checkNotPackage(tree)
285285
else
286-
if tree.symbol.is(Inline) && !Inlines.inInlineMethod then
287-
ctx.compilationUnit.needsInlining = true
288286
checkNoConstructorProxy(tree)
287+
registerNeedsInlining(tree)
289288
tree.tpe match {
290289
case tpe: ThisType => This(tpe.cls).withSpan(tree.span)
291290
case _ => tree
292291
}
293292
case tree @ Select(qual, name) =>
294-
if tree.symbol.is(Inline) then
295-
ctx.compilationUnit.needsInlining = true
293+
registerNeedsInlining(tree)
296294
if name.isTypeName then
297295
Checking.checkRealizable(qual.tpe, qual.srcPos)
298296
withMode(Mode.Type)(super.transform(checkNotPackage(tree)))
@@ -344,8 +342,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
344342
case tree: TypeApply =>
345343
if tree.symbol.isQuote then
346344
ctx.compilationUnit.needsStaging = true
347-
if tree.symbol.is(Inline) then
348-
ctx.compilationUnit.needsInlining = true
345+
registerNeedsInlining(tree)
349346
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
350347
for arg <- args do
351348
checkInferredWellFormed(arg)
@@ -363,7 +360,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
363360
case Inlined(call, bindings, expansion) if !call.isEmpty =>
364361
val pos = call.sourcePos
365362
CrossVersionChecks.checkExperimentalRef(call.symbol, pos)
366-
super.transform(call)
363+
withMode(Mode.InlinedCall)(transform(call))
367364
val callTrace = Inlines.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
368365
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(call)))
369366
case templ: Template =>
@@ -505,6 +502,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
505502
private def normalizeErasedRhs(rhs: Tree, sym: Symbol)(using Context) =
506503
if (sym.isEffectivelyErased) dropInlines.transform(rhs) else rhs
507504

505+
private def registerNeedsInlining(tree: Tree)(using Context): Unit =
506+
if tree.symbol.is(Inline) && !Inlines.inInlineMethod && !ctx.mode.is(Mode.InlinedCall) then
507+
ctx.compilationUnit.needsInlining = true
508+
508509
/** Check if the definition has macro annotation and sets `compilationUnit.hasMacroAnnotations` if needed. */
509510
private def registerIfHasMacroAnnotations(tree: DefTree)(using Context) =
510511
if !Inlines.inInlineMethod && MacroAnnotations.hasMacroAnnotation(tree.symbol) then

tests/neg/i17168.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
type F[X <: String] = X
22

3-
val a = summon[F[Int] =:= Int] // error
3+
val a = summon[F[Int] =:= Int] // error

0 commit comments

Comments
 (0)