Inferring SafeInt from HList arity triggers a stackoverflow error.
See original GitHub issueThe following are 2 almost identical programs, the first one compiles successfully:
// just fixture
object big {
val nat = Nat(100)
}
val op1 = implicitly[ToInt[big.nat.N]]
def getOps[D <: HList, T <: Nat](v: D)(
implicit
ofLength: hlist.Length.Aux[D, T],
asInt: ToInt[T]
): ToInt[T] = {
asInt
}
val filled = HList.fill[Double](100)(0.0)
val op2 = getOps(filled)
The second, while only replaces `ToInt` with `SafeInt`, triggers a stackoverflow error:
val op1 = implicitly[SafeInt[big.nat.N]]
def getOps[D <: HList, T <: Nat](v: D)(
implicit
ofLength: hlist.Length.Aux[D, T],
asInt: SafeInt[T]
): SafeInt[T] = {
asInt
}
val filled = HList.fill[Double](100)(0.0)
val op2 = getOps(filled)
error:
Exception when compiling 42 sources to /home/peng/git/scalaspike/common/build/classes/scala/test
java.lang.StackOverflowError scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:114) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1135) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:323) scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:321) scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123) …
This should be enough information for the inference, any advice why this could happen?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top GitHub Comments
ToInt
is for conversionSafeInt
is for having a.Out <: Int with Singleton
I see, Sorry for the misunderstanding. So it is a synonym for “Require Int”.
Case closed