Skip to content

Commit 5f86ca0

Browse files
committed
Handle right-associative extension operators
1 parent 4c4c1e8 commit 5f86ca0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,20 @@ abstract class Positioned extends Product {
208208
// Leave out tparams, they are copied with wrong positions from parent class
209209
check(tree.mods)
210210
check(tree.vparamss)
211-
case tree: DefDef if tree.mods.is(Extension) && tree.vparamss.nonEmpty =>
212-
check(tree.vparamss.head)
213-
check(tree.tparams)
214-
check(tree.vparamss.tail)
211+
case tree: DefDef if tree.mods.is(Extension) =>
212+
tree.vparamss match {
213+
case vparams1 :: vparams2 :: rest if !isLeftAssoc(tree.name) =>
214+
check(vparams2)
215+
check(tree.tparams)
216+
check(vparams1)
217+
check(rest)
218+
case vparams1 :: rest =>
219+
check(vparams1)
220+
check(tree.tparams)
221+
check(rest)
222+
case _ =>
223+
check(tree.tparams)
224+
}
215225
check(tree.tpt)
216226
check(tree.rhs)
217227
case _ =>

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,12 @@ object Parsers {
22592259
val mods1 = addFlag(mods, flags)
22602260
val name = ident()
22612261
val tparams = typeParamClauseOpt(ParamOwner.Def)
2262-
val vparamss = leadingParamss ::: paramClauses(ofMethod = true)
2262+
val vparamss = paramClauses(ofMethod = true) match {
2263+
case rparams :: rparamss if leadingParamss.nonEmpty && !isLeftAssoc(name) =>
2264+
rparams :: leadingParamss ::: rparamss
2265+
case rparamss =>
2266+
leadingParamss ::: rparamss
2267+
}
22632268
var tpt = fromWithinReturnType {
22642269
if (in.token == SUBTYPE && mods.is(Inline)) {
22652270
in.nextToken()

0 commit comments

Comments
 (0)