summaryrefslogtreecommitdiff
path: root/test/files/neg/t6666.scala
blob: d37ffaf1416840aedeb241d9d9eb93935ec6feff (plain) (blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class C(a: Any)
object F {
  def byname(a: => Any) = println(a)
  def hof(a: () => Any) = println(a())
}

class COkay extends C(0) {
  def this(a: Any) {
    this()
    def x = "".toString
    F.byname(x)
  }
}

//
// The thunk's apply method accesses the MODULE$
// field before it is set.
//
//   0: getstatic #23; //Field O1$.MODULE$:LO1$;
//   3: invokevirtual #26; //Method O1$.O1$$x$1:()Ljava/lang/String;
object O1 extends C({
  def x = "".toString
  F.byname(x)
})

// java.lang.NullPointerException
//   at O2$$anonfun$$init$$1.apply(<console>:11)
object O2 extends C({
  lazy val x = "".toString
  F.byname(x)
})

// java.lang.NullPointerException
//   at O3$$anonfun$$init$$1.apply(<console>:11)
object O3 extends C({
  def x = "".toString
  F.hof(() => x)
})

// Okay, the nested classes don't get an outer pointer passed,
// just an extra param for `x: String`.
object O6 extends C({
  val x = "".toString
  F.byname(x); F.hof(() => x); (new { val xx = x }.xx)
})


class C1 extends C({
  def x = "".toString
  F.byname(x)
})
class C2 extends C({
  lazy val x = "".toString
  F.byname(x)
})
class C3 extends C({
  def x = "".toString
  F.hof(() => x)
})
class C4 extends C({
  def x = "".toString
  object Nested { def xx = x}
  Nested.xx
})
class C5 extends C({
  def x = "".toString
  val y = {
    object Nested { def xx = x}
    Nested.xx
  }
})

// okay, for same reason as O6
class C6 extends C({
  val x = "".toString
  F.byname(x); F.hof(() => x); (new { val xx = x }.xx)
})

class C11(a: Any) {
  def this() = {
    this({
     def x = "".toString
      F.byname(x)
    })
  }
}

// Crashes earlier in lazyVals.
// class C12(a: Any) {
//   def this() = {
//     this({
//       lazy val x = "".toString
//       F.byname(x)
//     })
//   }
// }

class C13(a: Any) {
  def this() = {
    this({
      def x = "".toString
      F.hof(() => x)
    })
  }
}

class C14(a: Any) {
  def this() = {
    this({
      def x = "".toString
      object Nested { def xx = x}
      Nested.xx
    })
  }
}

class C15(a: Any) {
  def this() = {
    this({
      def x = "".toString
      val y = {
        object Nested { def xx = x}
        Nested.xx
      }
    })
  }
}

class COuter extends C({
  def foo = 0
  class CInner extends C({foo})
})