Skip to content

Commit

Permalink
Support def-local tracked members
Browse files Browse the repository at this point in the history
Weaken the check for legal tracked members
  • Loading branch information
KacperFKorban committed Feb 6, 2025
1 parent 9cb97ec commit f068ac3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
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)
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

0 comments on commit f068ac3

Please sign in to comment.