Skip to content

Experiment with declaration site tracked #22606

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,8 @@ object desugar {
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 typeDef: TypeDef if typeDef.isClassDef =>
true
}

def checkOpaqueAlias(tree: MemberDef)(using Context): MemberDef =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@ class Namer { typer: Typer =>
val sym = symbolOfTree(param)
sym.maybeOwner.maybeOwner.infoOrCompleter match
case info: ClassInfo
if !sym.is(Tracked) && isContextBoundWitnessWithAbstractMembers(sym, param, sym.maybeOwner.maybeOwner) =>
if !sym.is(Tracked) && (sym.info.widen.typeSymbol.is(Tracked) || isContextBoundWitnessWithAbstractMembers(sym, param, sym.maybeOwner.maybeOwner)) =>
typr.println(i"set tracked $param, $sym: ${sym.info} containing ${sym.info.memberNames(abstractTypeNameFilter).toList}")
setParamTrackedWithAccessors(sym, info)
case _ =>
Expand Down
8 changes: 0 additions & 8 deletions tests/neg/abstract-tracked.check
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
-- [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
| ^^^^^^^^^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/abstract-tracked.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import scala.language.experimental.modularity
import scala.language.future

tracked trait F // error
tracked trait F

trait G:
tracked def f: F // error

tracked object O // error

tracked class C // error
tracked class C

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 @@ -22,10 +22,6 @@
11 | tracked object Foo // error
| ^^^^^^^^^^^^^^^^^^
| Modifier tracked is not allowed for this definition
-- [E156] Syntax Error: tests/neg/tracked.scala:14:16 ------------------------------------------------------------------
14 | tracked class D // error
| ^^^^^^^^^^^^^^^
| Modifier tracked is not allowed for this definition
-- [E156] Syntax Error: tests/neg/tracked.scala:17:15 ------------------------------------------------------------------
17 | tracked type T = Int // 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 @@ -11,7 +11,7 @@ object B:
tracked object Foo // error

object C:
tracked class D // error
tracked class D

object D:
tracked type T = Int // error
Expand Down
25 changes: 25 additions & 0 deletions tests/pos/definition-site-tracked.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import scala.language.experimental.modularity

tracked trait Show[Self]:
type Out
def show(self: Self): Out

given ShowPerson: Show[Person] with
type Out = Int
def show(self: Person): Int = self.name.length

class Person(val name: String)(val showW: Show[Person]):
def show = showW.show(this)

given ShowString: Show[String] with
type Out = Double
def show(self: String): Double = self.length.toDouble

class Person1[S <: Show[String]](val name: String)(val showW: S):
def show = showW.show(name)

def Test =
val kasia = Person("Kasia")(ShowPerson)
val _: Int = kasia.show
val kasia1 = Person1("Kasia")(ShowString)
val _: Double = kasia1.show
Loading