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

[backport] Avoid overeager completion of Java annotations in classfile parser #15277

Merged
merged 1 commit into from
May 24, 2022
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: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,6 @@ class Definitions {
@tu lazy val ScalaStrictFPAnnot: ClassSymbol = requiredClass("scala.annotation.strictfp")
@tu lazy val ScalaStaticAnnot: ClassSymbol = requiredClass("scala.annotation.static")
@tu lazy val SerialVersionUIDAnnot: ClassSymbol = requiredClass("scala.SerialVersionUID")
@tu lazy val TASTYSignatureAnnot: ClassSymbol = requiredClass("scala.annotation.internal.TASTYSignature")
@tu lazy val TASTYLongSignatureAnnot: ClassSymbol = requiredClass("scala.annotation.internal.TASTYLongSignature")
@tu lazy val TailrecAnnot: ClassSymbol = requiredClass("scala.annotation.tailrec")
@tu lazy val ThreadUnsafeAnnot: ClassSymbol = requiredClass("scala.annotation.threadUnsafe")
@tu lazy val ConstructorOnlyAnnot: ClassSymbol = requiredClass("scala.annotation.constructorOnly")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ class ClassfileParser(

/** Parse inner classes. Expects `in.bp` to point to the superclass entry.
* Restores the old `bp`.
* @return true iff classfile is from Scala, so no Java info needs to be read.
* @return Some(unpickler) iff classfile is from Scala, so no Java info needs to be read.
*/
def unpickleOrParseInnerClasses()(using ctx: Context, in: DataReader): Option[Embedded] = {
val oldbp = in.bp
Expand Down Expand Up @@ -1028,7 +1028,7 @@ class ClassfileParser(
// attribute isn't, this classfile is a compilation artifact.
return Some(NoEmbedded)

if (scan(tpnme.RuntimeVisibleAnnotationATTR) || scan(tpnme.RuntimeInvisibleAnnotationATTR)) {
if (scan(tpnme.ScalaSignatureATTR) && scan(tpnme.RuntimeVisibleAnnotationATTR)) {
val attrLen = in.nextInt
val nAnnots = in.nextChar
var i = 0
Expand All @@ -1039,14 +1039,10 @@ class ClassfileParser(
while (j < nArgs) {
val argName = pool.getName(in.nextChar)
if (argName.name == nme.bytes) {
if (attrClass == defn.ScalaSignatureAnnot)
if attrClass == defn.ScalaSignatureAnnot then
return unpickleScala(parseScalaSigBytes)
else if (attrClass == defn.ScalaLongSignatureAnnot)
else if attrClass == defn.ScalaLongSignatureAnnot then
return unpickleScala(parseScalaLongSigBytes)
else if (attrClass == defn.TASTYSignatureAnnot)
return unpickleTASTY(parseScalaSigBytes)
else if (attrClass == defn.TASTYLongSignatureAnnot)
return unpickleTASTY(parseScalaLongSigBytes)
}
parseAnnotArg(skip = true)
j += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated
public @interface TASTYLongSignature {
public String[] bytes();
}
1 change: 1 addition & 0 deletions library/src/scala/annotation/internal/TASTYSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Deprecated
public @interface TASTYSignature {
public String bytes();
}
8 changes: 8 additions & 0 deletions tests/pos/i15166/InterfaceAudience_JAVA_ONLY_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@InterfaceStability_JAVA_ONLY_1.Evolving(bytes="no")
public class InterfaceAudience_JAVA_ONLY_1 {
@Retention(RetentionPolicy.RUNTIME)
public @interface Public { String bytes(); }
}
8 changes: 8 additions & 0 deletions tests/pos/i15166/InterfaceStability_JAVA_ONLY_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@InterfaceAudience_JAVA_ONLY_1.Public(bytes="yes")
public class InterfaceStability_JAVA_ONLY_1 {
@Retention(RetentionPolicy.RUNTIME)
public @interface Evolving { String bytes(); }
}
4 changes: 4 additions & 0 deletions tests/pos/i15166/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// scalac: -Xfatal-warnings
object Test {
val x: InterfaceAudience_JAVA_ONLY_1.Public = ???
}