Skip to content

Commit d28ac36

Browse files
authored
Preserve type bounds for inlined definitions in posttyper (#17190)
2 parents 7d6c835 + 8cc9ba3 commit d28ac36

File tree

6 files changed

+18
-24
lines changed

6 files changed

+18
-24
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 & 6 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 == defn.QuotedTypeModule_of 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,6 +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)
363+
withMode(Mode.InlinedCall)(transform(call))
366364
val callTrace = Inlines.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
367365
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(call)))
368366
case templ: Template =>
@@ -507,6 +505,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
507505
private def normalizeErasedRhs(rhs: Tree, sym: Symbol)(using Context) =
508506
if (sym.isEffectivelyErased) dropInlines.transform(rhs) else rhs
509507

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

tests/neg/i17168.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type F[X <: String] = X
2+
3+
val a = summon[F[Int] =:= Int] // error

tests/pos/i13332super.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/run/anon-mirror-gen-local.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Outer5 { self =>
5555
}
5656
}
5757

58-
lazy val o = new Outer5() // infinite init
58+
final lazy val o = new Outer5() // infinite init
5959

6060
}
6161

@@ -142,7 +142,7 @@ def locally3 = {
142142
class Bar extends Foo {
143143

144144
def hello =
145-
val mQux = summon[Mirror.Of[Bar.super.foo.type]]
145+
val mQux = summon[Mirror.Of[foo.type]]
146146
assert(mQux.fromProduct(EmptyTuple) == Qux)
147147
}
148148

@@ -157,4 +157,4 @@ def locally3 = {
157157
testOuter6
158158
locally1
159159
locally2
160-
locally3
160+
locally3

tests/run/i13332a.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class SubUniverse extends Universe {
150150

151151
trait Whole {
152152
trait MixinA {
153-
lazy val mixinB = new MixinB() {}
153+
final lazy val mixinB = new MixinB() {}
154154
}
155155
trait MixinB {
156156
object A extends MixinB { // by inheriting `MixinB`, we should not check for inheritance from the right

0 commit comments

Comments
 (0)