Skip to content

Commit f7b7188

Browse files
committed
Fix tracked modifier checks
1 parent d2b6a61 commit f7b7188

File tree

4 files changed

+22
-40
lines changed

4 files changed

+22
-40
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ object desugar {
14841484
val legalTracked: Context ?=> MemberDefTest = {
14851485
case valdef @ ValDef(_, _, _) =>
14861486
val sym = valdef.symbol
1487-
ctx.owner.exists && (ctx.owner.isClass || ctx.owner.isConstructor)
1487+
!ctx.owner.exists || ctx.owner.isClass || ctx.owner.is(Case) || ctx.owner.isConstructor || valdef.mods.is(Param) || valdef.mods.is(ParamAccessor)
14881488
}
14891489

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

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,14 +2835,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28352835
excludeDeferredGiven(rhs, sym):
28362836
typedExpr(_, tpt1.tpe.widenExpr)
28372837
setAbstractTrackedInfo(sym, rhs1, tpt)
2838-
val tpt2 = if sym.flags.is(Tracked) && tpt.isEmpty && !sym.flags.is(ParamAccessor) then TypeTree(rhs1.tpe) else tpt1
2838+
val tpt2 = if sym.flags.is(Tracked) && tpt.isEmpty && !sym.flags.is(ParamAccessor) && !sym.flags.is(Param) then TypeTree(rhs1.tpe) else tpt1
28392839
val vdef2 = assignType(cpy.ValDef(vdef)(name, tpt2, rhs1), sym)
28402840
postProcessInfo(vdef2, sym)
28412841
vdef2.setDefTree
28422842
}
28432843

28442844
private def setAbstractTrackedInfo(sym: Symbol, rhs: Tree, tpt: untpd.Tree)(using Context): Unit =
2845-
if sym.allOverriddenSymbols.exists(_.flags.is(Tracked)) && !sym.flags.is(ParamAccessor) then
2845+
if sym.allOverriddenSymbols.exists(_.flags.is(Tracked)) && !sym.flags.is(ParamAccessor) && !sym.flags.is(Param) then
28462846
sym.setFlag(Tracked)
28472847
if tpt.isEmpty then
28482848
sym.info = rhs.tpe

tests/neg/tracked.check

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@
66
7 | def foo(tracked a: Int) = // error
77
| ^
88
| ':' expected, but identifier found
9-
-- Error: tests/neg/tracked.scala:8:12 ---------------------------------------------------------------------------------
10-
8 | tracked val b: Int = 2 // error
11-
| ^^^
12-
| end of statement expected but 'val' found
13-
-- Error: tests/neg/tracked.scala:11:10 --------------------------------------------------------------------------------
14-
11 | tracked object Foo // error // error
15-
| ^^^^^^
16-
| end of statement expected but 'object' found
17-
-- Error: tests/neg/tracked.scala:14:10 --------------------------------------------------------------------------------
18-
14 | tracked class D // error // error
19-
| ^^^^^
20-
| end of statement expected but 'class' found
21-
-- Error: tests/neg/tracked.scala:17:10 --------------------------------------------------------------------------------
22-
17 | tracked type T = Int // error // error
23-
| ^^^^
24-
| end of statement expected but 'type' found
259
-- Error: tests/neg/tracked.scala:20:25 --------------------------------------------------------------------------------
2610
20 | given g2: (tracked val x: Int) => C = C(x) // error
2711
| ^^^^^^^^^^^^^^^^^^
@@ -30,21 +14,19 @@
3014
4 |class C2(tracked var x: Int) // error
3115
| ^
3216
| mutable variables may not be `tracked`
33-
-- [E006] Not Found Error: tests/neg/tracked.scala:11:2 ----------------------------------------------------------------
34-
11 | tracked object Foo // error // error
35-
| ^^^^^^^
36-
| Not found: tracked
37-
|
38-
| longer explanation available when compiling with `-explain`
39-
-- [E006] Not Found Error: tests/neg/tracked.scala:14:2 ----------------------------------------------------------------
40-
14 | tracked class D // error // error
41-
| ^^^^^^^
42-
| Not found: tracked
43-
|
44-
| longer explanation available when compiling with `-explain`
45-
-- [E006] Not Found Error: tests/neg/tracked.scala:17:2 ----------------------------------------------------------------
46-
17 | tracked type T = Int // error // error
47-
| ^^^^^^^
48-
| Not found: tracked
49-
|
50-
| longer explanation available when compiling with `-explain`
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
21+
-- [E156] Syntax Error: tests/neg/tracked.scala:11:17 ------------------------------------------------------------------
22+
11 | tracked object Foo // error
23+
| ^^^^^^^^^^^^^^^^^^
24+
| Modifier tracked is not allowed for this definition
25+
-- [E156] Syntax Error: tests/neg/tracked.scala:14:16 ------------------------------------------------------------------
26+
14 | tracked class D // error
27+
| ^^^^^^^^^^^^^^^
28+
| Modifier tracked is not allowed for this definition
29+
-- [E156] Syntax Error: tests/neg/tracked.scala:17:15 ------------------------------------------------------------------
30+
17 | tracked type T = Int // error
31+
| ^^^^^^^^^^^^^^^^^^^^
32+
| Modifier tracked is not allowed for this definition

tests/neg/tracked.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ object A:
88
tracked val b: Int = 2 // error
99

1010
object B:
11-
tracked object Foo // error // error
11+
tracked object Foo // error
1212

1313
object C:
14-
tracked class D // error // error
14+
tracked class D // error
1515

1616
object D:
17-
tracked type T = Int // error // error
17+
tracked type T = Int // error
1818

1919
object E:
2020
given g2: (tracked val x: Int) => C = C(x) // error

0 commit comments

Comments
 (0)