Skip to content

Commit

Permalink
Revert "Do not allow named self in objects"
Browse files Browse the repository at this point in the history
This reverts commit ecdadc9.
  • Loading branch information
odersky committed Mar 22, 2018
1 parent 0c5e39d commit 1211fc0
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ object desugar {
.withPos(mdef.pos.startPos)
val ValDef(selfName, selfTpt, _) = impl.self
val selfMods = impl.self.mods
if (!selfTpt.isEmpty || selfName != nme.WILDCARD) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
if (!selfTpt.isEmpty) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
val clsSelf = ValDef(selfName, SingletonTypeTree(Ident(moduleName)), impl.self.rhs)
.withMods(selfMods)
.withPos(impl.self.pos orElse impl.pos.startPos)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object NameKinds {
def infoString: String
}

object SimpleNameKind extends NameKind(UTF8) {
object SimpleNameKind extends NameKind(UTF8) { self =>
type ThisInfo = Info
val info = new Info
def mkString(underlying: TermName, info: ThisInfo) = unsupported("mkString")
Expand Down
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,13 @@ class Namer { typer: Typer =>

val selfInfo =
if (self.isEmpty) NoType
else if (cls.is(Module)) cls.owner.thisType.select(sourceModule)
else if (cls.is(Module)) {
val moduleType = cls.owner.thisType select sourceModule
if (self.name == nme.WILDCARD) moduleType
else recordSym(
ctx.newSymbol(cls, self.name, self.mods.flags, moduleType, coord = self.pos),
self)
}
else createSymbol(self)

// pre-set info, so that parent types can refer to type params
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotty/tools/dotc/FromTastyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class FromTastyTests extends ParallelTesting {
"spec-super.scala",
"spec-sparsearray-old.scala",
"collections_1.scala",

// Infinite compilation
"t3612.scala",
)
)
step1.checkCompile() // Compile all files to generate the class files with tasty
Expand Down
2 changes: 1 addition & 1 deletion scala2-library
4 changes: 0 additions & 4 deletions tests/neg/i831.scala

This file was deleted.

2 changes: 1 addition & 1 deletion tests/pickling/desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object desugar {
def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second
def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second

object caseClasses {
object caseClasses { self =>
trait List[+T] {
def head: T
def tail: List[T]
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object desugar {
def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second
def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second

object caseClasses {
object caseClasses { self =>
trait List[+T] {
def head: T
def tail: List[T]
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i831.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test { self =>
def a = 5
self.a
}
6 changes: 6 additions & 0 deletions tests/pos/t3612.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait C

class Outer {
object O0 extends C {}
object O extends C { self => }
}

0 comments on commit 1211fc0

Please sign in to comment.