Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

space: Fix how sealed abstract classes decompose #15553

Merged

Conversation

dwijnand
Copy link
Member

No description provided.

@dwijnand dwijnand linked an issue Jun 29, 2022 that may be closed by this pull request
@dwijnand dwijnand marked this pull request as ready for review June 30, 2022 07:14
@dwijnand dwijnand requested a review from anatoliykmetyuk June 30, 2022 07:16
@dwijnand
Copy link
Member Author

Me: "Hmm, GitHub won't suggest a reviewer, let me find the author so I can request them." "Ah, I'm the author, that's why." #14599 😄

@@ -631,7 +631,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
case tp =>
def getChildren(sym: Symbol): List[Symbol] =
sym.children.flatMap { child =>
if child eq sym then Nil // i3145: sealed trait Baz, val x = new Baz {}, Baz.children returns Baz...
if child eq sym then List(sym) // i3145: sealed trait Baz, val x = new Baz {}, Baz.children returns Baz...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sealed trait Baz, val x = new Baz {}, Baz.children returns Baz

Which exactly Baz in Baz.children are we talking about here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a joke question 😄 . Describing a full, legal, source file:

sealed trait Baz
object Baz:
  val inst = new Baz {}

Then there are 3 classes: Baz, the interface, Baz$, the module class, and Baz$$anon$1, the anonymous subclass of Baz:

$ javap Baz.class
Compiled from "Test.scala"
public interface Baz {
  public static Baz inst();
}
$ javap Baz\$.class
Compiled from "Test.scala"
public final class Baz$ implements java.io.Serializable {
  public static final Baz$ MODULE$;
  public static {};
  public Baz inst();
}
$ javap Baz\$\$anon\$1.class
Compiled from "Test.scala"
public final class Baz$$anon$1 implements Baz {
  public Baz$$anon$1();
}

So when you look up the sealed children of Baz, then Baz itself is returned, as a representative of the anonymous subclass.

@anatoliykmetyuk anatoliykmetyuk merged commit 18f2c0e into scala:main Jul 8, 2022
@dwijnand dwijnand deleted the space/sealed-abstracts-redundancy branch July 8, 2022 15:39
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.1.3 regression: spurious unreachable warning
3 participants