Commit 6648126
fix: allow postfix setters under language.postfixOps (scala#23775)
Allow for postfix operators to be followed by assigns.
This enables the definition and use of the following syntax (more
precisely the parsing of the `>_=` method as a `postfix operator +
assign`):
```scala
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
// Definition of Vector:
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("<", ", ", ">")
}
```
[Cherry-picked de18af4]1 parent 3a156a7 commit 6648126
File tree
4 files changed
+27
-1
lines changed- compiler/src/dotty/tools/dotc/parsing
- docs/_docs
- internals
- reference
- tests/pos
4 files changed
+27
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2179 | 2179 | | |
2180 | 2180 | | |
2181 | 2181 | | |
| 2182 | + | |
2182 | 2183 | | |
2183 | 2184 | | |
2184 | 2185 | | |
| |||
2339 | 2340 | | |
2340 | 2341 | | |
2341 | 2342 | | |
2342 | | - | |
| 2343 | + | |
2343 | 2344 | | |
2344 | 2345 | | |
2345 | 2346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
243 | 244 | | |
244 | 245 | | |
245 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
243 | 244 | | |
244 | 245 | | |
245 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments