diff --git a/compiler/src/dotty/tools/dotc/core/Mode.scala b/compiler/src/dotty/tools/dotc/core/Mode.scala index 40a45b9f4678..ea63eb6a419b 100644 --- a/compiler/src/dotty/tools/dotc/core/Mode.scala +++ b/compiler/src/dotty/tools/dotc/core/Mode.scala @@ -141,4 +141,7 @@ object Mode { * Type `Null` becomes a subtype of non-primitive value types in TypeComparer. */ val RelaxedOverriding: Mode = newMode(30, "RelaxedOverriding") + + /** We are checking the original call of an Inlined node */ + val InlinedCall: Mode = newMode(31, "InlinedCall") } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 7f3e47c14732..09f0fa49c527 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -283,16 +283,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase if tree.isType then checkNotPackage(tree) else - if tree.symbol.is(Inline) && !Inlines.inInlineMethod then - ctx.compilationUnit.needsInlining = true checkNoConstructorProxy(tree) + registerNeedsInlining(tree) tree.tpe match { case tpe: ThisType => This(tpe.cls).withSpan(tree.span) case _ => tree } case tree @ Select(qual, name) => - if tree.symbol.is(Inline) then - ctx.compilationUnit.needsInlining = true + registerNeedsInlining(tree) if name.isTypeName then Checking.checkRealizable(qual.tpe, qual.srcPos) withMode(Mode.Type)(super.transform(checkNotPackage(tree))) @@ -344,8 +342,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase case tree: TypeApply => if tree.symbol.isQuote then ctx.compilationUnit.needsStaging = true - if tree.symbol.is(Inline) then - ctx.compilationUnit.needsInlining = true + registerNeedsInlining(tree) val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree) for arg <- args do checkInferredWellFormed(arg) @@ -363,6 +360,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase case Inlined(call, bindings, expansion) if !call.isEmpty => val pos = call.sourcePos CrossVersionChecks.checkExperimentalRef(call.symbol, pos) + withMode(Mode.InlinedCall)(transform(call)) val callTrace = Inlines.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source)) cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(call))) case templ: Template => @@ -504,6 +502,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase private def normalizeErasedRhs(rhs: Tree, sym: Symbol)(using Context) = if (sym.isEffectivelyErased) dropInlines.transform(rhs) else rhs + private def registerNeedsInlining(tree: Tree)(using Context): Unit = + if tree.symbol.is(Inline) && !Inlines.inInlineMethod && !ctx.mode.is(Mode.InlinedCall) then + ctx.compilationUnit.needsInlining = true + /** Check if the definition has macro annotation and sets `compilationUnit.hasMacroAnnotations` if needed. */ private def registerIfHasMacroAnnotations(tree: DefTree)(using Context) = if !Inlines.inInlineMethod && MacroAnnotations.hasMacroAnnotation(tree.symbol) then diff --git a/tests/neg/i17168.scala b/tests/neg/i17168.scala new file mode 100644 index 000000000000..c31889c979b7 --- /dev/null +++ b/tests/neg/i17168.scala @@ -0,0 +1,3 @@ +type F[X <: String] = X + +val a = summon[F[Int] =:= Int] // error diff --git a/tests/pos/i13332super.scala b/tests/pos/i13332super.scala deleted file mode 100644 index 1ab695d5d4a5..000000000000 --- a/tests/pos/i13332super.scala +++ /dev/null @@ -1,14 +0,0 @@ -import scala.deriving.Mirror - -trait MixinAMini { - lazy val mixinB = new MixinBMini() {} -} -trait MixinBMini { - sealed trait Lst // crucially, no companion is defined - case class Cn(h: Int, t: Lst) extends Lst - case object Nl extends Lst -} -trait SubABMini extends MixinAMini with MixinBMini { - val mirror_SubABMini_super_mixinB_Lst = - summon[Mirror.Of[SubABMini.super[MixinAMini].mixinB.Lst]] -} diff --git a/tests/run/anon-mirror-gen-local.scala b/tests/run/anon-mirror-gen-local.scala index 68fb9500d5ba..ccd1ac4fc602 100644 --- a/tests/run/anon-mirror-gen-local.scala +++ b/tests/run/anon-mirror-gen-local.scala @@ -55,7 +55,7 @@ class Outer5 { self => } } - lazy val o = new Outer5() // infinite init + final lazy val o = new Outer5() // infinite init } @@ -142,7 +142,7 @@ def locally3 = { class Bar extends Foo { def hello = - val mQux = summon[Mirror.Of[Bar.super.foo.type]] + val mQux = summon[Mirror.Of[foo.type]] assert(mQux.fromProduct(EmptyTuple) == Qux) } @@ -157,4 +157,4 @@ def locally3 = { testOuter6 locally1 locally2 - locally3 \ No newline at end of file + locally3 diff --git a/tests/run/i13332a.scala b/tests/run/i13332a.scala index 3478ed325467..c4bd33ede153 100644 --- a/tests/run/i13332a.scala +++ b/tests/run/i13332a.scala @@ -150,7 +150,7 @@ class SubUniverse extends Universe { trait Whole { trait MixinA { - lazy val mixinB = new MixinB() {} + final lazy val mixinB = new MixinB() {} } trait MixinB { object A extends MixinB { // by inheriting `MixinB`, we should not check for inheritance from the right