Skip to content

Commit 45aee96

Browse files
committed
Define Predef.{summon,nn} overwrites directly in Scala 2 library TASTy
1 parent 0b9c396 commit 45aee96

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

project/TastyMiMaFilters.scala

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import tastymima.intf._
33

44
object TastyMiMaFilters {
55
val StdlibBootstrapped: java.util.List[ProblemMatcher] = asList(
6+
7+
// FIXME: method overwritten in scala2-library-bootstrapped/src/scala/Predef.scala
8+
ProblemMatcher.make(ProblemKind.IncompatibleTypeChange, "scala.Predef.nn"), // The symbol scala.Predef.nn has an incompatible type in current version: before: [T](x: T)(x.type & T); after: [T](x: scala.|[T, scala.Null])scala.&[x.type, T]
9+
// FIXME: method NOT overwritten yet in scala2-library-bootstrapped/src/scala/Predef.scala
10+
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.valueOf"), // The member scala.Predef.valueOf with signature (1):java.lang.Object does not have a correspondant in current version
11+
// FIXME: method NOT overwritten yet in scala2-library-bootstrapped/src/scala/Predef.scala
12+
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.ne"), // The member scala.Predef.ne with signature (java.lang.Object,java.lang.Object):scala.Boolean does not have a correspondant in current version
13+
// FIXME: method NOT overwritten yet in scala2-library-bootstrapped/src/scala/Predef.scala
14+
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.eq"), // The member scala.Predef.eq with signature (java.lang.Object,java.lang.Object):scala.Boolean does not have a correspondant in current version
15+
616
// Probably OK
717
ProblemMatcher.make(ProblemKind.IncompatibleSelfTypeChange, "scala.*"),
818

@@ -54,11 +64,6 @@ object TastyMiMaFilters {
5464
ProblemMatcher.make(ProblemKind.NewAbstractMember, "scala.collection.convert.impl.TableStepperBase.i0_="),
5565
ProblemMatcher.make(ProblemKind.NewAbstractMember, "scala.collection.convert.impl.TableStepperBase.maxLength_="),
5666

57-
// Problem: ???
58-
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.nn"), // The member scala.Predef.nn with signature (1,java.lang.Object):java.lang.Object does not have a correspondant in current version
59-
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.ne"), // The member scala.Predef.ne with signature (java.lang.Object,java.lang.Object):scala.Boolean does not have a correspondant in current version
60-
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.eq"), // The member scala.Predef.eq with signature (java.lang.Object,java.lang.Object):scala.Boolean does not have a correspondant in current version
61-
6267
// Probably OK: protected lazy val (processThread, (futureThread, futureValue), destroyer) = { ... }
6368
// None of these can be accessed from user code.
6469
// https://github.com/scala/scala/blob/cff8a9af4da67658d8e1e32f929e1aff03ffa384/src/library/scala/sys/process/ProcessImpl.scala#L99C5-L99C83
@@ -75,10 +80,6 @@ object TastyMiMaFilters {
7580
// https://github.com/scala/scala/blob/2.13.x/src/library/scala/collection/mutable/ArrayBuilder.scala#L504C1-L504C87
7681
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.collection.mutable.ArrayBuilder.ofUnit.addAll"), // The member scala.collection.mutable.ArrayBuilder.ofUnit.addAll with signature (java.lang.Object,scala.Int,scala.Int):scala.collection.mutable.ArrayBuilder$.ofUnit does not have a correspondant in current version
7782

78-
// Probably OK (TASTy MiMa bug): Patched Predef members
79-
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.valueOf"), // The member scala.Predef.valueOf with signature (1):java.lang.Object does not have a correspondant in current version
80-
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.Predef.summon"), // The member scala.Predef.summon with signature (1,java.lang.Object):java.lang.Object does not have a correspondant in current version
81-
8283
// TASTy-MiMa bugs
8384
ProblemMatcher.make(ProblemKind.InternalError, "scala.collection.SeqView.appendedAll"),
8485
ProblemMatcher.make(ProblemKind.InternalError, "scala.collection.SeqView.concat"),

scala2-library-bootstrapped/src/scala/Predef.scala

+58
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,64 @@ object Predef extends LowPriorityImplicits {
508508
*/
509509
// $ to avoid accidental shadowing (e.g. scala/bug#7788)
510510
implicit def $conforms[A]: A => A = <:<.refl
511+
512+
// TODO Add `valueOf`:
513+
// Issue is that this introduces a cyclic dependency between
514+
// the Scala 2 and 3 library due to the reference to `summonFrom`.
515+
// /**
516+
// * Retrieve the single value of a type with a unique inhabitant.
517+
// *
518+
// * @example {{{
519+
// * object Foo
520+
// * val foo = valueOf[Foo.type]
521+
// * // foo is Foo.type = Foo
522+
// *
523+
// * val bar = valueOf[23]
524+
// * // bar is 23.type = 23
525+
// * }}}
526+
// * @group utilities
527+
// */
528+
// inline def valueOf[T]: T = summonFrom {
529+
// case ev: ValueOf[T] => ev.value
530+
// }
531+
532+
/** Summon a given value of type `T`. Usually, the argument is not passed explicitly.
533+
*
534+
* @tparam T the type of the value to be summoned
535+
* @return the given value typed: the provided type parameter
536+
*/
537+
transparent inline def summon[T](using x: T): x.type = x
538+
539+
// Extension methods for working with explicit nulls
540+
541+
/** Strips away the nullability from a value. Note that `.nn` performs a checked cast,
542+
* so if invoked on a `null` value it will throw an `NullPointerException`.
543+
* @example {{{
544+
* val s1: String | Null = "hello"
545+
* val s2: String = s1.nn
546+
*
547+
* val s3: String | Null = null
548+
* val s4: String = s3.nn // throw NullPointerException
549+
* }}}
550+
*/
551+
extension [T](x: T | Null) inline def nn: x.type & T =
552+
if x.asInstanceOf[Any] == null then scala.runtime.Scala3RunTime.nnFail()
553+
x.asInstanceOf[x.type & T]
554+
555+
// FIXME
556+
// tests/explicit-nulls/pos/eq-ne.scala failed
557+
// tests/explicit-nulls/pos/flow-predef-eq.scala failed
558+
// extension (inline x: AnyRef | Null)
559+
// /** Enables an expression of type `T|Null`, where `T` is a subtype of `AnyRef`, to be checked for `null`
560+
// * using `eq` rather than only `==`. This is needed because `Null` no longer has
561+
// * `eq` or `ne` methods, only `==` and `!=` inherited from `Any`. */
562+
// inline def eq(inline y: AnyRef | Null): Boolean =
563+
// x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]
564+
// /** Enables an expression of type `T|Null`, where `T` is a subtype of `AnyRef`, to be checked for `null`
565+
// * using `ne` rather than only `!=`. This is needed because `Null` no longer has
566+
// * `eq` or `ne` methods, only `==` and `!=` inherited from `Any`. */
567+
// inline def ne(inline y: AnyRef | Null): Boolean =
568+
// !(x eq y)
511569
}
512570

513571
/** The `LowPriorityImplicits` class provides implicit values that

0 commit comments

Comments
 (0)