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

Support def-local tracked members #22538

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,10 @@ object desugar {
}

val legalTracked: Context ?=> MemberDefTest = {
case valdef @ ValDef(_, _, _) =>
val sym = valdef.symbol
!ctx.owner.exists || ctx.owner.isClass || ctx.owner.is(Case) || ctx.owner.isConstructor || valdef.mods.is(Param) || valdef.mods.is(ParamAccessor)
case valdef: ValDef if valdef.mods.is(Param) || valdef.mods.is(ParamAccessor) =>
!ctx.owner.exists || ctx.owner.isClass || ctx.owner.is(Case) || ctx.owner.isConstructor || ctx.owner.is(Synthetic) || (ctx.owner.isAllOf(Given | Method))
case valdef: ValDef =>
true
}

def checkOpaqueAlias(tree: MemberDef)(using Context): MemberDef =
Expand Down
4 changes: 0 additions & 4 deletions tests/neg/abstract-tracked.check
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@
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
3 changes: 0 additions & 3 deletions tests/neg/abstract-tracked.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ trait G:
tracked object O // error

tracked class C // error

def f =
tracked val x = 1 // error
4 changes: 0 additions & 4 deletions tests/neg/tracked.check
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
4 |class C2(tracked var x: Int) // error
| ^
| mutable variables may not be `tracked`
-- [E156] Syntax Error: tests/neg/tracked.scala:8:16 -------------------------------------------------------------------
8 | tracked val b: Int = 2 // error
| ^^^^^^^^^^^^^^^^^^^^^^
| Modifier tracked is not allowed for this definition
-- [E156] Syntax Error: tests/neg/tracked.scala:11:17 ------------------------------------------------------------------
11 | tracked object Foo // error
| ^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/tracked.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class C2(tracked var x: Int) // error

object A:
def foo(tracked a: Int) = // error
tracked val b: Int = 2 // error
tracked val b: Int = 2

object B:
tracked object Foo // error
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/tracked-val-weaker.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.language.experimental.modularity

object O:
tracked val x = 1

def Test =
tracked val x = 1
val _: 1 = O.x
val _: 1 = x
tracked val y = x
val _: x.type = y
tracked val y1 = O.x
val _: O.x.type = y1
Loading