Skip to content

Commit

Permalink
add child to parent in completion context
Browse files Browse the repository at this point in the history
This ensures that the positions of forced Child annotations
always happens in the source file of the parent class, and not in
another file that forced the completion to happen
  • Loading branch information
bishabosha committed Jul 17, 2024
1 parent 3e78238 commit 06bd788
Show file tree
Hide file tree
Showing 4 changed files with 1,361 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ class Namer { typer: Typer =>
else
try
completeInCreationContext(denot)
if (denot.isCompleted) registerIfChild(denot)
if (denot.isCompleted) registerIfChildInCreationContext(denot)
catch
case ex: CompilationUnit.SuspendException =>
val completer = SuspendCompleter()
Expand Down Expand Up @@ -937,10 +937,12 @@ class Namer { typer: Typer =>
denot.markAbsent()
end invalidateIfClashingSynthetic

/** If completed symbol is an enum value or a named class, register it as a child
/** Intentionally left without `using Context` parameter.
* This action should be performed in the context of where the completer was created.
* If completed symbol is an enum value or a named class, register it as a child
* in all direct parent classes which are sealed.
*/
def registerIfChild(denot: SymDenotation)(using Context): Unit = {
def registerIfChildInCreationContext(denot: SymDenotation): Unit = {
val sym = denot.symbol

def register(child: Symbol, parentCls: ClassSymbol) = {
Expand All @@ -964,7 +966,7 @@ class Namer { typer: Typer =>
end if
}

/** Intentionally left without `implicit ctx` parameter. We need
/** Intentionally left without `using Context` parameter. We need
* to pick up the context at the point where the completer was created.
*/
def completeInCreationContext(denot: SymDenotation): Unit = {
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i21154/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Z.*

object A:
val a: Option[AOptions] = ???
val b: Option[BOptions] = ???
val c: Option[COptions] = ???
9 changes: 9 additions & 0 deletions tests/pos/i21154/Z.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//> using options -Ytest-pickler-check

// in the original issue https://github.com/scala/scala3/issues/21154, the non-deterministic tasty
// depends on the order of compilation of files, the use-site (A.scala) has to come first,
// and the file defining the enum has to come second (Z.scala), A.scala in namer will force Z to complete.
enum Z:
case AOptions()
case BOptions()
case COptions()
Loading

0 comments on commit 06bd788

Please sign in to comment.