diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-16 18:20:39 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-16 18:20:39 +0100 |
commit | e3bc2e9abc9e1749de2cf4ab899d4cb31594869e (patch) | |
tree | 115f62c2d174479d191204001fe59e4a80e0ecbb /src/dotty/tools/dotc/core/Types.scala | |
parent | ef09dd258e91bd83100edae267ffa656461d7bc5 (diff) | |
download | dotty-e3bc2e9abc9e1749de2cf4ab899d4cb31594869e.tar.gz dotty-e3bc2e9abc9e1749de2cf4ab899d4cb31594869e.tar.bz2 dotty-e3bc2e9abc9e1749de2cf4ab899d4cb31594869e.zip |
Generalize implicit scope of ThisType
The implicit scope of a ThisType is now always the implicit scope of the self type. This caused cycles which necessitated cycle detectors in namedParts and computeImplicitScope.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 4e961ecd9..b3d33e358 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2325,22 +2325,28 @@ object Types { class NamedPartsAccumulator(p: NamedType => Boolean)(implicit ctx: Context) extends TypeAccumulator[mutable.Set[NamedType]] { def maybeAdd(x: mutable.Set[NamedType], tp: NamedType) = if (p(tp)) x += tp else x - def apply(x: mutable.Set[NamedType], tp: Type): mutable.Set[NamedType] = tp match { - case tp: TermRef => - apply(foldOver(maybeAdd(x, tp), tp), tp.underlying) - case tp: TypeRef => - foldOver(maybeAdd(x, tp), tp) - case tp: ThisType => - apply(x, if (tp.cls is Module) tp.underlying else tp.cls.typeRef) - case tp: ConstantType => - apply(x, tp.underlying) - case tp: MethodParam => - apply(x, tp.underlying) - case tp: PolyParam => - apply(x, tp.underlying) - case _ => - foldOver(x, tp) - } + val seen: mutable.Set[Type] = mutable.Set() + def apply(x: mutable.Set[NamedType], tp: Type): mutable.Set[NamedType] = + if (seen contains tp) x + else { + seen += tp + tp match { + case tp: TermRef => + apply(foldOver(maybeAdd(x, tp), tp), tp.underlying) + case tp: TypeRef => + foldOver(maybeAdd(x, tp), tp) + case tp: ThisType => + apply(x, tp.underlying) + case tp: ConstantType => + apply(x, tp.underlying) + case tp: MethodParam => + apply(x, tp.underlying) + case tp: PolyParam => + apply(x, tp.underlying) + case _ => + foldOver(x, tp) + } + } } // ----- Name Filters -------------------------------------------------- |