diff options
author | Martin Odersky <odersky@gmail.com> | 2014-10-17 15:35:11 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-10-26 16:24:00 +0100 |
commit | 3fea9472c0d068bc08ae764429ca6b4bca95bcd8 (patch) | |
tree | 06a7a208ec8e4afb1a3a964d64fb22e594c74c0c /src/dotty/tools/dotc/typer/TypeAssigner.scala | |
parent | 25a8937f115ed2ac1af33c41c73a621dab4ee712 (diff) | |
download | dotty-3fea9472c0d068bc08ae764429ca6b4bca95bcd8.tar.gz dotty-3fea9472c0d068bc08ae764429ca6b4bca95bcd8.tar.bz2 dotty-3fea9472c0d068bc08ae764429ca6b4bca95bcd8.zip |
Avoid hoisting local classes
The patch disables hoisting of classes local to a block into the
result type of the block.
Instead, we widen the result type of the block to one which reflects
all refinements made to the parents type of the local class.
Test cases in avoid.scala, t1569.scala.
The original t1569.scala no longer works. Why is explained in neg/t1569-failedAvoid.scala
Diffstat (limited to 'src/dotty/tools/dotc/typer/TypeAssigner.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index ccf67b55b..cb6fefab1 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -49,7 +49,21 @@ trait TypeAssigner { case TypeAlias(ref) => apply(ref) case info: ClassInfo => - mapOver(info.instantiatedParents.reduceLeft(ctx.typeComparer.andType(_, _))) + val parentType = info.instantiatedParents.reduceLeft(ctx.typeComparer.andType(_, _)) + def addRefinement(parent: Type, decl: Symbol) = { + val inherited = parentType.findMember(decl.name, info.cls.thisType, Private) + val inheritedInfo = inherited.atSignature(decl.info .signature).info + if (inheritedInfo.exists && decl.info <:< inheritedInfo && !(inheritedInfo <:< decl.info)) + typr.echo( + i"add ref $parent $decl --> ", + RefinedType(parent, decl.name, decl.info)) + else + parent + } + val refinableDecls = info.decls.filterNot( + sym => sym.is(TypeParamAccessor | Private) || sym.isConstructor) + val fullType = (parentType /: refinableDecls)(addRefinement) + mapOver(fullType) case _ => mapOver(tp) } |