aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-01-05 16:02:09 +0700
committerMartin Odersky <odersky@gmail.com>2017-01-05 18:00:06 +0700
commitaa6ebe938639f07dd6f5612e645f1449f37a86eb (patch)
tree24d257c1f12d0f5cb9b76102043046e3a904d98a /compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
parent42eb864dc752254fc3b8b0428570fe94aa1dafc7 (diff)
downloaddotty-aa6ebe938639f07dd6f5612e645f1449f37a86eb.tar.gz
dotty-aa6ebe938639f07dd6f5612e645f1449f37a86eb.tar.bz2
dotty-aa6ebe938639f07dd6f5612e645f1449f37a86eb.zip
Implement structural type member access
New scheme for implementing structural type member access.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/ast/TreeInfo.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/ast/TreeInfo.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
index da83d0644..429b7235b 100644
--- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
+++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
@@ -629,6 +629,28 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
case nil =>
Nil
}
+
+ /** Is this a selection of a member of a structural type that is not a member
+ * of an underlying class or trait?
+ */
+ def isStructuralTermSelect(tree: Tree)(implicit ctx: Context) = tree match {
+ case tree: Select =>
+ def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match {
+ case RefinedType(parent, rname, rinfo) =>
+ rname == tree.name && tree.tpe.widen <:< rinfo || hasRefinement(parent)
+ case tp: TypeProxy =>
+ hasRefinement(tp.underlying)
+ case tp: OrType =>
+ hasRefinement(tp.tp1) || hasRefinement(tp.tp2)
+ case tp: AndType =>
+ hasRefinement(tp.tp1) && hasRefinement(tp.tp2)
+ case _ =>
+ false
+ }
+ !tree.symbol.exists && tree.isTerm && hasRefinement(tree.qualifier.tpe)
+ case _ =>
+ false
+ }
}
object TreeInfo {