Skip to content

Commit f068ac3

Browse files
committed
Support def-local tracked members
Weaken the check for legal tracked members
1 parent 9cb97ec commit f068ac3

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -1574,9 +1574,10 @@ object desugar {
15741574
}
15751575

15761576
val legalTracked: Context ?=> MemberDefTest = {
1577-
case valdef @ ValDef(_, _, _) =>
1578-
val sym = valdef.symbol
1579-
!ctx.owner.exists || ctx.owner.isClass || ctx.owner.is(Case) || ctx.owner.isConstructor || valdef.mods.is(Param) || valdef.mods.is(ParamAccessor)
1577+
case valdef: ValDef if valdef.mods.is(Param) || valdef.mods.is(ParamAccessor) =>
1578+
!ctx.owner.exists || ctx.owner.isClass || ctx.owner.is(Case) || ctx.owner.isConstructor || ctx.owner.is(Synthetic)
1579+
case valdef: ValDef =>
1580+
true
15801581
}
15811582

15821583
def checkOpaqueAlias(tree: MemberDef)(using Context): MemberDef =

tests/neg/abstract-tracked.check

-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@
1414
7 | tracked def f: F // error
1515
| ^^^^^^^^^^^^^^^^
1616
| Modifier tracked is not allowed for this definition
17-
-- [E156] Syntax Error: tests/neg/abstract-tracked.scala:14:14 ---------------------------------------------------------
18-
14 | tracked val x = 1 // error
19-
| ^^^^^^^^^^^^^^^^^
20-
| Modifier tracked is not allowed for this definition

tests/neg/abstract-tracked.scala

-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ trait G:
99
tracked object O // error
1010

1111
tracked class C // error
12-
13-
def f =
14-
tracked val x = 1 // error

tests/neg/tracked.check

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
4 |class C2(tracked var x: Int) // error
1515
| ^
1616
| mutable variables may not be `tracked`
17-
-- [E156] Syntax Error: tests/neg/tracked.scala:8:16 -------------------------------------------------------------------
18-
8 | tracked val b: Int = 2 // error
19-
| ^^^^^^^^^^^^^^^^^^^^^^
20-
| Modifier tracked is not allowed for this definition
2117
-- [E156] Syntax Error: tests/neg/tracked.scala:11:17 ------------------------------------------------------------------
2218
11 | tracked object Foo // error
2319
| ^^^^^^^^^^^^^^^^^^

tests/neg/tracked.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class C2(tracked var x: Int) // error
55

66
object A:
77
def foo(tracked a: Int) = // error
8-
tracked val b: Int = 2 // error
8+
tracked val b: Int = 2
99

1010
object B:
1111
tracked object Foo // error

tests/pos/tracked-val-weaker.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.language.experimental.modularity
2+
3+
object O:
4+
tracked val x = 1
5+
6+
def Test =
7+
tracked val x = 1
8+
val _: 1 = O.x
9+
val _: 1 = x
10+
tracked val y = x
11+
val _: x.type = y
12+
tracked val y1 = O.x
13+
val _: O.x.type = y1

0 commit comments

Comments
 (0)