Skip to content

Commit

Permalink
Test stdlib-bootstrpped ScalaNumericConversions.underlying (#18086)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki authored Jul 5, 2023
2 parents 6367318 + 5e5735b commit 819c625
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion project/TastyMiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ object TastyMiMaFilters {
// Problem? Very complicated signature
ProblemMatcher.make(ProblemKind.IncompatibleTypeChange, "scala.collection.generic.IsMap.mapOpsIsMap"),

// Problem: Overriding java method (`public abstract Object underlying();` with `def underlying: Object`)
// Probably OK: Overriding java method (`public abstract Object underlying();` with `def underlying: Object`)
// Calls to the underlying seem to link correctly.
// Tested in stdlib-bootstrapped/test/Main.scala
ProblemMatcher.make(ProblemKind.MissingTermMember, "scala.math.Big*.underlying"),
ProblemMatcher.make(ProblemKind.NewAbstractMember, "scala.math.ScalaNumericConversions.underlying"),

Expand Down
30 changes: 30 additions & 0 deletions stdlib-bootstrapped-tasty-tests/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object HelloWorld:
testScala2UnapplySignatures()
testScala2ObjectParents()
testScala2CaseClassUnderscoreMembers()
testScalaNumberUnderlying()
}

def testScala2UnapplySignatures() = {
Expand All @@ -37,3 +38,32 @@ object HelloWorld:
val some: Some[Int] = Some(1)
// FIXME: assert(!typeChecks("some._1"))
}

def testScalaNumberUnderlying() = {
import scala.math.{ScalaNumericConversions, ScalaNumber}

val _: java.math.BigInteger = BigInt(1).underlying
val _: Object = (BigInt(1): ScalaNumericConversions).underlying
val _: Object = (BigInt(1): ScalaNumber).underlying

// val _: java.math.BigDecimal = BigDecimal(1).underlying // FIXME: inferred result type of non-private method
val _: Object = (BigDecimal(1): ScalaNumericConversions).underlying
val _: Object = (BigDecimal(1): ScalaNumber).underlying

class MyNumber1(override val underlying: BigInt) extends ScalaNumericConversions {
def doubleValue: Double = ???; def floatValue: Float = ???;
def intValue: Int = ???; def longValue: Long = ???
def isWhole: Boolean = ???
}
val _: BigInt = MyNumber1(1).underlying
val _: Object = (MyNumber1(1): ScalaNumericConversions).underlying
val _: Object = (MyNumber1(1): ScalaNumber).underlying

class MyNumber2(override val underlying: Object) extends ScalaNumber {
def doubleValue: Double = ???; def floatValue: Float = ???;
def intValue: Int = ???; def longValue: Long = ???
def isWhole: Boolean = ???
}
val _: Object = MyNumber2(BigInt(1)).underlying
val _: Object = (MyNumber2(BigInt(1)): ScalaNumber).underlying
}

0 comments on commit 819c625

Please sign in to comment.