Skip to content

Commit

Permalink
Fix creating forwarders for simple alias givens (scala#16193)
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban authored Oct 16, 2022
2 parents 92f6b8c + b0e1f74 commit a15bd38
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions tests/run-deep-subtype/i16191.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List(private final Context C.ctx)
16 changes: 16 additions & 0 deletions tests/run-deep-subtype/i16191.scala
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a15bd38

Please sign in to comment.