File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,7 @@ class OpenHashMapTest {
15
15
val m = OpenHashMap .empty[Int , Int ]
16
16
17
17
// Reflect to get the private `deleted` field's value, which should be zero.
18
-
19
- /* TODO Doesn't work, due to scala/bug#9306.
18
+ // Was broken, see scala/bug#9306.
20
19
import scala .reflect .runtime .{universe => ru }
21
20
22
21
val mirror = ru.runtimeMirror(m.getClass.getClassLoader)
@@ -27,7 +26,7 @@ class OpenHashMapTest {
27
26
.head.asTerm
28
27
29
28
val fieldMirror = mirror.reflect(m).reflectField(termSym)
30
- */
29
+
31
30
// Use Java reflection instead for now.
32
31
val field =
33
32
try { // Name may or not be mangled, depending on what the compiler authors are doing.
@@ -43,7 +42,7 @@ class OpenHashMapTest {
43
42
assertEquals(1 , field.getInt(m))
44
43
45
44
m.put(0 , 0 ) // Add an entry with the same key
46
- // TODO assertEquals(0, fieldMirror.get.asInstanceOf[Int])
45
+ assertEquals(0 , fieldMirror.get.asInstanceOf [Int ])
47
46
assertEquals(0 , field.getInt(m))
48
47
}
49
48
Original file line number Diff line number Diff line change
1
+ package scala .reflect
2
+
3
+ import org .junit .Assert ._
4
+ import org .junit .Ignore
5
+ import org .junit .Test
6
+
7
+ class FieldAccessTest {
8
+
9
+ class TestClass {
10
+ private val x = 123
11
+ // Uncommenting the following line would make the test fail
12
+ () => x
13
+ }
14
+
15
+ /** scala/bug#9306 */
16
+ @ Test
17
+ def testFieldAccess (): Unit = {
18
+ import scala .reflect .runtime .{universe => ru }
19
+ import scala .reflect .runtime .currentMirror
20
+ val obj = new TestClass
21
+ val objType = currentMirror.reflect(obj).symbol.toType
22
+ val objFields = objType.members.collect { case ms : ru.MethodSymbol if ms.isGetter => ms }
23
+ assertEquals(123 , currentMirror.reflect(obj).reflectField(objFields.head).get)
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments