aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/ast/Desugar.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2017-02-05 12:47:05 +0100
committerGuillaume Martres <smarter@ubuntu.com>2017-02-05 17:50:05 +0100
commitac868319ecf75bcffe6000a41379c5c12e92e62e (patch)
tree4fcef8e1a93bde01abb8fe4ccc4c7e44e28f60f4 /compiler/src/dotty/tools/dotc/ast/Desugar.scala
parentda7d7231b7f21fe1085abc569eb783590074a359 (diff)
downloaddotty-ac868319ecf75bcffe6000a41379c5c12e92e62e.tar.gz
dotty-ac868319ecf75bcffe6000a41379c5c12e92e62e.tar.bz2
dotty-ac868319ecf75bcffe6000a41379c5c12e92e62e.zip
Represent untyped operators as Ident instead of Name
This has two advantages: - We can distinguish BackquotedIdent from Ident, allowing the user to use a defined "type `&`", see testcase. - We get better positions for the operators. This is useful in IDEs, for example to get the type at point.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/ast/Desugar.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/ast/Desugar.scala24
1 files changed, 12 insertions, 12 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
index 2e471e046..3835355e3 100644
--- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
@@ -353,7 +353,7 @@ object desugar {
for (i <- 0 until arity if nme.selectorName(i) `ne` caseParams(i).name)
yield syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name))
def isRepeated(tree: Tree): Boolean = tree match {
- case PostfixOp(_, nme.raw.STAR) => true
+ case PostfixOp(_, Ident(nme.raw.STAR)) => true
case ByNameTypeTree(tree1) => isRepeated(tree1)
case _ => false
}
@@ -739,23 +739,23 @@ object desugar {
/** Translate infix operation expression left op right
*/
- def makeBinop(left: Tree, op: Name, right: Tree): Tree = {
+ def makeBinop(left: Tree, op: Ident, right: Tree): Tree = {
def assignToNamedArg(arg: Tree) = arg match {
case Assign(Ident(name), rhs) => cpy.NamedArg(arg)(name, rhs)
case _ => arg
}
- if (isLeftAssoc(op)) {
+ if (isLeftAssoc(op.name)) {
val args: List[Tree] = right match {
case Parens(arg) => assignToNamedArg(arg) :: Nil
case Tuple(args) => args mapConserve assignToNamedArg
case _ => right :: Nil
}
- Apply(Select(left, op), args)
+ Apply(Select(left, op.name), args)
} else {
val x = ctx.freshName().toTermName
new InfixOpBlock(
ValDef(x, TypeTree(), left).withMods(synthetic),
- Apply(Select(right, op), Ident(x)))
+ Apply(Select(right, op.name), Ident(x)))
}
}
@@ -956,25 +956,25 @@ object desugar {
Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems)
case InfixOp(l, op, r) =>
if (ctx.mode is Mode.Type)
- if (op == tpnme.raw.AMP) AndTypeTree(l, r) // l & r
- else if (op == tpnme.raw.BAR) OrTypeTree(l, r) // l | r
- else AppliedTypeTree(Ident(op), l :: r :: Nil) // op[l, r]
+ if (!op.isBackquoted && op.name == tpnme.raw.AMP) AndTypeTree(l, r) // l & r
+ else if (!op.isBackquoted && op.name == tpnme.raw.BAR) OrTypeTree(l, r) // l | r
+ else AppliedTypeTree(op, l :: r :: Nil) // op[l, r]
else if (ctx.mode is Mode.Pattern)
- Apply(Ident(op), l :: r :: Nil) // op(l, r)
+ Apply(op, l :: r :: Nil) // op(l, r)
else // l.op(r), or val x = r; l.op(x), plus handle named args specially
makeBinop(l, op, r)
case PostfixOp(t, op) =>
- if ((ctx.mode is Mode.Type) && op == nme.raw.STAR) {
+ if ((ctx.mode is Mode.Type) && !op.isBackquoted && op.name == nme.raw.STAR) {
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType
Annotated(
AppliedTypeTree(ref(seqType), t),
New(ref(defn.RepeatedAnnotType), Nil :: Nil))
} else {
assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode)
- Select(t, op)
+ Select(t, op.name)
}
case PrefixOp(op, t) =>
- Select(t, nme.UNARY_PREFIX ++ op)
+ Select(t, nme.UNARY_PREFIX ++ op.name)
case Parens(t) =>
t
case Tuple(ts) =>