Skip to content

Commit f7fdf6e

Browse files
committed
Fix creating forwarders for simple alias givens
Fixes #16191
1 parent 62684d0 commit f7fdf6e

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-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/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/i16191.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Context
2+
3+
def foo =
4+
val ctx: Context = new Context
5+
given a: Context = ctx
6+
7+
class C:
8+
private val ctx: Context = new Context
9+
given Context = ctx
10+
given C = this
11+
12+
@main def Test =
13+
val c = new C()
14+
println(c.getClass.getDeclaredFields.toList)
15+

0 commit comments

Comments
 (0)