Scala-native: Bug with generic functions throwing exceptions passed by name

Created on 25 Sep 2018  路  5Comments  路  Source: scala-native/scala-native

Trying to port Quill I faced this issue that appears with the combination of exceptions, @tailrec loops and scalatest.
You can find a minimal reproduction in the attached repository.
https://github.com/lolgab/scalanativebug

bug

All 5 comments

class Test extends FunSuite {
  @tailrec
  final def loop[T](a: Try[T]): T = {
    a.get
    loop(a)
  }

  test("test") {
    loop(Failure(new Exception))
  }
}

Hi @lolgab,
I ran your test reproduction. Interesting that the plugin continues on the error. Does Scala Test plan to have an actual release that supports both Native and JVM? I got the test to work on JVM but with 3.0.5 not 3.2.0-SNAP10.

sbt:scalanativebug-master> test
[info] Compiling 1 Scala source to /Users/eric/workspace/scalanativebug-master/target/scala-2.11/test-classes ...
[info] Done compiling.
[info] Compiling 1 Scala source to /Users/eric/workspace/scalanativebug-master/target/scala-2.11/test-classes ...
[info] Done compiling.
[info] Linking (2515 ms)
[info] Discovered 2235 classes and 14871 methods
[info] Optimizing (debug mode) (3204 ms)
[info] Generating intermediate code (1312 ms)
[info] Produced 67 files
[error] /Users/eric/workspace/scalanativebug-master/target/scala-2.11/native/a.ll:69:7: error: value doesn't match function result type 'void'
[error]   ret i8* %_10
[error]       ^
[error] 1 error generated.
[info] Compiling to native code (2921 ms)
[error] clang-5.0: error: no such file or directory: '/Users/eric/workspace/scalanativebug-master/target/scala-2.11/native/a.ll.o'
[info] Linking native code (immix gc) (30 ms)
[info] Starting process '/Users/eric/workspace/scalanativebug-master/target/scala-2.11/scalanativebug-master-out' on port '58987'.
Exception in thread "Thread-426" java.io.IOException: Cannot run program "/Users/eric/workspace/scalanativebug-master/target/scala-2.11/scalanativebug-master-out": error=2, No such file or directory

Updates:

  • @tailrec doesn't matter
  • recursion doesn't matter
  • Scalatest doesn't matter
  • using Try and Failure don't matter.

I saw the issue only in tests because it happens only when a function with generic return type throws an exception and when the result is passed by name to another function.
Below you can find a smaller and dependency-free reproduction:

object Main {
  def f[T]: T = throw new Exception

  def f2[T](a: => T) = ()

  def main(args: Array[String]): Unit = f2(f)
}

Hi @ekrich , I don't know if there are plans to release Scala Native Scalatest. I encountered another strange behaviour with Scala Native Scalatest with tests running nicely but showing a count of 0 at the end.
Thank you for your answer :)

Thanks for the report, @lolgab !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

langley picture langley  路  6Comments

phdoerfler picture phdoerfler  路  3Comments

densh picture densh  路  4Comments

densh picture densh  路  5Comments

LeeTibbert picture LeeTibbert  路  4Comments