Skip to content

Commit

Permalink
Define Predef.{summon,nn} overwrites directly in Scala 2 library TASTy
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Mar 6, 2024
1 parent 7e07214 commit ba0eb36
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
19 changes: 10 additions & 9 deletions project/TastyMiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import tastymima.intf._

object TastyMiMaFilters {
val StdlibBootstrapped: java.util.List[ProblemMatcher] = asList(

// FIXME: method overwritten in scala2-library-bootstrapped/src/scala/Predef.scala
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]
// FIXME: method NOT overwritten yet in scala2-library-bootstrapped/src/scala/Predef.scala
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
// FIXME: method NOT overwritten yet in scala2-library-bootstrapped/src/scala/Predef.scala
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
// FIXME: method NOT overwritten yet in scala2-library-bootstrapped/src/scala/Predef.scala
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

// Probably OK
ProblemMatcher.make(ProblemKind.IncompatibleSelfTypeChange, "scala.*"),

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

// Problem: ???
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
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
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

// Probably OK: protected lazy val (processThread, (futureThread, futureValue), destroyer) = { ... }
// None of these can be accessed from user code.
// https://github.com/scala/scala/blob/cff8a9af4da67658d8e1e32f929e1aff03ffa384/src/library/scala/sys/process/ProcessImpl.scala#L99C5-L99C83
Expand All @@ -75,10 +80,6 @@ object TastyMiMaFilters {
// https://github.com/scala/scala/blob/2.13.x/src/library/scala/collection/mutable/ArrayBuilder.scala#L504C1-L504C87
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

// Probably OK (TASTy MiMa bug): Patched Predef members
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
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

// TASTy-MiMa bugs
ProblemMatcher.make(ProblemKind.InternalError, "scala.collection.SeqView.appendedAll"),
ProblemMatcher.make(ProblemKind.InternalError, "scala.collection.SeqView.concat"),
Expand Down
58 changes: 58 additions & 0 deletions scala2-library-bootstrapped/src/scala/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,64 @@ object Predef extends LowPriorityImplicits {
*/
// $ to avoid accidental shadowing (e.g. scala/bug#7788)
implicit def $conforms[A]: A => A = <:<.refl

// TODO Add `valueOf`:
// Issue is that this introduces a cyclic dependency between
// the Scala 2 and 3 library due to the reference to `summonFrom`.
// /**
// * Retrieve the single value of a type with a unique inhabitant.
// *
// * @example {{{
// * object Foo
// * val foo = valueOf[Foo.type]
// * // foo is Foo.type = Foo
// *
// * val bar = valueOf[23]
// * // bar is 23.type = 23
// * }}}
// * @group utilities
// */
// inline def valueOf[T]: T = summonFrom {
// case ev: ValueOf[T] => ev.value
// }

/** Summon a given value of type `T`. Usually, the argument is not passed explicitly.
*
* @tparam T the type of the value to be summoned
* @return the given value typed: the provided type parameter
*/
transparent inline def summon[T](using x: T): x.type = x

// Extension methods for working with explicit nulls

/** Strips away the nullability from a value. Note that `.nn` performs a checked cast,
* so if invoked on a `null` value it will throw an `NullPointerException`.
* @example {{{
* val s1: String | Null = "hello"
* val s2: String = s1.nn
*
* val s3: String | Null = null
* val s4: String = s3.nn // throw NullPointerException
* }}}
*/
extension [T](x: T | Null) inline def nn: x.type & T =
if x.asInstanceOf[Any] == null then scala.runtime.Scala3RunTime.nnFail()
x.asInstanceOf[x.type & T]

// FIXME
// tests/explicit-nulls/pos/eq-ne.scala failed
// tests/explicit-nulls/pos/flow-predef-eq.scala failed
// extension (inline x: AnyRef | Null)
// /** Enables an expression of type `T|Null`, where `T` is a subtype of `AnyRef`, to be checked for `null`
// * using `eq` rather than only `==`. This is needed because `Null` no longer has
// * `eq` or `ne` methods, only `==` and `!=` inherited from `Any`. */
// inline def eq(inline y: AnyRef | Null): Boolean =
// x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]
// /** Enables an expression of type `T|Null`, where `T` is a subtype of `AnyRef`, to be checked for `null`
// * using `ne` rather than only `!=`. This is needed because `Null` no longer has
// * `eq` or `ne` methods, only `==` and `!=` inherited from `Any`. */
// inline def ne(inline y: AnyRef | Null): Boolean =
// !(x eq y)
}

/** The `LowPriorityImplicits` class provides implicit values that
Expand Down

0 comments on commit ba0eb36

Please sign in to comment.