Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion library/src/scala/Option.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ sealed abstract class Option[+A] extends IterableOnce[A] with Product with Seria
* val textField = new JComponent(initialText.orNull,20)
* ```
*/
@inline final def orNull[A1 >: A](implicit ev: Null <:< A1): A1 = this getOrElse ev(null)
@inline final def orNull: A | Null = this.getOrElse(null)

// for binary and TASTy backwards compatibility
@deprecated @inline protected final def orNull[A1 >: A](implicit ev: Null <:< A1): A1 = this getOrElse ev(null)

/** Returns a $some containing the result of applying $f to this $option's
* value if this $option is nonempty.
Expand Down
1 change: 1 addition & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object MiMaFilters {

// Breaking changes since last reference version
Build.mimaPreviousDottyVersion -> Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.None.orNull"),
ProblemFilters.exclude[MissingTypesProblem]("scala.util.control.NonLocalReturns$ReturnThrowable"),
// THIS IS FINE, IT SHOULD HAVE BEEN THIS WAY
ProblemFilters.exclude[MissingTypesProblem]("scala.Function1$"),
Expand Down
6 changes: 6 additions & 0 deletions tests/explicit-nulls/pos/option-ornull.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import java.util.Optional

class CheckResult(result: Option[Unit]):
def foo =
val x: Optional[Unit] = Optional.ofNullable(result.orNull)
42
Loading