Skip to content

Support "Applied Constructor Types" #22542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KacperFKorban opened this issue Feb 6, 2025 · 0 comments · Fixed by #22543
Closed

Support "Applied Constructor Types" #22542

KacperFKorban opened this issue Feb 6, 2025 · 0 comments · Fixed by #22543
Assignees
Labels
area:experimental:modularity Issues related to the modularity extension. itype:enhancement

Comments

@KacperFKorban
Copy link
Member

Example

Under modularity, it should be possible to have a shorter way for writing precise types of class applications (for classes with tracked parameters)

For example, it should be possible to write the following code:

import scala.language.experimental.modularity

class Box(tracked val v: Any)

val c: C(42) /* ≡ C { val v: 42 } */ = C(42)
@KacperFKorban KacperFKorban added area:experimental:modularity Issues related to the modularity extension. itype:enhancement labels Feb 6, 2025
@KacperFKorban KacperFKorban self-assigned this Feb 6, 2025
odersky pushed a commit to dotty-staging/dotty that referenced this issue May 12, 2025
closes scala#22542 

Introduce new syntax to make classes with `tracked` parameters
easier to use. The new syntax is essentially the ability to use an
application
of a class constructor as a type, we call such types applied constructor
types.

With this new feature the following example compiles correctly and the
type in
the comment is the resulting type of the applied constructor types.

```scala
import scala.language.experimental.modularity

class C(tracked val v: Any)

val c: C(42) /* C { val v: 42 } */ = C(42)
```

### Syntax change

```
SimpleType        ::=  SimpleLiteral
                    |  ‘?’ TypeBounds
---                 |  SimpleType1
+++                 |  SimpleType1 {ParArgumentExprs}
```

A `SimpleType` can now optionally be followed by `ParArgumentExprs`.

---------

Co-authored-by: Matt Bovel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:modularity Issues related to the modularity extension. itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant