Skip to content

Compilation never stops with an upper bounded type param using a union type with 3 types #14870

@Lasering

Description

@Lasering

Compiler version

3.1.1

Minimized code

This code compiles (although it takes a little bit, aka more than usual for so little code)

import squants.energy.{Energy, KilowattHours}
import squants.time.{Minutes, Time}
import squants.thermal.{Temperature, Kelvin}
import squants.{Quantity, UnitOfMeasure, Dimensionless, Each}

case class Price[Q <: Quantity[Q] & (Energy | Time)](amount: Double, per: UnitOfMeasure[Q])
Price(5.5, KilowattHours)
Price(5.5, Minutes)
//Price(5.5, Kelvin) // This line correctly fails to compile

Changing Price to

case class Price[Q <: Quantity[Q] & (Energy | Time | Dimensionless)](amount: Double, per: UnitOfMeasure[Q])

Causes the compiler to never stop compiling.

Output

Scastie times out after 30 seconds.
Ran locally for 300 seconds then killed it.

Expectation

With a union type of 2 types it works, but with 3 types it fails. This suggests a explosion of combinations to big to handle in a reasonable time. There must be a limit to this explosion of combinations, however I was expecting it to be much higher: in the tens or even in the hundreds not 3.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions