Skip to content

Commit e68753a

Browse files
committed
Add docs and syntax change for applied constructor types
1 parent a119e08 commit e68753a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: docs/_docs/internals/syntax.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ AnnotType1 ::= SimpleType1 {Annotation}
196196
197197
SimpleType ::= SimpleLiteral SingletonTypeTree(l)
198198
| ‘?’ TypeBounds
199-
| SimpleType1
199+
| SimpleType1 {ParArgumentExprs}
200200
SimpleType1 ::= id Ident(name)
201201
| Singleton ‘.’ id Select(t, name)
202202
| Singleton ‘.’ ‘type’ SingletonTypeTree(p)

Diff for: docs/_docs/reference/experimental/modularity.md

+27
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,33 @@ LocalModifier ::= ‘tracked’
196196

197197
The (soft) `tracked` modifier is allowed as a local modifier.
198198

199+
## Applied constructor types
200+
201+
A new syntax is also introduced, to make classes with `tracked` parameters
202+
easier to use. The new syntax is essentially the ability to use an application
203+
of a class constructor as a type, we call such types applied constructor types.
204+
205+
With this new feature the following example compiles correctly and the type in
206+
the comment is the resulting type of the applied constructor types.
207+
208+
```scala
209+
import scala.language.experimental.modularity
210+
211+
class Box(tracked val v: Any)
212+
213+
val c: C(42) /* C { val v: 42 } */ = C(42)
214+
```
215+
216+
### Syntax change
217+
218+
```
219+
SimpleType ::= SimpleLiteral
220+
| ‘?’ TypeBounds
221+
--- | SimpleType1
222+
+++ | SimpleType1 {ParArgumentExprs}
223+
```
224+
225+
A `SimpleType` can now optionally be followed by `ParArgumentExprs`.
199226

200227
## Allow Class Parents to be Refined Types
201228

0 commit comments

Comments
 (0)