Skip to content

Commit 73fdcb3

Browse files
bishaboshaWojciechMazur
authored andcommitted
add child to parent in completion context
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 [Cherry-picked a2bec5e]
1 parent 55861e9 commit 73fdcb3

File tree

4 files changed

+1361
-4
lines changed

4 files changed

+1361
-4
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ class Namer { typer: Typer =>
826826
else
827827
try
828828
completeInCreationContext(denot)
829-
if (denot.isCompleted) registerIfChild(denot)
829+
if (denot.isCompleted) registerIfChildInCreationContext(denot)
830830
catch
831831
case ex: CompilationUnit.SuspendException =>
832832
val completer = SuspendCompleter()
@@ -915,10 +915,12 @@ class Namer { typer: Typer =>
915915
denot.markAbsent()
916916
end invalidateIfClashingSynthetic
917917

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

924926
def register(child: Symbol, parentCls: ClassSymbol) = {
@@ -942,7 +944,7 @@ class Namer { typer: Typer =>
942944
end if
943945
}
944946

945-
/** Intentionally left without `implicit ctx` parameter. We need
947+
/** Intentionally left without `using Context` parameter. We need
946948
* to pick up the context at the point where the completer was created.
947949
*/
948950
def completeInCreationContext(denot: SymDenotation): Unit = {

tests/pos/i21154/A.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Z.*
2+
3+
object A:
4+
val a: Option[AOptions] = ???
5+
val b: Option[BOptions] = ???
6+
val c: Option[COptions] = ???

tests/pos/i21154/Z.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Ytest-pickler-check
2+
3+
// in the original issue https://github.com/scala/scala3/issues/21154, the non-deterministic tasty
4+
// depends on the order of compilation of files, the use-site (A.scala) has to come first,
5+
// and the file defining the enum has to come second (Z.scala), A.scala in namer will force Z to complete.
6+
enum Z:
7+
case AOptions()
8+
case BOptions()
9+
case COptions()

0 commit comments

Comments
 (0)