Skip to content

Do not allow named self in objects #4118

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

Merged
merged 1 commit into from
Mar 15, 2018
Merged
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: 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) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
if (!selfTpt.isEmpty || selfName != nme.WILDCARD) 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) { self =>
object SimpleNameKind extends NameKind(UTF8) {
type ThisInfo = Info
val info = new Info
def mkString(underlying: TermName, info: ThisInfo) = unsupported("mkString")
Expand Down
8 changes: 1 addition & 7 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +954,7 @@ class Namer { typer: Typer =>

val selfInfo =
if (self.isEmpty) NoType
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 if (cls.is(Module)) cls.owner.thisType.select(sourceModule)
else createSymbol(self)

// pre-set info, so that parent types can refer to type params
Expand Down
3 changes: 0 additions & 3 deletions compiler/test/dotty/tools/dotc/FromTastyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ 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: 4 additions & 0 deletions tests/neg/i831.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test { self => // error: objects must not have a self type
def a = 5
self.a // error: not found: self
}
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 { self =>
object caseClasses {
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 { self =>
object caseClasses {
trait List[+T] {
def head: T
def tail: List[T]
Expand Down
4 changes: 0 additions & 4 deletions tests/pos/i831.scala

This file was deleted.

6 changes: 0 additions & 6 deletions tests/pos/t3612.scala

This file was deleted.