question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inferring SafeInt from HList arity triggers a stackoverflow error.

See original GitHub issue

The 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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
soronpocommented, Sep 3, 2020

ToInt is for conversion SafeInt is for having a .Out <: Int with Singleton

0reactions
tribbloidcommented, Mar 14, 2022

I see, Sorry for the misunderstanding. So it is a synonym for “Require Int”.

Case closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making sense of error message related to type inference when ...
It's just returning exactly the same type as the compiler inferred for its argument. I consider the compiler error a bug, but as...
Read more >
How to Fix java.lang.StackOverflowError in Java - Rollbar
StackOverflowError indicates that the application stack is exhausted and is usually caused by deep or infinite recursion.
Read more >
The StackOverflowError in Java - Baeldung
Another interesting scenario that causes this error is if a class is being instantiated within the same class as an instance variable of...
Read more >
Diagnosing a java.lang.StackOverflowError - IBM
Symptom. A stack overflow can result from: A deeply nested application; An infinite loop within an application; A problem in just-in-time ...
Read more >
StackOverflowError in Java with examples - GeeksforGeeks
This error is mainly due to the bad calling of constructors, that is, calling each other, which is not even required, and also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found