Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -52,6 +52,7 @@ object MiMaFilters {
ProblemFilters.exclude[FinalMethodProblem]("scala.jdk.Accumulator.:++"),
ProblemFilters.exclude[FinalMethodProblem]("scala.jdk.Accumulator.concat"),
ProblemFilters.exclude[FinalMethodProblem]("scala.jdk.Accumulator.sizeHint$default$2"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.None.orNull"),
Comment thread
olhotak marked this conversation as resolved.
Outdated
)
)
}
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