summaryrefslogtreecommitdiff
path: root/test/files/jvm/innerClassAttribute/Classes_1.scala
blob: 27f01a880a7fdf48afd45769d4c6e52c2a054e5f (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
class A1 {
  class B
}

class A2 {
  object B
}

object A3 {
  class B1
  object B2
}

class A4 {
  def f(l: List[String]): List[String] = {
    l map (_ + "1") : @noinline // inlining adds a reference to the nested class scala/collection/generic/GenTraversableFactory$GenericCanBuildFrom
  }
}

class A5 {
  def f(): Object = {
    object B
    B
  }
}

trait A6 {
  def hui = -6
  trait TT
}

class A7 extends A6

abstract class A8 extends A6 {
  def fish: TT
}

class A9 {
  class brick extends annotation.StaticAnnotation
}

class A10 {
  val a9 = new A9()
  // there's no reference to brick in the bytecode (only in the pickle), so there's no InnerClass attribute for it.
  @a9.brick def f = -7
}

class A11 {
  @JavaAnnot_1.Ann def f = -8
}

object A12 {
  object B {
    class C
  }
}

class A13 {
  def oak: A12.B.C = new A12.B.C
}

class A14 {
  def f = {
    val x: Object = {
      class K
      new K
    }
    x
  }
  def g = {
    val x: Object = new A6 { }
  }
}

object A15 {
  def f = {
    class B { // non-static, even though it doesn't have an outer pointer
      class C // non-static
    }
  }
}

class A16 {
  val x: A6 = {
    class U extends A6
    new A6 { }
  }

  {
    class V extends A6
    new A6 { }
  }

  new A6 { }
}

class A17 {
  object B {
    class C // not static, also has an outer pointer.
  }
}

class A18 {
  def f = {
    def g = {
      class A
      new A6 { }
      val y = {
        if ((new Object).hashCode() == 1) {class B {} ; new B} else 2
        if ((new Object).hashCode() == 1) new A6 { } else "haifish"
      }
    }
  }
}

class A19 {
  ((x: String) => x + "3")

  val x = {
    ((x: String) => x + "1")
  }

  {
    ((x: String) => x + "2")
  }
}

class A20 {
  (s: String) => {
    {(s: String) => ()}
    {(s: String) => (s: String) => 1}
  }
}

class A21 {
  class I1
  def f = { class J1 }
}
object A21 {
  class I2
  object I3 {
    class J2  // static
  }
  def g = { class J3 } // non-static
  val x = { class J4 } // non-static
  {
    class J5 // non-static (!)
    new J5
  }
}

class A22 {
  class C
  object C {
    class D // inner class of C$, not of C. Not added to the inner class table of C, only to C$
  }
}

class A23 {
  def f = {
    val a = new Java_A_1()
    val c = new Java_A_1.C()
    val d = new Java_A_1.C.D()
    val e = new c.E()
    val f = new a.F()
    val g = new f.G()
  }
}

trait A24Sym

trait A24Base {
  // trait with concrete members: interface plus (absract) impl class
  trait DefinitionsApi {
    def Abs: A24Sym
    def Conc: A24Sym = new A24Sym { }
  }
}

trait A24 extends A24Base {
  class DefinitionsClass extends DefinitionsApi {
    // bridge methods are generated for Abs and Conc. there used to be a bug: the bridge symbol was a ModuleSymbol,
    // calling companionClass would return NoSymbol. i changed erasure to make the bridge symbol is a MethodSymbol.
    object Abs extends A24Sym
    override object Conc extends A24Sym
  }
}

class SI_9105 {
                                       //      outerClass       enclMeth
  val fun = (s: String) => {
    class A                            //        SI_9105           null
    def m: Object = { class B; new B } //        SI_9105            m$1
    val f: Object = { class C; new C } //        SI_9105           null
  }
  def met = (s: String) => {
    class D                            //        SI_9105            met
    def m: Object = { class E; new E } //        SI_9105            m$1
    val f: Object = { class F; new F } //        SI_9105            met
  }

  def byName(op: => Any) = 0

  val bnV = byName {
    class G                            //        SI_9105           null
    def m: Object = { class H; new H } //        SI_9105            m$1
    val f: Object = { class I; new I } //        SI_9105           null
    ""
  }
  def bnM = byName {
    class J                            //        SI_9105            bnM
    def m: Object = { class K; new K } //        SI_9105            m$1
    val f: Object = { class L; new L } //        SI_9105            bnM
    ""
  }
}

trait SI_9124 {
  trait A // member class, no enclosing method attribute

  new A { def f1 = 0 } // nested class, enclosing class SI_9124, no encl meth

  def f = new A { def f2 = 0 } // enclosing method is f in the interface SI_9124

  private def g: Object = new A { def f3 = 0 } // only encl class (SI_9124), encl meth can be g in 2.12 because the interface SI_9124 now has the method g

  object O { // member, no encl meth attribute
    new A { def f4 = 0 } // enclosing class is O$, no enclosing method
  }

          val f1 = { new A { def f5 = 0 }; 1 } // encl class SI_9124, no encl meth
  private val f2 = { new A { def f6 = 0 }; 1 } // like above
}

trait ImplClassesAreTopLevel {
  // all impl classes are top-level, so they don't appear in any InnerClass entry, and none of them have an EnclosingMethod attr
  trait B1 { def f = 1 }
  { trait B2 { def f = 1 }; new B2 {} }
  val m = {
    trait B3 { def f = 1 }
    new B3 {}
  }
  def n = {
    trait B4 { def f = 1 }
    new B4 {}
  }
}

class SpecializedClassesAreTopLevel {
  // all specialized classes are top-level
  class A[@specialized(Int) T]; new A[Int]

  object T {
    class B[@specialized(Int) T]; new B[Int]
  }

  // these crash the compiler, SI-7625

  // { class B[@specialized(Int) T]; new B[Int] }

  // val m: Object = {
  //   class C[@specialized(Int) T]
  //   new C[Int]
  // }

  // def n: Object = {
  //   class D[@specialized(Int) T]
  //   new D[Int]
  // }
}

object AnonymousClassesMayBeNestedInSpecialized {
  abstract class A
  class C[@specialized(Int) T] {
    def foo(t: T): A = new A { }
  }

  // specialization duplicates the anonymous class, one copy is nested in the specialized subclass of C

  // class C$mcI$sp extends C[Int] {
  //   override def foo(t: Int): A = C$mcI$sp.this.foo$mcI$sp(t);
  //   override def foo$mcI$sp(t: Int): A = {
  //     final class $anon extends A { }
  //     new <$anon: A>()
  //   }
  // }
}

object NestedInValueClass {
  // note that we can only test anonymous functions, nested classes are not allowed inside value classes
  class A(val arg: String) extends AnyVal {
    // A has InnerClass entries for the two closures (and for A and A$). not for B / C
    def f = {
      def g = List().map(x => ((s: String) => x)): @noinline // outer class A, no outer method (g is moved to the companion, doesn't exist in A)
      g.map(x => ((s: String) => x)): @noinline              // outer class A, outer method f
    }
    // statements and field declarations are not allowed in value classes
  }

  object A {
    // A$ has InnerClass entries for B, C, A, A$. Also for the closures above, because they are referenced in A$'s bytecode.
    class B // member class of A$
    def f = { class C; new C } // outer class A$, outer method f
  }
}

object LocalAndAnonymousInLazyInitializer {
  abstract class A
  class C {
    lazy val a: A = new A { }
    lazy val b: A = {
      class AA extends A
      new AA
    }
    lazy val c: A = {
      object AA extends A
      AA
    }
  }
  object O {
    lazy val a: A = new A { }
    lazy val b: A = {
      class AA extends A
      new AA
    }
    lazy val c: A = {
      object AA extends A
      AA
    }
  }
  trait T {
    lazy val a: A = new A { }
    lazy val b: A = {
      class AA extends A
      new AA
    }
    lazy val c: A = {
      object AA extends A
      AA
    }
  }
}