Skip to content

Fix and improve the document for Explicit Nulls #11699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2021

Conversation

ShapelessCat
Copy link
Contributor

  • Fix some text and adjust the markdown format.
  • Insert one space before and after | to make the code examples have a consistent style.
  • Adjust the link to the image "Type Hierarchy for Explicit Nulls": put this image name in the [] part instead of putting it after the hyperlink text.
  • Convert "UnsafeNulls" to a in-file link that points to the subsection ###UnsafeNulls
  • Update tests/explicit-nulls/neg/flow-varref-in-closure.scala to tests/explicit-nulls/neg/flow-varref-in-closure.scala, and also convert it to a link that points to file ../../../../tests/explicit-nulls/neg/flow-varref-in-closure.scala.
  • Remove ()s from some side-effect free Scala method calls.

@ShapelessCat
Copy link
Contributor Author

ShapelessCat commented Mar 11, 2021

I have a question to this line:

val d2: Array[String | Null] = d1 // unsafely convert Array[String] to Array[String | Null]

which is the line 492 before changing, and line 508 after changing.

I didn't touch this line, but I don't quite understand the "unsafely" in its comment.
Since d1 is of type Array[String], it seems val d2: Array[String | Null] = d1 doesn't include any unsafe operation. Can anyone explain to me why this assignment is unsafe. Thanks!

@noti0na1
Copy link
Member

Thanks for the fix!

Because Array in Scala is invariant, Array[String] is not a subtype of Array[String | Null]. Hence, this conversion is unsafe.

@odersky odersky merged commit ca7c6fc into scala:master Mar 11, 2021
@ShapelessCat ShapelessCat deleted the fix-docs_explicit-nulls branch March 15, 2021 21:09
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.

4 participants