Commit fafb5c1
fix: allow postfix setters under language.postfixOps (#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 f162878 commit fafb5c1
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 | |
|---|---|---|---|
| |||
2370 | 2370 | | |
2371 | 2371 | | |
2372 | 2372 | | |
| 2373 | + | |
2373 | 2374 | | |
2374 | 2375 | | |
2375 | 2376 | | |
| |||
2525 | 2526 | | |
2526 | 2527 | | |
2527 | 2528 | | |
2528 | | - | |
| 2529 | + | |
2529 | 2530 | | |
2530 | 2531 | | |
2531 | 2532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
264 | 265 | | |
265 | 266 | | |
266 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
| |||
| 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