File tree 3 files changed +64
-0
lines changed 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- Error: tests/init/neg/enum-desugared.scala:17:15 --------------------------------------------------------------------
2
+ 17 | Array(this.LazyErrorId, this.NoExplanationID) // error // error
3
+ | ^^^^^^^^^^^^^^^^
4
+ | Promoting the value to fully-initialized is unsafe. May only use initialized value as method arguments
5
+ |
6
+ | The unsafe promotion may cause the following problem(s):
7
+ |
8
+ | 1. Calling the external method method name may cause initialization errors. Calling trace:
9
+ | -> override def productPrefix: String = this.name() [ enum-desugared.scala:29 ]
10
+ -- Error: tests/init/neg/enum-desugared.scala:17:33 --------------------------------------------------------------------
11
+ 17 | Array(this.LazyErrorId, this.NoExplanationID) // error // error
12
+ | ^^^^^^^^^^^^^^^^^^^^
13
+ | Promoting the value to fully-initialized is unsafe. May only use initialized value as method arguments
14
+ |
15
+ | The unsafe promotion may cause the following problem(s):
16
+ |
17
+ | 1. Calling the external method method ordinal may cause initialization errors. Calling trace:
18
+ | -> def errorNumber: Int = this.ordinal() - 2 [ enum-desugared.scala:8 ]
Original file line number Diff line number Diff line change
1
+ package example
2
+
3
+ import language .`3.0-migration`
4
+
5
+ sealed abstract class ErrorMessageID ($name : String , _$ordinal : Int )
6
+ extends java.lang.Enum [ErrorMessageID ]($name, _$ordinal) with scala.reflect.Enum {
7
+
8
+ def errorNumber : Int = this .ordinal() - 2
9
+ }
10
+
11
+ object ErrorMessageID {
12
+
13
+ final val LazyErrorId = $new (0 , " LazyErrorId" )
14
+ final val NoExplanationID = $new (1 , " NoExplanationID" )
15
+
16
+ private [this ] val $values : Array [ErrorMessageID ] =
17
+ Array (this .LazyErrorId , this .NoExplanationID ) // error // error
18
+
19
+ def values : Array [ErrorMessageID ] = $values.clone()
20
+
21
+ def valueOf ($name : String ): ErrorMessageID = $name match {
22
+ case " LazyErrorId" => this .LazyErrorId
23
+ case " NoExplanationID" => this .NoExplanationID
24
+ case _ => throw new IllegalArgumentException (" enum case not found: " + $name)
25
+ }
26
+
27
+ private [this ] def $new (_$ordinal : Int , $name : String ): ErrorMessageID =
28
+ new ErrorMessageID ($name, _$ordinal) with scala.runtime.EnumValue {
29
+ override def productPrefix : String = this .name()
30
+ }
31
+
32
+ def fromOrdinal (ordinal : Int ): ErrorMessageID =
33
+ try ErrorMessageID .$values.apply(ordinal)
34
+ catch { case _ => throw new NoSuchElementException (ordinal.toString()) }
35
+ }
Original file line number Diff line number Diff line change
1
+ class Foo (x : Int ) {
2
+ var y : Int = x
3
+ case class Bar (z : Int ) extends Foo (z)
4
+ def updateY (n : Int ): Unit = {
5
+ if (y < 20 ) {
6
+ val b = new Bar (x + n)
7
+ y = b.z
8
+ }
9
+ }
10
+ updateY(5 )
11
+ }
You can’t perform that action at this time.
0 commit comments