Skip to content
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

Work around lampepfl/dotty#19019: patch the SelfDef of inner module classes. #395

Merged
merged 1 commit into from
Nov 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,17 @@ private[tasties] class TreeUnpickler private (
case _ => readTypeTree
}
}
val self = readSelf

val self0 = readSelf
val self = self0 match
case Some(orig @ SelfDef(name, tpt)) if cls.name.isObjectClassTypeName && cls.owner.isClass =>
// Work around https://github.com/lampepfl/dotty/issues/19019: replace with a correct SELFDEF
val owner = cls.owner.asClass
val fixedTpt = TypeWrapper(TermRef(owner.thisType, cls.name.sourceObjectName))(orig.pos)
Some(SelfDef(name, fixedTpt)(orig.pos))
case _ =>
self0

cls.withGivenSelfType(self.map(_.tpt.toType))
// The first entry is the constructor
val cstr = readStat.asInstanceOf[DefDef]
Expand Down
43 changes: 43 additions & 0 deletions test-sources/src/main/scala/simple_trees/ObjectWithSelf.scala
adpi2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package simple_trees

object ObjectWithSelf:
object StaticObjectNoSelf:
def foo: Any = this
def bar: Any = this.foo
end StaticObjectNoSelf

object StaticObjectWithSelf:
self =>

def foo: Any = self
def bar: Any = self.foo
end StaticObjectWithSelf

class Container:
object NonStaticObjectNoSelf:
def foo: Any = this
def bar: Any = this.foo
end NonStaticObjectNoSelf

object NonStaticObjectWithSelf:
self =>

def foo: Any = self
def bar: Any = self.foo // used to cause StackOverflow while resolving this in WholeClasspathSuite tests
end NonStaticObjectWithSelf
end Container

def methodOwner(): Unit =
object LocalObjectNoSelf:
def foo: Any = this
def bar: Any = this.foo
end LocalObjectNoSelf

object LocalObjectWithSelf:
self =>

def foo: Any = self
def bar: Any = self.foo
end LocalObjectWithSelf
end methodOwner
end ObjectWithSelf