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.

regression: Integer overflow in nesting level of a Macro expansion (PolyType/TypeBounds) between 3.1.1 and 3.1.2

See original GitHub issue

Compiler version

3.1.2

Minimized code

It requires some macro magic to reproduce and I didn’t manage to extract the minimal reproducible code. But it manifests with one specific open source project https://github.com/davenverse/epimetheus

If you perform git clone and then run sbt (in my case JDK 17 was used) with these commands it will encounter compilation errors.

++ 3.1.2; Test / compile

Output

sbt log

[error] -- Error: ~/epimetheus/core/src/test/scala/io/chrisdavenport/epimetheus/CounterSpec.scala:30:68 
[error] 30 |        counter <- Counter.labelled(cr, Name("boo"), "Boo Counter", Sized(Label("foo")), {(s: String) => Sized(s)})
[error]    |                                                                    ^
[error]    |Could not decrease the nesting level of a from 2147483647 to 6 in

And a lot more of PolyType and TypeBounds output.

Expectation

Compile w/o errors like it was with 3.1.1

++ 3.1.1; Test / compile

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bishaboshacommented, Apr 14, 2022

the example still fails for me without the macro, so I removed it

1reaction
arixmkiicommented, Apr 14, 2022

I managed to minimize it to 2 Scala sources (because Macros support is involved) - Base - with macro definitions and Test with failing example. It is still big, but I eliminated all external dependencies at least.

Base.scala

package testcase

import scala.compiletime.ops.int.*

final class Label (val getLabel: String)

trait ShapelessPolyfill {

  type Represented[R] = R match {
    case IndexedSeq[a] => a
  }

  type TupleSized[R, A, N <: Int] <: Tuple = N match {
    case 0 => EmptyTuple
    case S[n] => A *: TupleSized[R, A, n]
  }

  extension [R, A, N <: Int] (s: TupleSized[R, A, N]) {
    def unsized: IndexedSeq[A] = s.productIterator.toIndexedSeq.asInstanceOf[IndexedSeq[A]]
  }

  type Nat = Int

  type Sized[Repr, L <: Nat] = TupleSized[Repr, Represented[Repr], L]

  object Sized {
    def apply[A](a1: A): Sized[IndexedSeq[A], 1] = Tuple1(a1)
  }

}

object poly extends ShapelessPolyfill

Test.scala

package testcase

import poly.*

def failing: Tuple1[Label] = Sized(new Label("foo"))

With 3.1.1 it compiles

nestingbug % ls -a                 
.		..		Base.scala	Test.scala
nestingbug % scalac -version       
Scala compiler version 3.1.1 -- Copyright 2002-2022, LAMP/EPFL
nestingbug % scalac Base.scala     
nestingbug % scalac Test.scala

With 3.1.2 it fails

nestingbug % ls -a
.		..		Base.scala	Test.scala
nestingbug % scalac -version
Scala compiler version 3.1.2 -- Copyright 2002-2022, LAMP/EPFL
nestingbug % scalac Base.scala
nestingbug % scalac Test.scala
-- Error: Test.scala:5:29 ------------------------------------------------------
5 |def failing: Tuple1[Label] = Sized(Label("foo"))
  |                             ^
  |Could not decrease the nesting level of a from 2147483647 to 2 in 
... A lot more output omitted...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Help to create a macro do avoid integer overflow
I need help to create a macro to do the following: On every integer operation, check if overflow will happen. If it does,...
Read more >
Expansion of nested macros, from the inner to the outer?
The answer is these aren't nested macros, but macros in parameters. ... The number in the brackets [] is the nesting level during...
Read more >
GNU MPFR 3.1.5
How to install and use GNU MPFR, a library for reliable multiple precision floating-point arithmetic, version 3.1.5.
Read more >
The C Preprocessor - GCC, the GNU Compiler Collection
3.9.1 Misnesting . ... The '#' which begins a directive cannot come from a macro expansion. ... and patch level of the compiler,...
Read more >
The SAS LGTPHCURV9 Macro
The %LGTPHCURV9 macro fits restricted cubic splines to unconditional logistic, pooled lo- gistic, conditional logistic, and proportional hazards regression ...
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