Skip to content

Commit 33c078c

Browse files
committed
Add transparent modifier
1 parent ebb4d23 commit 33c078c

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ object Mode {
9393

9494
/** We are in the IDE */
9595
val Interactive = newMode(20, "Interactive")
96+
97+
/** We are typing the body of a transparent method */
98+
val TransparentBody = newMode(21, "TransparentBody")
9699
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ object SymDenotations {
783783
is(InlineMethod, butNot = Accessor)
784784

785785
def isTransparentMethod(implicit ctx: Context): Boolean =
786-
is(TransparentMethod, butNot = Accessor)
786+
is(TransparentMethod, butNot = AccessorOrSynthetic)
787787

788788
def isInlineableMethod(implicit ctx: Context) = isInlinedMethod || isTransparentMethod
789789

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ class TreeUnpickler(reader: TastyReader,
532532
rootd.symbol
533533
case _ =>
534534
val completer = adjustIfModule(new Completer(ctx.owner, subReader(start, end)))
535-
F if (isClass)
535+
if (isClass)
536536
ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord)
537537
else
538538
ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord)
@@ -547,7 +547,7 @@ F if (isClass)
547547
sym.completer.withDecls(newScope)
548548
forkAt(templateStart).indexTemplateParams()(localContext(sym))
549549
}
550-
else if (sym.isInlineableMethod)
550+
else if (sym.isInlinedMethod)
551551
sym.addAnnotation(LazyBodyAnnotation { ctx0 =>
552552
implicit val ctx: Context = localContext(sym)(ctx0).addMode(Mode.ReadPositions)
553553
// avoids space leaks by not capturing the current context

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ object Inliner {
232232
* from Scala2x class files might be `@inline`, but still lack that body.
233233
*/
234234
def hasBodyToInline(sym: SymDenotation)(implicit ctx: Context): Boolean =
235-
sym.isInlinedMethod && sym.hasAnnotation(defn.BodyAnnot) // TODO: Open this up for transparent methods as well
235+
sym.isInlineableMethod && sym.hasAnnotation(defn.BodyAnnot)
236236

237237
/** The body to inline for method `sym`.
238238
* @pre hasBodyToInline(sym)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,8 @@ class Namer { typer: Typer =>
11281128
// it would be erased to BoxedUnit.
11291129
def dealiasIfUnit(tp: Type) = if (tp.isRef(defn.UnitClass)) defn.UnitType else tp
11301130

1131-
val rhsCtx = ctx.addMode(Mode.InferringReturnType)
1131+
var rhsCtx = ctx.addMode(Mode.InferringReturnType)
1132+
if (sym.isTransparentMethod) rhsCtx = rhsCtx.addMode(Mode.TransparentBody)
11321133
def rhsType = typedAheadExpr(mdef.rhs, inherited orElse rhsProto)(rhsCtx).tpe
11331134

11341135
// Approximate a type `tp` with a type that does not contain skolem types.

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ class Typer extends Namer
14281428
(tparams1, sym.owner.typeParams).zipped.foreach ((tdef, tparam) =>
14291429
rhsCtx.gadt.setBounds(tdef.symbol, TypeAlias(tparam.typeRef)))
14301430
}
1431+
if (sym.isTransparentMethod) rhsCtx = rhsCtx.addMode(Mode.TransparentBody)
14311432
val rhs1 = normalizeErasedRhs(typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx), sym)
14321433

14331434
// Overwrite inline body to make sure it is not evaluated twice

0 commit comments

Comments
 (0)