Skip to content
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

Implement applied constructor types #22543

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

KacperFKorban
Copy link
Member

@KacperFKorban KacperFKorban commented Feb 6, 2025

closes #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.

import scala.language.experimental.modularity

class Box(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.

docs/_docs/reference/experimental/modularity.md Outdated Show resolved Hide resolved
def f(x: Int): Int = x
def id[T](x: T): T = x
def idDependent(x: Any): x.type = x

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about constructors with mixed tracked and non-tracked parameters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests for those, but the current approach is: you have to write all parameters, but the non-tracked params won't influence the resulting type.

@KacperFKorban KacperFKorban added the release-notes Should be mentioned in the release notes label Feb 7, 2025
- only type applied constructor types in Typer
- handle multiple parameter lists
- add tests for mixed tracked and not tracked parameters
@KacperFKorban KacperFKorban force-pushed the mb/applied-constructors branch from a12b589 to f64cc82 Compare February 7, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes Should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "Applied Constructor Types"
3 participants