Skip to content

Commit 5326d34

Browse files
committed
Merge pull request scala#2761 from scalamacros/ticket/7510
Assorted toolbox fixes
2 parents 1e5bfdb + 2864c7f commit 5326d34

File tree

7 files changed

+53
-3
lines changed

7 files changed

+53
-3
lines changed

bincompat-forward.whitelist.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ filter {
511511
{
512512
matchName="scala.reflect.internal.SymbolTable.isMacroExpansionSuppressed"
513513
problemName=MissingMethodProblem
514+
},
515+
{
516+
matchName="scala.reflect.runtime.JavaMirrors#JavaMirror#FromJavaClassCompleter.scala$reflect$runtime$JavaMirrors$JavaMirror$FromJavaClassCompleter$$enterEmptyCtorIfNecessary$1"
517+
problemName=MissingMethodProblem
514518
}
515519
]
516520
}

src/reflect/scala/reflect/runtime/JavaMirrors.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,10 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
673673
val parents = try {
674674
parentsLevel += 1
675675
val jsuperclazz = jclazz.getGenericSuperclass
676-
val superclazz = if (jsuperclazz == null) AnyClass.tpe else typeToScala(jsuperclazz)
677-
superclazz :: (jclazz.getGenericInterfaces.toList map typeToScala)
676+
val ifaces = jclazz.getGenericInterfaces.toList map typeToScala
677+
val isAnnotation = (jclazz.getModifiers & JAVA_ACC_ANNOTATION) != 0
678+
if (isAnnotation) AnnotationClass.tpe :: ClassfileAnnotationClass.tpe :: ifaces
679+
else (if (jsuperclazz == null) AnyClass.tpe else typeToScala(jsuperclazz)) :: ifaces
678680
} finally {
679681
parentsLevel -= 1
680682
}
@@ -686,6 +688,11 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
686688
def enter(sym: Symbol, mods: Int) =
687689
(if (jModifier.isStatic(mods)) module.moduleClass else clazz).info.decls enter sym
688690

691+
def enterEmptyCtorIfNecessary(): Unit = {
692+
if (jclazz.getConstructors.isEmpty)
693+
clazz.info.decls.enter(clazz.newClassConstructor(NoPosition))
694+
}
695+
689696
for (jinner <- jclazz.getDeclaredClasses) {
690697
jclassAsScala(jinner) // inner class is entered as a side-effect
691698
// no need to call enter explicitly
@@ -702,6 +709,8 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
702709
for (jconstr <- jclazz.getConstructors)
703710
enter(jconstrAsScala(jconstr), jconstr.getModifiers)
704711

712+
enterEmptyCtorIfNecessary()
713+
705714
} :: pendingLoadActions
706715

707716
if (parentsLevel == 0) {

test/files/run/reflection-magicsymbols-invoke.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Array
8282
it's important to print the list of Array's members
8383
if some of them change (possibly, adding and/or removing magic symbols), we must update this test
8484
constructor Array: (_length: Int)Array[T]
85-
constructor Object: ()java.lang.Object
85+
constructor Cloneable: ()java.lang.Cloneable
8686
method !=: (x$1: Any)Boolean
8787
method !=: (x$1: AnyRef)Boolean
8888
method ##: ()Int

test/files/run/t6989.check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ isProtected = false
101101
isPublic = false
102102
privateWithin = <none>
103103
============
104+
sym = constructor $PrivateJavaClass, signature = ()JavaClass_1.this.$PrivateJavaClass, owner = class $PrivateJavaClass
105+
isPrivate = false
106+
isProtected = false
107+
isPublic = true
108+
privateWithin = <none>
109+
============
104110
sym = value this$0, signature = foo.JavaClass_1, owner = class $PrivateJavaClass
105111
isPrivate = false
106112
isProtected = false
@@ -119,6 +125,12 @@ isProtected = true
119125
isPublic = false
120126
privateWithin = package foo
121127
============
128+
sym = constructor $ProtectedJavaClass, signature = ()JavaClass_1.this.$ProtectedJavaClass, owner = class $ProtectedJavaClass
129+
isPrivate = false
130+
isProtected = false
131+
isPublic = true
132+
privateWithin = <none>
133+
============
122134
sym = value this$0, signature = foo.JavaClass_1, owner = class $ProtectedJavaClass
123135
isPrivate = false
124136
isProtected = false
@@ -173,6 +185,12 @@ isProtected = false
173185
isPublic = false
174186
privateWithin = <none>
175187
============
188+
sym = constructor PrivateStaticJavaClass, signature = ()foo.JavaClass_1.PrivateStaticJavaClass, owner = class PrivateStaticJavaClass
189+
isPrivate = false
190+
isProtected = false
191+
isPublic = true
192+
privateWithin = <none>
193+
============
176194
sym = object PrivateStaticJavaClass, signature = foo.JavaClass_1.PrivateStaticJavaClass.type, owner = object JavaClass_1
177195
isPrivate = true
178196
isProtected = false
@@ -185,6 +203,12 @@ isProtected = false
185203
isPublic = false
186204
privateWithin = <none>
187205
============
206+
sym = constructor ProtectedStaticJavaClass, signature = ()foo.JavaClass_1.ProtectedStaticJavaClass, owner = class ProtectedStaticJavaClass
207+
isPrivate = false
208+
isProtected = false
209+
isPublic = true
210+
privateWithin = <none>
211+
============
188212
sym = object ProtectedStaticJavaClass, signature = foo.JavaClass_1.ProtectedStaticJavaClass.type, owner = object JavaClass_1
189213
isPrivate = true
190214
isProtected = false

test/files/run/t7510.check

Whitespace-only changes.

test/files/run/t7510/Ann_1.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package foo;
2+
3+
public @interface Ann_1 {
4+
}

test/files/run/t7510/Test_2.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.reflect.runtime.universe._
2+
import scala.reflect.runtime.{currentMirror => cm}
3+
import scala.tools.reflect.ToolBox
4+
5+
object Test extends App {
6+
val tb = cm.mkToolBox()
7+
tb.compile(tb.parse("@foo.Ann_1 class C"))
8+
}
9+

0 commit comments

Comments
 (0)