diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-10 11:15:21 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-12-14 14:30:09 +0100 |
commit | f829cf8ba742b149a10250710c46b5a1c49aa7cc (patch) | |
tree | 65b55ddd4abeaf6e6e95b9b730d31be48ea23f25 /src | |
parent | 2a3f78673afe581fffec7f88039ba27a71ed2fe2 (diff) | |
download | dotty-f829cf8ba742b149a10250710c46b5a1c49aa7cc.tar.gz dotty-f829cf8ba742b149a10250710c46b5a1c49aa7cc.tar.bz2 dotty-f829cf8ba742b149a10250710c46b5a1c49aa7cc.zip |
Make some types of definitions symbolic
This is needed to ensure that the type of a definition node
(ValDef, TypeDef, or DefDef) always refers to the symbol of
that definition.
Caused a spurious error in selfReq to go away (so error count was
updated).
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 30d6baf8a..69cea30dd 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -392,13 +392,30 @@ trait TypeAssigner { tree.withType(proto) def assignType(tree: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = - tree.withType(if (sym.exists) sym.valRef else NoType) + tree.withType(if (sym.exists) assertExists(symbolicIfNeeded(sym).orElse(sym.valRef)) else NoType) def assignType(tree: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = - tree.withType(sym.termRefWithSig) + tree.withType(symbolicIfNeeded(sym).orElse(sym.termRefWithSig)) def assignType(tree: untpd.TypeDef, sym: Symbol)(implicit ctx: Context) = - tree.withType(sym.typeRef) + tree.withType(symbolicIfNeeded(sym).orElse(sym.typeRef)) + + private def symbolicIfNeeded(sym: Symbol)(implicit ctx: Context) = { + val owner = sym.owner + owner.infoOrCompleter match { + case info: ClassInfo if !owner.is(Package) && info.givenSelfType.exists => + // In that case a simple typeRef/termWithWithSig could return a member of + // the self type, not the symbol itself. To avoid this, we make the reference + // symbolic. In general it seems to be faster to keep the non-symblic + // reference, since there is less pressure on the uniqueness tables that way + // and less work to update all the different references. That's why symbolic references + // are only used if necessary. + NamedType.withFixedSym(owner.thisType, sym) + case _ => NoType + } + } + + def assertExists(tp: Type) = { assert(tp != NoType); tp } def assignType(tree: untpd.Import, sym: Symbol)(implicit ctx: Context) = tree.withType(sym.nonMemberTermRef) |