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 #21754

Closed
KacperFKorban opened this issue Oct 11, 2024 · 0 comments · Fixed by #21761
Closed

Implement tracked members #21754

KacperFKorban opened this issue Oct 11, 2024 · 0 comments · Fixed by #21761
Assignees
Labels
area:experimental:modularity Issues related to the modularity extension. itype:enhancement

Comments

@KacperFKorban
Copy link
Member

It would be great to be able to declare abstract tracked members.

tracked members, when overridden, will keep their exact type.

e.g. the following code should compile

import scala.language.experimental.modularity
import scala.language.future

trait F:
  tracked val x: Int

object Test:
  val f = new F:
    val x = 1

  summon[f.x.type <:< 1]
@KacperFKorban KacperFKorban added itype:enhancement area:experimental:modularity Issues related to the modularity extension. labels Oct 11, 2024
@KacperFKorban KacperFKorban self-assigned this Oct 11, 2024
KacperFKorban added a commit that referenced this issue Dec 19, 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:

```scala 3
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`.

---------

Co-authored-by: Matt Bovel <[email protected]>
Co-authored-by: odersky <[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