Skip to content
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

Add fromNullable to Predef for explicit nulls #20222

Merged
merged 6 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions library/src-bootstrapped/scala/annotation/experimental.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ package scala.annotation
* @see [[https://dotty.epfl.ch/docs/reference/other-new-features/experimental-defs]]
* @syntax markdown
*/
@deprecatedInheritance("Scheduled for being final in the future", "3.4.0")
class experimental(message: String) extends StaticAnnotation:
final class experimental(message: String) extends StaticAnnotation:
def this() = this("")
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package scala.annotation

@deprecatedInheritance("Scheduled for being final in the future", "3.4.0")
class experimental extends StaticAnnotation
final class experimental extends StaticAnnotation
4 changes: 4 additions & 0 deletions library/src/scala/runtime/stdLibPatches/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ object Predef:
* `eq` or `ne` methods, only `==` and `!=` inherited from `Any`. */
inline def ne(inline y: AnyRef | Null): Boolean =
!(x eq y)

extension (inline opt: Option.type)
@experimental
inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf[Option[T]]
noti0na1 marked this conversation as resolved.
Show resolved Hide resolved
bishabosha marked this conversation as resolved.
Show resolved Hide resolved
end Predef
3 changes: 3 additions & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object MiMaFilters {
// Additions that require a new minor version of the library
Build.mimaPreviousDottyVersion -> Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.annotation.experimental.this"),
ProblemFilters.exclude[FinalClassProblem]("scala.annotation.experimental"),
),

// Additions since last LTS
Expand Down Expand Up @@ -56,6 +57,8 @@ object MiMaFilters {
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeModule.apply"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeMethods.methodTypeKind"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeMethods.isContextual"),
// Change `experimental` annotation to a final class
ProblemFilters.exclude[FinalClassProblem]("scala.annotation.experimental"),
),

// Breaking changes since last LTS
Expand Down
6 changes: 6 additions & 0 deletions tests/explicit-nulls/neg/from-nullable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.annotation.experimental

@experimental def testFromNullable =
val s: String | Null = "abc"
val sopt1: Option[String] = Option(s) // error
val sopt2: Option[String] = Option.fromNullable(s) // ok
noti0na1 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions tests/neg/experimentalExperimental.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class MyExperimentalAnnot extends scala.annotation.experimental // error
1 change: 0 additions & 1 deletion tests/pos/experimentalExperimental.scala

This file was deleted.

3 changes: 3 additions & 0 deletions tests/run-tasty-inspector/stdlibExperimentalDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ val experimentalDefinitionInLibrary = Set(
"scala.Tuple$.Reverse", // can be stabilized in 3.5
"scala.Tuple$.ReverseOnto", // can be stabilized in 3.5
"scala.runtime.Tuples$.reverse", // can be stabilized in 3.5

// New feature: fromNullable for explicit nulls
"scala.Predef$.fromNullable",
)


Expand Down
Loading