summaryrefslogtreecommitdiff
path: root/test/files/run/t9697.scala
blob: b837feb237e3f6b4999d4430c3b3680e5c45dbad (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
object log {
  val b = new collection.mutable.StringBuilder
  def apply(s: Any): Unit = b.append(s)
  def check(s: String) = {
    val bs = b.toString
    assert(s == bs, bs)
    b.clear()
  }
}

package t9697 {
  abstract class WA extends DelayedInit {
    override def delayedInit(x: => Unit): Unit = x
    val waField = "4"
  }

  class C {
    def b(s: String) = log(s)
    val cField = "1"

    {
      val dummyLocal = "2"
      new WA {
        val anonField = "3"
        b(cField)
        b(dummyLocal)
        b(anonField)
        b(waField)
      }
    }
  }
}

package sd229 {
  class Broken {
    def is(ee: AnyRef) = {
      new Delayed {
        log(ee)
      }
    }
  }

  class Delayed extends DelayedInit {
    def delayedInit(x: => Unit): Unit = x
  }
}


// already fixed in 2.11.8, crashes in 2.10.6
package t4683a {
  class A { log("a") }
  class B { log("b") }
  class Bug extends DelayedInit {
    log("bug")
    def foo(a: A): B = new B
    def delayedInit(init: => Unit): Unit = init
  }
}

// already fixed in 2.12.0-RC1, crashes in 2.11.8
package t4683b {
  class Entity extends DelayedInit {
    def delayedInit(x: => Unit): Unit = x
    
    class Field
    
    protected def EntityField[T <: Entity: reflect.ClassTag] = new Field
    
    def find[T <: Entity: reflect.ClassTag] {
      Nil.map(dbo => {
        class EntityHolder extends Entity {
          val entity = EntityField[T]
        }
      })
      log("find")
    }
  }
}

package t4683c {
  trait T extends DelayedInit {
    def delayedInit(body: => Unit) = {
      log("init")
      body
    }
  }
}

package t4683d {
  class C extends DelayedInit {
    def delayedInit(body: => Unit): Unit = body
  }
  class Injector {
    def test: Object = {
      val name = "k"
      class crash extends C {
        log(name)
      }
      new crash()
    }
  }
}

object Test extends App {
  new t9697.C()
  log.check("1234")

  new sd229.Broken().is("hi")
  log.check("hi")

  val a: t4683a.A = new t4683a.A
  var b: t4683a.B = null
  new t4683a.Bug {
    val b = foo(a)
  }
  log.check("abugb")

  new t4683b.Entity().find[t4683b.Entity]
  log.check("find")

  val f = (p1: Int) => new t4683c.T { log(p1) }
  f(5)
  log.check("init5")

  new t4683d.Injector().test
  log.check("k")
}