Skip to content

Instantly share code, notes, and snippets.

View abeln's full-sized avatar

Abel Nieto abeln

View GitHub Profile
diff --git a/src/scalap/scala/tools/scalap/Decode.scala b/src/scalap/scala/tools/scalap/Decode.scala
index acef441..4e5197e 100644
--- a/src/scalap/scala/tools/scalap/Decode.scala
+++ b/src/scalap/scala/tools/scalap/Decode.scala
@@ -55,7 +55,7 @@ object Decode {
classFile annotation SCALA_SIG_ANNOTATION map { case Annotation(_, els) =>
val bytesElem = els find (x => constant(x.elementNameIndex) == BYTES_VALUE) orNull
- val _bytes = bytesElem.elementValue match { case ConstValueIndex(x) => constantWrapped(x) }
+ val _bytes = bytesElem.nn.elementValue match { case ConstValueIndex(x) => constantWrapped(x) }
diff --git a/cssparse/test/src-jvm/cssparse/ProjectTests.scala b/cssparse/test/src-jvm/cssparse/ProjectTests.scala
index a9dcc39..bc76b63 100644
--- a/cssparse/test/src-jvm/cssparse/ProjectTests.scala
+++ b/cssparse/test/src-jvm/cssparse/ProjectTests.scala
@@ -10,7 +10,7 @@ object ProjectTests extends TestSuite {
def checkCss()(implicit testPath: utest.framework.TestPath) = {
val url = "https://github.com/" + testPath.value.last
- val name = url.split("/").last
+ val name = url.split("/").last.nn
@abeln
abeln / scalapb.diff
Created November 13, 2019 23:34
Migrate ScalaPB to explicit nulls
diff --git a/compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala b/compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala
index cfcf0c3..24c3100 100644
--- a/compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala
+++ b/compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala
@@ -940,7 +940,7 @@ class DescriptorImplicits(params: GeneratorParams, files: Seq[FileDescriptor]) {
}
def baseName(fileName: String) =
- fileName.split("/").last.replaceAll(raw"[.]proto$$|[.]protodevel", "")
+ fileName.split("/").last.nn.replaceAll(raw"[.]proto$$|[.]protodevel", "")
@abeln
abeln / semanticdb.diff
Created November 13, 2019 19:12
Migrate semanticdb to explicit nulls
diff --git a/src/main/scala/dotty/semanticdb/SourceFile.scala b/src/main/scala/dotty/semanticdb/SourceFile.scala
index c53579b..34560bc 100644
--- a/src/main/scala/dotty/semanticdb/SourceFile.scala
+++ b/src/main/scala/dotty/semanticdb/SourceFile.scala
@@ -68,4 +68,4 @@ class SourceFile(path: java.nio.file.Path) {
}
return previous
}
-}
\ No newline at end of file
@abeln
abeln / minitest.diff
Last active November 13, 2019 05:00
Porting minitest to explicit nulls
diff --git a/shared/src/main/scala/minitest/api/Result.scala b/shared/src/main/scala/minitest/api/Result.scala
index f681231..85aa4ab 100644
--- a/shared/src/main/scala/minitest/api/Result.scala
+++ b/shared/src/main/scala/minitest/api/Result.scala
@@ -55,7 +55,7 @@ object Result {
}
}
- final case class Failure(msg: String, source: Option[Throwable], location: Option[SourceLocation])
+ final case class Failure(msg: String | Null, source: Option[Throwable], location: Option[SourceLocation])
@abeln
abeln / scopt.diff
Created November 12, 2019 22:02
Port scopts to explicit nulls
diff --git a/jvm/src/main/scala/PlatformReadInstances.scala b/jvm/src/main/scala/PlatformReadInstances.scala
index da707c4..73227a7 100644
--- a/jvm/src/main/scala/PlatformReadInstances.scala
+++ b/jvm/src/main/scala/PlatformReadInstances.scala
@@ -12,7 +12,7 @@ private[scopt] object platform {
import java.net.{ InetAddress, URI }
type ParseException = java.text.ParseException
- def mkParseEx(s: String, p: Int) = new java.text.ParseException(s, p)
+ def mkParseEx(s: String | Null, p: Int) = new java.text.ParseException(s, p)
@abeln
abeln / gist:4385c87a8a7b233e00ed06d6b88dcb73
Created October 21, 2019 21:44
standard library with flag on
[info] Compiling 614 Scala sources and 148 Java sources to /home/anietoro/src/dotty2/community-build/community-projects/stdLib213/build/quick/classes/library ...
[warn] bad option '-Ynew-collections' was ignored
[warn] -- Warning: /home/anietoro/src/dotty2/community-build/community-projects/stdLib213/src/library/scala/collection/immutable/Vector.scala:1085:2
[warn] 1085 | private[immutable] final def gotoNewBlockStart(index: Int, depth: Int): Unit = {
[warn] | ^
[warn] | Line is indented too far to the left, or a `}' is missing
[warn] -- Warning: /home/anietoro/src/dotty2/community-build/community-projects/stdLib213/src/library/scala/concurrent/impl/Promise.scala:104:2
[warn] 104 | class DefaultPromise[T] private[this] (initial: AnyRef) extends AtomicReference[AnyRef](initial) with scala.concurrent.Promise[T] with scala.concurrent.Future[T] with (Try[T] => Unit) {
[warn] | ^
[warn] | Line is indented too far to the left, or a `}' is missing
@abeln
abeln / gist:fd3052ccc26901242d06f39b055156b2
Last active October 21, 2019 19:30
PB library errors after latest flag turned on
[warn] -- Deprecation Warning: /home/anietoro/src/dotty2/community-build/community-projects/ScalaPB/lenses/shared/src/main/scala/scalapb/lenses/Lenses.scala:108:12
[warn] 108 | s.mapValues { (m: B) =>
[warn] | ^^^^^^^^^^^
[warn] |method mapValues in trait MapOps is deprecated: Use .view.mapValues(f). A future version will include a strict version of this method (for now, .view.mapValues(f).toMap).
[error] -- [E008] Member Not Found Error: /home/anietoro/src/dotty2/community-build/community-projects/ScalaPB/compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala:943:29
[error] 943 | fileName.split("/").last.replaceAll(raw"[.]proto$$|[.]protodevel", "")
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | value replaceAll is not a member of String | Null
[warn] one warning found
[info] Done compiling.
layout title
doc-page
Explicit Nulls

This proposal describes a modification to the Scala type system that makes reference types (anything that extends AnyRef) non-nullable.

This means the following code will no longer typecheck:

layout title
doc-page
Explicit Nulls

The "explicit nulls" feature (enabled via a flag) changes the Scala type hierarchy so that reference types (e.g. String) are non-nullable. We can still express nullability with union types: e.g. val x: String|Null = null.

The implementation of the feature in dotty can be conceptually divided in several parts: