8000 read JEP 360 PermittedSubclasses_attribute by xuwei-k · Pull Request #9228 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

read JEP 360 PermittedSubclasses_attribute #9228

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -912,6 +912,13 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
}
in.skip(attrLen)

case tpnme.PermittedSubclassesATTR =>
// https://openjdk.java.net/jeps/360
log(s"$sym is java sealed.")
sym setFlag JAVA_SEALED
// TODO read permitted sub classes?
in.skip(attrLen)

case _ =>
in.skip(attrLen)
}
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/scala/tools/nsc/typechecker/Namers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,12 @@ trait Namers extends MethodSynthesis {
psym addChild context.owner
else
pending += ParentSealedInheritanceError(tpt, psym)

if (psym.isJavaSealed) {
// TODO Don't report error if this is a permitted subclass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔

pending += ParentSealedInheritanceError(tpt, psym)
}

if (psym.isLocalToBlock && psym.isClass && !phase.erasedTypes)
psym addChild context.owner
}
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/internal/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ModifierFlags {
final val JAVA_DEFAULTMETHOD = 1L << 47 // symbol is a java default method
final val JAVA_ENUM = 1L << 48 // symbol is a java enum
final val JAVA_ANNOTATION = 1L << 49 // symbol is a java annotation
final val JAVA_SEALED = 1L << 50 // symbol is a java sealed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

final val SYNTHESIZE_IMPL_IN_SUBCLASS = 1L << 50 // used in fields phase to indicate this accessor should receive an implementation in a subclass

duplicate? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Is there any difference in behavior between Java sealed and Scala sealed? If not, can we reuse the existing Sealed flag instead of adding another one?

Copy link
Member

Choose a reason for hiding this comment

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

+1 to reusing SEALED. If there is some logic that only applies to Scala sealed, we can implement this with sym.isSealed && !sym.isJava.


// Overridden.
def flagToString(flag: Long): String = ""
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/internal/HasFlags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ trait HasFlags {
def isSynthetic = hasFlag(SYNTHETIC)
def isTrait = hasFlag(TRAIT) && !hasFlag(PARAM)
def isTraitOrInterface = isTrait || isInterface
def isJavaSealed = hasFlag(JAVA_SEALED)

def flagBitsToString(bits: Long): String = {
// Fast path for common case
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/internal/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ trait StdNames {
final val SignatureATTR: NameType = nameType("Signature")
final val SourceFileATTR: NameType = nameType("SourceFile")
final val SyntheticATTR: NameType = nameType("Synthetic")
final val PermittedSubclassesATTR: NameType = nameType("PermittedSubclasses")

final val scala_ : NameType = nameType("scala")

Expand Down
0