-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
4b7f321
commit 0041987
Showing
15 changed files
with
198 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
trait F: | ||
tracked val a: Int | ||
|
||
class G: | ||
val a: Int = 1 | ||
|
||
def Test = | ||
val g = new G | ||
summon[g.a.type <:< 1] // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- [E156] Syntax Error: tests/neg/abstract-tracked.scala:4:14 ---------------------------------------------------------- | ||
4 |tracked trait F // error | ||
|^^^^^^^^^^^^^^^ | ||
|Modifier tracked is not allowed for this definition | ||
-- [E156] Syntax Error: tests/neg/abstract-tracked.scala:9:15 ---------------------------------------------------------- | ||
9 |tracked object O // error | ||
|^^^^^^^^^^^^^^^^ | ||
|Modifier tracked is not allowed for this definition | ||
-- [E156] Syntax Error: tests/neg/abstract-tracked.scala:11:14 --------------------------------------------------------- | ||
11 |tracked class C // error | ||
|^^^^^^^^^^^^^^^ | ||
|Modifier tracked is not allowed for this definition | ||
-- [E156] Syntax Error: tests/neg/abstract-tracked.scala:7:14 ---------------------------------------------------------- | ||
7 | tracked def f: F // error | ||
| ^^^^^^^^^^^^^^^^ | ||
| Modifier tracked is not allowed for this definition | ||
-- [E156] Syntax Error: tests/neg/abstract-tracked.scala:14:14 --------------------------------------------------------- | ||
14 | tracked val x = 1 // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| Modifier tracked is not allowed for this definition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
tracked trait F // error | ||
|
||
trait G: | ||
tracked def f: F // error | ||
|
||
tracked object O // error | ||
|
||
tracked class C // error | ||
|
||
def f = | ||
tracked val x = 1 // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.