Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ba3d04

Browse files
committed
Merge pull request scala#2536 from adriaanm/ticket-7359
[backport scala#1727] SI-7359 cyclic nested java class
2 parents 2a5abf7 + 7f9feba commit 3ba3d04

File tree

6 files changed

+32
-81
lines changed

6 files changed

+32
-81
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
692692
(if (jModifier.isStatic(mods)) module.moduleClass else clazz).info.decls enter sym
693693

694694
for (jinner <- jclazz.getDeclaredClasses) {
695-
enter(jclassAsScala(jinner, clazz), jinner.getModifiers)
695+
jclassAsScala(jinner) // inner class is entered as a side-effect
696+
// no need to call enter explicitly
696697
}
697698

698699
pendingLoadActions = { () =>
@@ -1051,13 +1052,17 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
10511052
* @param jclazz The Java class
10521053
* @return A Scala class symbol that wraps all reflection info of `jclazz`
10531054
*/
1054-
private def jclassAsScala(jclazz: jClass[_]): Symbol = jclassAsScala(jclazz, sOwner(jclazz))
1055+
private def jclassAsScala(jclazz: jClass[_]): Symbol = {
1056+
val clazz = sOwner(jclazz) // sOwner called outside of closure for binary compatibility
1057+
toScala(classCache, jclazz){ (mirror, jclazz) =>
1058+
mirror.jclassAsScala(jclazz, clazz)
1059+
}
1060+
}
10551061

10561062
private def jclassAsScala(jclazz: jClass[_], owner: Symbol): ClassSymbol = {
1057-
val name = scalaSimpleName(jclazz)
1058-
val completer = (clazz: Symbol, module: Symbol) => new FromJavaClassCompleter(clazz, module, jclazz)
1059-
val (clazz, module) = createClassModule(owner, name, completer)
1060-
classCache enter (jclazz, clazz)
1063+
val name = scalaSimpleName(jclazz)
1064+
val completer = (clazz: Symbol, module: Symbol) => new FromJavaClassCompleter(clazz, module, jclazz)
1065+
val (clazz, _) = createClassModule(owner, name, completer)
10611066
clazz
10621067
}
10631068

test/files/run/t6989.check

Lines changed: 9 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,6 @@ isProtected = false
113113
isPublic = false
114114
privateWithin = <none>
115115
============
116-
sym = class $PrivateJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
117-
isPrivate = true
118-
isProtected = false
119-
isPublic = false
120-
privateWithin = <none>
121-
============
122-
sym = value this$0, signature = foo.JavaClass_1, owner = class $PrivateJavaClass
123-
isPrivate = false
124-
isProtected = false
125-
isPublic = false
126-
privateWithin = package foo
127-
============
128116
sym = class $ProtectedJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
129117
isPrivate = false
130118
isProtected = true
@@ -143,18 +131,6 @@ isProtected = false
143131
isPublic = false
144132
privateWithin = package foo
145133
============
146-
sym = class $ProtectedJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
147-
isPrivate = false
148-
isProtected = true
149-
isPublic = false
150-
privateWithin = package foo
151-
============
152-
sym = value this$0, signature = foo.JavaClass_1, owner = class $ProtectedJavaClass
153-
isPrivate = false
154-
isProtected = false
155-
isPublic = false
156-
privateWithin = package foo
157-
============
158134
sym = class $PublicJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
159135
isPrivate = false
160136
isProtected = false
@@ -179,97 +155,55 @@ isProtected = false
179155
isPublic = true
180156
privateWithin = <none>
181157
============
182-
sym = class $PublicJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
183-
isPrivate = false
184-
isProtected = false
185-
isPublic = true
186-
privateWithin = <none>
187-
============
188-
sym = constructor $PublicJavaClass, signature = (x$1: foo.JavaClass_1)JavaClass_1.this.$PublicJavaClass, owner = class $PublicJavaClass
158+
sym = constructor JavaClass_1, signature = ()foo.JavaClass_1, owner = class JavaClass_1
189159
isPrivate = false
190160
isProtected = false
191161
isPublic = true
192162
privateWithin = <none>
193163
============
194-
sym = value this$0, signature = foo.JavaClass_1, owner = class $PublicJavaClass
195-
isPrivate = false
196-
isProtected = false
197-
isPublic = false
198-
privateWithin = package foo
199-
============
200-
sym = constructor JavaClass_1, signature = ()foo.JavaClass_1, owner = class JavaClass_1
164+
sym = object JavaClass_1, signature = foo.JavaClass_1.type, owner = package foo
201165
isPrivate = false
202166
isProtected = false
203167
isPublic = true
204168
privateWithin = <none>
205169
============
206-
sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
170+
sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
207171
isPrivate = true
208172
isProtected = false
209173
isPublic = false
210174
privateWithin = <none>
211175
============
212-
sym = object PrivateStaticJavaClass, signature = JavaClass_1.this.PrivateStaticJavaClass.type, owner = class JavaClass_1
176+
sym = object PrivateStaticJavaClass, signature = foo.JavaClass_1.PrivateStaticJavaClass.type, owner = object JavaClass_1
213177
isPrivate = true
214178
isProtected = false
215179
isPublic = false
216180
privateWithin = <none>
217181
============
218-
sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
182+
sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
219183
isPrivate = true
220184
isProtected = false
221185
isPublic = false
222186
privateWithin = <none>
223187
============
224-
sym = object ProtectedStaticJavaClass, signature = JavaClass_1.this.ProtectedStaticJavaClass.type, owner = class JavaClass_1
188+
sym = object ProtectedStaticJavaClass, signature = foo.JavaClass_1.ProtectedStaticJavaClass.type, owner = object JavaClass_1
225189
isPrivate = true
226190
isProtected = false
227191
isPublic = false
228192
privateWithin = <none>
229193
============
230-
sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
231-
isPrivate = false
232-
isProtected = false
233-
isPublic = true
234-
privateWithin = <none>
235-
============
236-
sym = constructor PublicStaticJavaClass, signature = ()JavaClass_1.this.PublicStaticJavaClass, owner = class PublicStaticJavaClass
237-
isPrivate = false
238-
isProtected = false
239-
isPublic = true
240-
privateWithin = <none>
241-
============
242-
sym = object PublicStaticJavaClass, signature = JavaClass_1.this.PublicStaticJavaClass.type, owner = class JavaClass_1
194+
sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
243195
isPrivate = false
244196
isProtected = false
245197
isPublic = true
246198
privateWithin = <none>
247199
============
248-
sym = object JavaClass_1, signature = foo.JavaClass_1.type, owner = package foo
249-
isPrivate = false
250-
isProtected = false
251-
isPublic = true
252-
privateWithin = <none>
253-
============
254-
sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
255-
isPrivate = true
256-
isProtected = false
257-
isPublic = false
258-
privateWithin = <none>
259-
============
260-
sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
261-
isPrivate = true
262-
isProtected = false
263-
isPublic = false
264-
privateWithin = <none>
265-
============
266-
sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
200+
sym = constructor PublicStaticJavaClass, signature = ()foo.JavaClass_1.PublicStaticJavaClass, owner = class PublicStaticJavaClass
267201
isPrivate = false
268202
isProtected = false
269203
isPublic = true
270204
privateWithin = <none>
271205
============
272-
sym = constructor PublicStaticJavaClass, signature = ()JavaClass_1.this.PublicStaticJavaClass, owner = class PublicStaticJavaClass
206+
sym = object PublicStaticJavaClass, signature = foo.JavaClass_1.PublicStaticJavaClass.type, owner = object JavaClass_1
273207
isPrivate = false
274208
isProtected = false
275209
isPublic = true

test/files/run/t6989/JavaClass_1.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
// I'm leaving the incorrect results of FromJavaClassCompleters in the check
99
// file, so that we get notified when something changes there.
10+
// ^^^ It's not clear what those incorrect results were, but the fix for SI-7359
11+
// (backport of fix for SI-6548) has probably resolved some of these. OP, please revisit this comment.
1012

1113
class PackagePrivateJavaClass {
1214
private int privateField = 0;

test/files/run/t7359.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ok

test/files/run/t7359/Cyclic_1.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
abstract class Cyclic {
2+
static interface Inner<T extends Inner> { }
3+
}

test/files/run/t7359/Test_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.reflect.runtime.universe._
2+
3+
object Test extends App {
4+
typeOf[Cyclic].members
5+
println("ok")
6+
}

0 commit comments

Comments
 (0)