-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:inlinearea:pattern-matchingarea:union-typesIssues tied to union types.Issues tied to union types.itype:bug
Description
Compiler version
3.8.1
Minimized code
trait Dist[T]:
def sample(using rng: java.util.Random): T
inline def Uniform[F <: Float | Double | Int | Long](inline low: F, inline high: F): Dist[F] = new:
override def sample(using rng: java.util.Random): F =
inline compiletime.erasedValue[F] match
case _: Float => rng.nextFloat(low, high)
case _: Double => rng.nextDouble(low, high)
case _: Int => rng.nextInt(low, high)
case _: Long => rng.nextLong(low, high)Output
case _: Float => rng.nextFloat(): F
^^^^^^^^^^^^^^^
Found: Float
Required: F
where: F is a type in method Uniform with bounds <: Float | Double | Int | Long
Tree:
rng.nextFloat()
I tried to show that
Float
conforms to
F
but none of the attempts shown below succeeded:
==> Float <: F
==> Float <: Nothing in frozen constraint = false
The tests were made under the empty constraintExpectation
I expect the constraint not to be empty, specifically for the type match to constrain F to Float.
Partial workaround
inline (low, high) match
case (low: Float, high: Float) => rng.nextFloat(low, high)does work for constraining the inputs, but this still fails on the return type without asInstanceOf
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:inlinearea:pattern-matchingarea:union-typesIssues tied to union types.Issues tied to union types.itype:bug