Skip to content

Commit a15bd38

Browse files
Fix creating forwarders for simple alias givens (#16193)
Fixes #16191
2 parents 92f6b8c + b0e1f74 commit a15bd38

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ object Flags {
571571
val GivenOrImplicit: FlagSet = Given | Implicit
572572
val GivenOrImplicitVal: FlagSet = GivenOrImplicit.toTermFlags
573573
val GivenMethod: FlagSet = Given | Method
574+
val LazyGiven: FlagSet = Given | Lazy
574575
val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */
575576
val InlineMethod: FlagSet = Inline | Method
576577
val InlineParam: FlagSet = Inline | Param

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class UncacheGivenAliases extends MiniPhase with IdentityDenotTransformer:
5353
*/
5454
override def transformValDef(tree: ValDef)(using Context): Tree =
5555
val sym = tree.symbol
56-
if sym.isAllOf(Given, Lazy) && !needsCache(sym, tree.rhs) then
56+
if sym.isAllOf(LazyGiven) && !needsCache(sym, tree.rhs) then
5757
sym.copySymDenotation(
5858
initFlags = sym.flags &~ Lazy | Method,
5959
info = ExprType(sym.info))

tests/run-deep-subtype/i16191.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
List(private final Context C.ctx)

tests/run-deep-subtype/i16191.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This does not need deep-sub-type. It was placed here to avoid being run from JS tests.
2+
class Context
3+
4+
def foo =
5+
val ctx: Context = new Context
6+
given a: Context = ctx
7+
8+
class C:
9+
private val ctx: Context = new Context
10+
given Context = ctx
11+
given C = this
12+
13+
@main def Test =
14+
val c = new C()
15+
println(c.getClass.getDeclaredFields.toList)
16+

0 commit comments

Comments
 (0)