aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/tpd.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-24 18:04:22 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-24 18:09:01 +0200
commitaa7a0399ad5424dd5292f2f1941c7293c16d6b79 (patch)
treefcc3efccc01f6d5160774c0b3998481f2d492500 /src/dotty/tools/dotc/ast/tpd.scala
parent70abd73e9306eca3ec4de1d98b877e4fafe66ad0 (diff)
downloaddotty-aa7a0399ad5424dd5292f2f1941c7293c16d6b79.tar.gz
dotty-aa7a0399ad5424dd5292f2f1941c7293c16d6b79.tar.bz2
dotty-aa7a0399ad5424dd5292f2f1941c7293c16d6b79.zip
Check that idents don't assume magic.
In TreeChecker, make sure that every identifier has a type with an elidable prefix. This excludes identifiers pointing to members of random prefixes without making the prefix explicit in the tree as part of a Select node.
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r--src/dotty/tools/dotc/ast/tpd.scala21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala
index 5a9198adc..db0171d55 100644
--- a/src/dotty/tools/dotc/ast/tpd.scala
+++ b/src/dotty/tools/dotc/ast/tpd.scala
@@ -35,7 +35,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
untpd.SelectFromTypeTree(qualifier, tp.name).withType(tp)
def This(cls: ClassSymbol)(implicit ctx: Context): This =
- ta.assignType(untpd.This(cls.name))
+ untpd.This(cls.name).withType(cls.thisType)
def Super(qual: Tree, mix: TypeName, inConstrCall: Boolean)(implicit ctx: Context): Super =
ta.assignType(untpd.Super(qual, mix), qual, inConstrCall)
@@ -252,9 +252,26 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
// ------ Making references ------------------------------------------------------
+ def prefixIsElidable(tp: NamedType)(implicit ctx: Context) = tp.prefix match {
+ case NoPrefix =>
+ true
+ case ThisType(cls) =>
+ cls.isStaticOwner ||
+ tp.symbol.is(ParamOrAccessor) && tp.symbol.maybeOwner.enclosingClass == cls
+ case pre: TermRef =>
+ pre.symbol.is(Module) && pre.symbol.isStatic
+ case _ =>
+ false
+ }
+
+ def needsSelect(tp: Type)(implicit ctx: Context) = tp match {
+ case tp: TermRef => !prefixIsElidable(tp)
+ case _ => false
+ }
+
/** A tree representing the same reference as the given type */
def ref(tp: NamedType)(implicit ctx: Context): NameTree =
- if (tp.symbol.isStatic || tp.prefix == NoPrefix) Ident(tp)
+ if (prefixIsElidable(tp)) Ident(tp)
else tp.prefix match {
case pre: SingletonType => singleton(pre).select(tp)
case pre => SelectFromTypeTree(TypeTree(pre), tp)