diff options
author | liu fengyun <liu@fengy.me> | 2017-02-02 02:10:28 +0100 |
---|---|---|
committer | liu fengyun <liu@fengy.me> | 2017-02-02 02:18:11 +0100 |
commit | 33ee93abd302fb30b040c52551650e0a4bba61e7 (patch) | |
tree | 27e49c6ca9abd344a60c78fe014472a30aa214e7 | |
parent | b5185f1b4481ef61243741c7f7ed0ba8f696776b (diff) | |
download | dotty-33ee93abd302fb30b040c52551650e0a4bba61e7.tar.gz dotty-33ee93abd302fb30b040c52551650e0a4bba61e7.tar.bz2 dotty-33ee93abd302fb30b040c52551650e0a4bba61e7.zip |
support pre-typer transform of trees
Currently `mergeCompanionDefs` assume `ModuleDef` is expanded
exactly to `module val; module class`. To enable more
general pre-typer transform, we need to weaken the assumption
to that the first two elements of the thicket must be
`module val; module class`.
This change will enable transform def macros defined inside
an object, as well as other pre-typer transforms.
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Namer.scala | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 068ef3e4b..931381f1f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -498,7 +498,9 @@ class Namer { typer: Typer => } for (mdef @ ModuleDef(name, _) <- stats if !mdef.mods.is(Flags.Package)) { val typName = name.toTypeName - val Thicket(vdef :: (mcls @ TypeDef(_, impl: Template)) :: Nil) = mdef.attachment(ExpandedTree) + // Expansion of object is a flattened thicket with the first two elements being: + // module val :: module class :: rest + val Thicket(vdef :: (mcls @ TypeDef(_, impl: Template)) :: rest) = expanded(mdef) moduleDef(typName) = mcls classDef get name.toTypeName match { case Some(cdef) => @@ -506,7 +508,7 @@ class Namer { typer: Typer => case Thicket(cls :: mval :: TypeDef(_, compimpl: Template) :: crest) => val mcls1 = cpy.TypeDef(mcls)( rhs = cpy.Template(impl)(body = compimpl.body ++ impl.body)) - mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: Nil)) + mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: rest)) moduleDef(typName) = mcls1 cdef.putAttachment(ExpandedTree, Thicket(cls :: crest)) case _ => |