From 975d297cc42dd170fe8869474038a4204771a7a1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 11 Sep 2016 13:48:02 +0200 Subject: Fix problem related to accessor generation under separate compilation Accessors were multiply generated under separate compilation. To fix this, the resident body of an inlined function is now the same as the inlined body. Both use accessors where necessary. Previously, only the inlined body used accessors. --- src/dotty/tools/dotc/typer/Typer.scala | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Typer.scala') diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index dde2c866b..60f04b268 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1495,10 +1495,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case Some(xtree) => traverse(xtree :: rest) case none => - val mdef1 = typed(mdef) - buf += mdef1 - if (Inliner.hasBodyToInline(mdef1.symbol)) - buf ++= Inliner.removeInlineAccessors(mdef1.symbol) + typed(mdef) match { + case mdef1: DefDef if Inliner.hasBodyToInline(mdef1.symbol) => + buf ++= inlineExpansion(mdef1) + case mdef1 => + buf += mdef1 + } traverse(rest) } case Thicket(stats) :: rest => @@ -1512,6 +1514,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit traverse(stats) } + /** Given an inline method `mdef`, the method rewritten so that its body + * uses accessors to access non-public members, followed by the accessor definitions. + * Overwritten in Retyper to return `mdef` unchanged. + */ + protected def inlineExpansion(mdef: DefDef)(implicit ctx: Context): List[Tree] = + tpd.cpy.DefDef(mdef)(rhs = Inliner.bodyToInline(mdef.symbol)) :: + Inliner.removeInlineAccessors(mdef.symbol) + def typedExpr(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = typed(tree, pt)(ctx retractMode Mode.PatternOrType) def typedType(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = // todo: retract mode between Type and Pattern? -- cgit v1.2.3