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

Conversation

xuwei-k
Copy link
Contributor
@xuwei-k xuwei-k commented Sep 30, 2020

(partially?) fix 12171 🤔

scala/bug#12171

How to add tests? 🤔

I have tested manually

# use JDK 8

sbt dist/mkPack

# switch to JDK 15

$ mkdir tmp
# cd tmp

# create test source files

$ cat A.java
public sealed class A{}

final class B extends A{}

$ cat C.scala 
class C extends A


$ javac --enable-preview --release 15 A.java && ../build/pack/bin/scalac C.scala -classpath .
ノート:A.javaはプレビュー言語機能を使用します。
ノート:詳細は、-Xlint:previewオプションを指定して再コンパイルしてください。
C.scala:1: error: illegal inheritance from sealed class A
class C extends A
                ^
1 error

@scala-jenkins scala-jenkins added this to the 2.13.4 milestone Sep 30, 2020
@@ -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? 🤔

@@ -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.

🤔

@@ -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
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.

@retronym
Copy link
Member

We can test without needed a hard dependency on JDK15 by building using ASM to write out the same classes that javac 15 would write. See test/files/run/t7741a/GroovyInterface$1Dump.java for an example of how we use this to test interop with Groovy.

@SethTisue
Copy link
Member

@xuwei-k interested in continuing work on this...?

@dwijnand
Copy link
Member

This needs a lot more work, and it is something that we ultimately want supported in our Java parser. But we'll close this PR for now, for inactivity. We can reopen if interest returns, or someone can resubmit change.

@dwijnand dwijnand closed this Jan 15, 2021
@SethTisue SethTisue removed this from the 2.13.5 milestone Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0