@@ -1879,28 +1879,39 @@ class Typer extends Namer
18791879
18801880 /** Translate infix operation expression `l op r` to
18811881 *
1882- * l.op(r) if `op` is left-associative
1882+ * l.op(r) if `op` is left-associative
18831883 * { val x = l; r.op(l) } if `op` is right-associative call-by-value and `l` is impure
18841884 * r.op(l) if `op` is right-associative call-by-name or `l` is pure
1885+ *
1886+ * Translate infix type `l op r` to `op[l, r]`
1887+ * Translate infix pattern `l op r` to `op(l, r)`
18851888 */
18861889 def typedInfixOp (tree : untpd.InfixOp , pt : Type )(implicit ctx : Context ): Tree = {
18871890 val untpd .InfixOp (l, op, r) = tree
1888- val app = typedApply(desugar.binop(l, op, r), pt)
1889- checkValidInfix(tree, app)
1890- if (untpd.isLeftAssoc(op.name)) app
1891- else {
1892- val defs = new mutable.ListBuffer [Tree ]
1893- def lift (app : Tree ): Tree = (app : @ unchecked) match {
1894- case Apply (fn, args) =>
1895- if (app.tpe.isError) app
1896- else tpd.cpy.Apply (app)(fn, LiftImpure .liftArgs(defs, fn.tpe, args))
1897- case Assign (lhs, rhs) =>
1898- tpd.cpy.Assign (app)(lhs, lift(rhs))
1899- case Block (stats, expr) =>
1900- tpd.cpy.Block (app)(stats, lift(expr))
1891+ val result =
1892+ if (ctx.mode.is(Mode .Type ))
1893+ typedAppliedTypeTree(cpy.AppliedTypeTree (tree)(op, l :: r :: Nil ))
1894+ else if (ctx.mode.is(Mode .Pattern ))
1895+ typedUnApply(cpy.Apply (tree)(op, l :: r :: Nil ), pt)
1896+ else {
1897+ val app = typedApply(desugar.binop(l, op, r), pt)
1898+ if (untpd.isLeftAssoc(op.name)) app
1899+ else {
1900+ val defs = new mutable.ListBuffer [Tree ]
1901+ def lift (app : Tree ): Tree = (app : @ unchecked) match {
1902+ case Apply (fn, args) =>
1903+ if (app.tpe.isError) app
1904+ else tpd.cpy.Apply (app)(fn, LiftImpure .liftArgs(defs, fn.tpe, args))
1905+ case Assign (lhs, rhs) =>
1906+ tpd.cpy.Assign (app)(lhs, lift(rhs))
1907+ case Block (stats, expr) =>
1908+ tpd.cpy.Block (app)(stats, lift(expr))
1909+ }
1910+ wrapDefs(defs, lift(app))
1911+ }
19011912 }
1902- wrapDefs(defs, lift(app) )
1903- }
1913+ checkValidInfix(tree, result.symbol )
1914+ result
19041915 }
19051916
19061917 /** Translate tuples of all arities */
@@ -2153,7 +2164,7 @@ class Typer extends Namer
21532164 case tree : untpd.UnApply => typedUnApply(tree, pt)
21542165 case tree : untpd.Tuple => typedTuple(tree, pt)
21552166 case tree : untpd.DependentTypeTree => typed(untpd.TypeTree ().withSpan(tree.span), pt)
2156- case tree : untpd.InfixOp if ctx.mode.isExpr => typedInfixOp(tree, pt)
2167+ case tree : untpd.InfixOp => typedInfixOp(tree, pt)
21572168 case tree @ untpd.PostfixOp (qual, Ident (nme.WILDCARD )) => typedAsFunction(tree, pt)
21582169 case untpd.EmptyTree => tpd.EmptyTree
21592170 case tree : untpd.Quote => typedQuote(tree, pt)
0 commit comments