File: t8196.scala

package info (click to toggle)
scala 2.11.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 62,776 kB
  • sloc: java: 13,415; xml: 3,252; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (51 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import scala.reflect.runtime.{ universe => ru }

object Test extends App {
 
  trait FormTrait {

    val runtimeMirror = ru.runtimeMirror(this.getClass.getClassLoader)
    val instanceMirror = runtimeMirror.reflect(this)
    val members = instanceMirror.symbol.typeSignature.members
    def fields = members.filter(_.typeSignature <:< ru.typeOf[Int])
  }
 
  val f = () => {
 
    class Form1 extends FormTrait {
      val f1 = 5
    }
    val form1 = new Form1
 
    println(form1.fields)
 
    val form2 = new FormTrait {
      val g1 = new Form1
    }
 
    form2.g1 // comment this line in order to make the test pass
    ()
  }

  val g = () => {
    // Reported as SI-8195, same root cause
    trait Form {
 
      private val runtimeMirror = ru.runtimeMirror(this.getClass.getClassLoader)
      private val instanceMirror = runtimeMirror.reflect(this)
      private val members = instanceMirror.symbol.typeSignature.members
 
    }
 
    val f1 = new Form {
      val a = 1
    }
 
    val f2 = new Form {
      val b = f1.a
    }
  }

  f() 
  g() 
}