diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 72428d02f5d3..8bf65ed8288f 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -571,6 +571,7 @@ object Flags { val GivenOrImplicit: FlagSet = Given | Implicit val GivenOrImplicitVal: FlagSet = GivenOrImplicit.toTermFlags val GivenMethod: FlagSet = Given | Method + val LazyGiven: FlagSet = Given | Lazy val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */ val InlineMethod: FlagSet = Inline | Method val InlineParam: FlagSet = Inline | Param diff --git a/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala b/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala index 56fd4f754d60..95d40102c5a7 100644 --- a/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala +++ b/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala @@ -53,7 +53,7 @@ class UncacheGivenAliases extends MiniPhase with IdentityDenotTransformer: */ override def transformValDef(tree: ValDef)(using Context): Tree = val sym = tree.symbol - if sym.isAllOf(Given, Lazy) && !needsCache(sym, tree.rhs) then + if sym.isAllOf(LazyGiven) && !needsCache(sym, tree.rhs) then sym.copySymDenotation( initFlags = sym.flags &~ Lazy | Method, info = ExprType(sym.info)) diff --git a/tests/run-deep-subtype/i16191.check b/tests/run-deep-subtype/i16191.check new file mode 100644 index 000000000000..e5eae6f0a701 --- /dev/null +++ b/tests/run-deep-subtype/i16191.check @@ -0,0 +1 @@ +List(private final Context C.ctx) diff --git a/tests/run-deep-subtype/i16191.scala b/tests/run-deep-subtype/i16191.scala new file mode 100644 index 000000000000..126632c0b67c --- /dev/null +++ b/tests/run-deep-subtype/i16191.scala @@ -0,0 +1,16 @@ +// This does not need deep-sub-type. It was placed here to avoid being run from JS tests. +class Context + +def foo = + val ctx: Context = new Context + given a: Context = ctx + +class C: + private val ctx: Context = new Context + given Context = ctx + given C = this + +@main def Test = + val c = new C() + println(c.getClass.getDeclaredFields.toList) +