Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,7 @@ object Parsers {
* | ForExpr
* | [SimpleExpr `.'] id `=' Expr
* | PrefixOperator SimpleExpr `=' Expr
* | InfixExpr id [nl] `=' Expr -- only if language.postfixOps is enabled
* | SimpleExpr1 ArgumentExprs `=' Expr
* | PostfixExpr [Ascription]
* | ‘inline’ InfixExpr MatchClause
Expand Down Expand Up @@ -2528,7 +2529,7 @@ object Parsers {
def expr1Rest(t: Tree, location: Location): Tree =
if in.token == EQUALS then
t match
case Ident(_) | Select(_, _) | Apply(_, _) | PrefixOp(_, _) =>
case Ident(_) | Select(_, _) | Apply(_, _) | PrefixOp(_, _) | PostfixOp(_, _) =>
atSpan(startOffset(t), in.skipToken()) {
val loc = if location.inArgs then location else Location.ElseWhere
Assign(t, subPart(() => expr(loc)))
Expand Down
1 change: 1 addition & 0 deletions docs/_docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[
| ForExpr
| [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
| PrefixOperator SimpleExpr ‘=’ Expr Assign(expr, expr)
| InfixExpr id [nl] `=' Expr Assign(expr, expr) -- only if language.postfixOperators is enabled
| SimpleExpr ArgumentExprs ‘=’ Expr Assign(expr, expr)
| PostfixExpr [Ascription]
| ‘inline’ InfixExpr MatchClause
Expand Down
23 changes: 23 additions & 0 deletions tests/pos/vec-access-syntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import scala.language.postfixOps

class Vector(values: Int*) {
val data = values.toArray
class Getter(i: Int) {
def `>_=`(x: Int) =
data(i) = x
def > : Int =
data(i)
}
def < (i:Int) = new Getter(i)
override def toString = data.mkString("<", ", ", ">")
}

object Test {
def main(args: Array[String]): Unit = {
val v = new Vector(1, 2, 3)
println(v) // prints <1, 2, 3>
v<1> = 10 // assign 10 to element at index 1
println(v) // prints <1, 10, 3>
println(v<1>) // prints: value at 1 is 10
}
}
Loading