Skip to content

Commit 2df913f

Browse files
committed
Update types in DottyPredef
1 parent 49a35e3 commit 2df913f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

library/src/dotty/DottyPredef.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,21 @@ object DottyPredef {
4848
*
4949
* Note that `.nn` performs a checked cast, so if invoked on a null value it'll throw an NPE.
5050
*/
51-
def[T] (x: T|Null) nn: T =
51+
def[T] (x: T|Null) nn: x.type & T =
5252
if (x == null) throw new NullPointerException("tried to cast away nullability, but value is null")
53-
else x.asInstanceOf[T]
53+
else x.asInstanceOf[x.type & T]
5454

5555
/** Reference equality where the receiver is a nullable union.
5656
* Note that if the receiver `r` is a reference type (e.g. `String`), then `r.eq` will invoke the
5757
* `eq` method in `AnyRef`.
5858
*/
5959
def (x: AnyRef|Null) eq(y: AnyRef|Null): Boolean =
60-
(x == null && y == null) || (x != null && x.eq(y))
60+
x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]
6161

6262
/** Reference disequality where the receiver is a nullable union.
6363
* Note that if the receiver `r` is a reference type (e.g. `String`), then `r.ne` will invoke the
6464
* `ne` method in `AnyRef`.
6565
*/
6666
def (x: AnyRef|Null) ne(y: AnyRef|Null): Boolean =
67-
(x == null && y != null) || (x != null && x.ne(y))
68-
67+
x.asInstanceOf[AnyRef] ne y.asInstanceOf[AnyRef]
6968
}

0 commit comments

Comments
 (0)