Skip to content

Commit 0e6e63a

Browse files
committed
Describe and add tests for source incompabilities
1 parent cb9ba23 commit 0e6e63a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs/_docs/reference/experimental/named-tuples.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,24 @@ This revives SIP 43, with a much simpler desugaring than originally proposed.
174174
Named patterns are compatible with extensible pattern matching simply because
175175
`unapply` results can be named tuples.
176176

177+
### Source Incompatibilities
178+
179+
There are some source incompatibilities involving named tuples of length one.
180+
First, what was previously classified as an assignment could now be interpreted as a named tuple. Example:
181+
```scala
182+
var age: Int
183+
(age = 1)
184+
```
185+
This was an assignment in parentheses before, and is a named tuple of arity one now. It is however not idiomatic Scala code, since assignments are not usually enclosed in parentheses.
186+
187+
Second, what was a named argument to an infix operator can now be interpreted as a named tuple.
188+
```scala
189+
class C:
190+
infix def f(age: Int)
191+
val c: C
192+
```
193+
then
194+
```scala
195+
c f (age = 1)
196+
```
197+
will now construct a tuple as second operand instead of passing a named parameter.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import language.experimental.namedTuples
2+
var age = 22
3+
val x = (age = 1)
4+
val _: (age: Int) = x
5+
val x2 = {age = 1}
6+
val _: Unit = x2
7+
8+
class C:
9+
infix def id[T](age: T): T = age
10+
11+
def test =
12+
val c: C = ???
13+
val y = c id (age = 1)
14+
val _: (age: Int) = y
15+
val y2 = c.id(age = 1)
16+
val _: Int = y2
17+

0 commit comments

Comments
 (0)