-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
def f(x: Int): Int = x | ||
def id[T](x: T): T = x | ||
def idDependent(x: Any): x.type = x | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sounds strange, so a bit like an unused function parameter? maybe there should be a placeholder like erasedValue
or ?
for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have to be unused, though one might argue that it makes it worse 😅 BUT, the following works:
class Generic[A](val a: A)
val _: Generic(compiletime.erasedValue[Int]) = Generic(42)
val _: Generic(??? : Int) = Generic(42)
val _: Generic(43) = Generic(42)
a12b589
to
f64cc82
Compare
The CI failure seems to be the same as on |
Co-authored-by: Kacper Korban <[email protected]>
- only type applied constructor types in Typer - handle multiple parameter lists - add tests for mixed tracked and not tracked parameters
examples; Hide more implementation parts under modularity
51894ab
to
64aee9d
Compare
I've noticed during your presentation that it also works for import language.experimental.modularity
class Box[T](using tracked val value: Int)
def main =
given Int = 42
val b: Box() = Box() after typer: def main: Unit =
final lazy given val given_Int: Int = 42
val b: Box[Any]{val value: (given_Int : Int)} = new Box[Any](given_Int)() |
closes #22542
Introduce new syntax to make classes with
tracked
parameterseasier 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.
Syntax change
A
SimpleType
can now optionally be followed byParArgumentExprs
.