Skip to content

Commit 1211fc0

Browse files
committed
Revert "Do not allow named self in objects"
This reverts commit ecdadc9.
1 parent 0c5e39d commit 1211fc0

File tree

10 files changed

+25
-10
lines changed

10 files changed

+25
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ object desugar {
645645
.withPos(mdef.pos.startPos)
646646
val ValDef(selfName, selfTpt, _) = impl.self
647647
val selfMods = impl.self.mods
648-
if (!selfTpt.isEmpty || selfName != nme.WILDCARD) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
648+
if (!selfTpt.isEmpty) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
649649
val clsSelf = ValDef(selfName, SingletonTypeTree(Ident(moduleName)), impl.self.rhs)
650650
.withMods(selfMods)
651651
.withPos(impl.self.pos orElse impl.pos.startPos)

compiler/src/dotty/tools/dotc/core/NameKinds.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object NameKinds {
6363
def infoString: String
6464
}
6565

66-
object SimpleNameKind extends NameKind(UTF8) {
66+
object SimpleNameKind extends NameKind(UTF8) { self =>
6767
type ThisInfo = Info
6868
val info = new Info
6969
def mkString(underlying: TermName, info: ThisInfo) = unsupported("mkString")

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,13 @@ class Namer { typer: Typer =>
954954

955955
val selfInfo =
956956
if (self.isEmpty) NoType
957-
else if (cls.is(Module)) cls.owner.thisType.select(sourceModule)
957+
else if (cls.is(Module)) {
958+
val moduleType = cls.owner.thisType select sourceModule
959+
if (self.name == nme.WILDCARD) moduleType
960+
else recordSym(
961+
ctx.newSymbol(cls, self.name, self.mods.flags, moduleType, coord = self.pos),
962+
self)
963+
}
958964
else createSymbol(self)
959965

960966
// pre-set info, so that parent types can refer to type params

compiler/test/dotty/tools/dotc/FromTastyTests.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class FromTastyTests extends ParallelTesting {
5959
"spec-super.scala",
6060
"spec-sparsearray-old.scala",
6161
"collections_1.scala",
62+
63+
// Infinite compilation
64+
"t3612.scala",
6265
)
6366
)
6467
step1.checkCompile() // Compile all files to generate the class files with tasty

tests/neg/i831.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/pickling/desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object desugar {
1111
def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second
1212
def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second
1313

14-
object caseClasses {
14+
object caseClasses { self =>
1515
trait List[+T] {
1616
def head: T
1717
def tail: List[T]

tests/pos/desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object desugar {
1111
def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second
1212
def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second
1313

14-
object caseClasses {
14+
object caseClasses { self =>
1515
trait List[+T] {
1616
def head: T
1717
def tail: List[T]

tests/pos/i831.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test { self =>
2+
def a = 5
3+
self.a
4+
}

tests/pos/t3612.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait C
2+
3+
class Outer {
4+
object O0 extends C {}
5+
object O extends C { self => }
6+
}

0 commit comments

Comments
 (0)