Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception during macro expansion: java.lang.ArrayIndexOutOfBoundsException: #258

Open
tribbloid opened this issue Dec 15, 2021 · 2 comments

Comments

@tribbloid
Copy link

Simple demonstration:

import org.scalatest.funspec.AnyFunSpec

import scala.language.experimental.macros

class ErrorCase extends AnyFunSpec {

  final val code = """
object FoundReq {
  class L
  type R
  def f(r: R): Int = ???
  f(new L)
}"""

  val aa = utest.compileError(
    code
  )
}

This generates the error:

[Error] /home/..../ErrorCase.scala:19:30: exception during macro expansion: 
java.lang.ArrayIndexOutOfBoundsException: 26
	at scala.reflect.internal.util.BatchSourceFile.findLine$1(SourceFile.scala:218)
	at scala.reflect.internal.util.BatchSourceFile.offsetToLine(SourceFile.scala:221)
	at scala.reflect.internal.util.InternalPositionImpl.line0(Position.scala:177)
	at scala.reflect.internal.util.InternalPositionImpl.lineContent(Position.scala:189)
	at scala.reflect.internal.util.InternalPositionImpl.lineContent$(Position.scala:189)
	at scala.reflect.internal.util.Position.lineContent(Position.scala:19)
	at utest.asserts.AssertsCompanionVersionSpecific.calcPosMsg$1(Asserts.scala:27)
	at utest.asserts.AssertsCompanionVersionSpecific.compileError(Asserts.scala:82)
	at utest.asserts.AssertsCompanionVersionSpecific.compileError$(Asserts.scala:21)
	at utest.asserts.Asserts$.compileError(Asserts.scala:15)

@tribbloid
Copy link
Author

it is observed on Scala 2.13.7 on OpenJDK 8u311

@tribbloid
Copy link
Author

I believe the error is triggered by the following code:

      def prefix = if (funcs.length == 1) "" else s"#${i+1}: "
      res match{
        case Success(value) =>
          if (!value) throw Util.makeAssertError(prefix + src, logged, null)
        case Failure(e) => throw Util.makeAssertError(prefix + src, logged, e)
      }

The solution should be simple: just add a fallback in case makeAssertError throws an exception, in which the prefix is reverted to ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant