Skip to content

Conversation

@liufengyun
Copy link
Contributor

The field elemSeparator and caseSeparator are used before they are initialized.

-- Error: tests/run/typeclass-derivation2a.scala:31:22 -------------------------
31 |    private final val elemSeparator = '\000'
   |                      ^
   |Access non-initialized field value elemSeparator. Calling trace:
   | -> initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])	[ typeclass-derivation2a.scala:29 ]
   |  -> else if (labelsStr(cur) == elemSeparator)	[ typeclass-derivation2a.scala:43 ]

-- Error: tests/run/typeclass-derivation2a.scala:32:22 -------------------------
32 |    private final val caseSeparator = '\001'
   |                      ^
   |Access non-initialized field value caseSeparator. Calling trace:
   | -> initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])	[ typeclass-derivation2a.scala:29 ]
   |  -> else if (labelsStr(cur) == caseSeparator)	[ typeclass-derivation2a.scala:41 ]
2 errors found

initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])

private final val elemSeparator = '\000'
private final val caseSeparator = '\001'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liufengyun what happens if it is an inline val?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, due to const-fold it's not an error. The checker now runs before const-fold, it thus reports an error.

But I think it's still good to report errors here, as in this case const-fold changes the semantics of programs, which is too subtle for end users.

Note: due to const-fold, the code does not misbehave at runtime.
However, it's still good to report errors here, as in this case
const-fold changes the semantics of programs, which is too subtle for end users.

The field `elemSeparator` and `caseSeparator` are used before they are initialized.

-- Error: tests/run/typeclass-derivation2a.scala:31:22 -------------------------
31 |    private final val elemSeparator = '\000'
   |                      ^
   |Access non-initialized field value elemSeparator. Calling trace:
   | -> initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])	[ typeclass-derivation2a.scala:29 ]
   |  -> else if (labelsStr(cur) == elemSeparator)	[ typeclass-derivation2a.scala:43 ]
-- Error: tests/run/typeclass-derivation2a.scala:32:22 -------------------------
32 |    private final val caseSeparator = '\001'
   |                      ^
   |Access non-initialized field value caseSeparator. Calling trace:
   | -> initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])	[ typeclass-derivation2a.scala:29 ]
   |  -> else if (labelsStr(cur) == caseSeparator)	[ typeclass-derivation2a.scala:41 ]
2 errors found
```Scala
-- Error: tests/run/tuples1.scala:28:27 ----------------------------------------
28 |  val c0_1 = x0 ++ x1; val c0_1c: Int *: Unit = c0_1c; println(s"c0_1 = $c0_1")
   |                           ^
   |Access non-initialized field value c0_1c. Calling trace:
   | -> val c0_1 = x0 ++ x1; val c0_1c: Int *: Unit = c0_1c; println(s"c0_1 = $c0_1")	[ tuples1.scala:28 ]
-- Error: tests/run/tuples1.scala:29:27 ----------------------------------------
29 |  val c1_0 = x1 ++ x0; val c1_0c: Int *: Unit = c1_0c; println(s"c1_0 = $c1_0")
   |                           ^
   |Access non-initialized field value c1_0c. Calling trace:
   | -> val c1_0 = x1 ++ x0; val c1_0c: Int *: Unit = c1_0c; println(s"c1_0 = $c1_0")	[ tuples1.scala:29 ]
```
@odersky odersky merged commit c1612fa into scala:master Jan 29, 2020
@odersky odersky deleted the fix-init branch January 29, 2020 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants