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 tracked members #21761

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

KacperFKorban
Copy link
Member

@KacperFKorban KacperFKorban commented Oct 14, 2024

closes #21754

Allow for the tracked modifier to be used for val members of classes and traits. tracked members and members inheriting from tracked force the type of the member (or it's overriding member) to be as exact as
possible. More precisely, it will will assign the tracked member the infered type of the rhs. For instance, consider the following definition:

trait F:
  tracked val a: Int
  tracked val b: Int

class N extends F:
  val a = 22 // a.type =:= 22
  val b: Int = 22 // b.type =:= Int
  tracked val c = 22 // c.type =:= 22

Here, the tracked modifier ensures that the type of a in N is 22 and not Int. But the type of b is N is Int since it's explicitly declared as Int. tracked members can also be immediately initialized, as in the case of c.

@KacperFKorban KacperFKorban marked this pull request as ready for review October 17, 2024 18:49
@KacperFKorban KacperFKorban requested a review from mbovel October 17, 2024 18:49
Move tracked inference logic to `inferredResultType`
@KacperFKorban KacperFKorban assigned odersky and unassigned mbovel Nov 12, 2024
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

This PR needs an update to the spec. I believe we should update docs/_docs/reference/experimenta/modularity.md and also docs/_docs/internals/syntax.md. With a spec we can better evaluate whether the implementation is correct.

internals/syntax.md describes the syntax supported by the parser, including all language imports.

@odersky odersky assigned KacperFKorban and unassigned odersky Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement tracked members
3 participants