@@ -1874,28 +1874,39 @@ class Typer extends Namer
18741874
18751875 /** Translate infix operation expression `l op r` to
18761876 *
1877- * l.op(r) if `op` is left-associative
1877+ * l.op(r) if `op` is left-associative
18781878 * { val x = l; r.op(l) } if `op` is right-associative call-by-value and `l` is impure
18791879 * r.op(l) if `op` is right-associative call-by-name or `l` is pure
1880+ *
1881+ * Translate infix type `l op r` to `op[l, r]`
1882+ * Translate infix pattern `l op r` to `op(l, r)`
18801883 */
18811884 def typedInfixOp (tree : untpd.InfixOp , pt : Type )(implicit ctx : Context ): Tree = {
18821885 val untpd .InfixOp (l, op, r) = tree
1883- val app = typedApply(desugar.binop(l, op, r), pt)
1884- checkValidInfix(tree, app)
1885- if (untpd.isLeftAssoc(op.name)) app
1886- else {
1887- val defs = new mutable.ListBuffer [Tree ]
1888- def lift (app : Tree ): Tree = (app : @ unchecked) match {
1889- case Apply (fn, args) =>
1890- if (app.tpe.isError) app
1891- else tpd.cpy.Apply (app)(fn, LiftImpure .liftArgs(defs, fn.tpe, args))
1892- case Assign (lhs, rhs) =>
1893- tpd.cpy.Assign (app)(lhs, lift(rhs))
1894- case Block (stats, expr) =>
1895- tpd.cpy.Block (app)(stats, lift(expr))
1886+ val result =
1887+ if (ctx.mode.is(Mode .Type ))
1888+ typedAppliedTypeTree(cpy.AppliedTypeTree (tree)(op, l :: r :: Nil ))
1889+ else if (ctx.mode.is(Mode .Pattern ))
1890+ typedUnApply(cpy.Apply (tree)(op, l :: r :: Nil ), pt)
1891+ else {
1892+ val app = typedApply(desugar.binop(l, op, r), pt)
1893+ if (untpd.isLeftAssoc(op.name)) app
1894+ else {
1895+ val defs = new mutable.ListBuffer [Tree ]
1896+ def lift (app : Tree ): Tree = (app : @ unchecked) match {
1897+ case Apply (fn, args) =>
1898+ if (app.tpe.isError) app
1899+ else tpd.cpy.Apply (app)(fn, LiftImpure .liftArgs(defs, fn.tpe, args))
1900+ case Assign (lhs, rhs) =>
1901+ tpd.cpy.Assign (app)(lhs, lift(rhs))
1902+ case Block (stats, expr) =>
1903+ tpd.cpy.Block (app)(stats, lift(expr))
1904+ }
1905+ wrapDefs(defs, lift(app))
1906+ }
18961907 }
1897- wrapDefs(defs, lift(app) )
1898- }
1908+ checkValidInfix(tree, result.symbol )
1909+ result
18991910 }
19001911
19011912 /** Translate tuples of all arities */
@@ -2129,7 +2140,7 @@ class Typer extends Namer
21292140 case tree : untpd.UnApply => typedUnApply(tree, pt)
21302141 case tree : untpd.Tuple => typedTuple(tree, pt)
21312142 case tree : untpd.DependentTypeTree => typed(untpd.TypeTree ().withSpan(tree.span), pt)
2132- case tree : untpd.InfixOp if ctx.mode.isExpr => typedInfixOp(tree, pt)
2143+ case tree : untpd.InfixOp => typedInfixOp(tree, pt)
21332144 case tree @ untpd.PostfixOp (qual, Ident (nme.WILDCARD )) => typedAsFunction(tree, pt)
21342145 case untpd.EmptyTree => tpd.EmptyTree
21352146 case tree : untpd.Quote => typedQuote(tree, pt)
0 commit comments