LF: SErrorCrash should not be thrown by Speedy callbacks (#12099)

as it is normally caught in the interpreter loop.  In particular the
caller of the engine should not have to catch such an error.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Remy 2021-12-10 13:20:38 +01:00 committed by GitHub
parent 346fecbb03
commit 35beb44c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 11 deletions

View File

@ -521,7 +521,7 @@ private[lf] object Speedy {
this.compiledPackages = packages
// To avoid infinite loop in case the packages are not updated properly by the caller
assert(compiledPackages.packageIds.contains(ref.packageId))
lookupVal(eval)
ctrl = eval
},
)
)

View File

@ -10,16 +10,18 @@ import com.daml.lf.language.Ast._
import com.daml.lf.language.LanguageVersion
import com.daml.lf.language.Util._
import com.daml.lf.speedy.SError._
import com.daml.lf.speedy.SExpr.LfDefRef
import com.daml.lf.speedy.SResult._
import com.daml.lf.testing.parser.Implicits._
import org.scalatest.Inside
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers
import org.slf4j.LoggerFactory
import scala.language.implicitConversions
class InterpreterTest extends AnyWordSpec with Matchers with TableDrivenPropertyChecks {
class InterpreterTest extends AnyWordSpec with Inside with Matchers with TableDrivenPropertyChecks {
private implicit def id(s: String): Ref.Name = Name.assertFromString(s)
@ -250,18 +252,15 @@ class InterpreterTest extends AnyWordSpec with Matchers with TableDrivenProperty
result match {
case SResultNeedPackage(pkgId, _, cb) =>
ref.packageId shouldBe pkgId
try {
cb(pkgs3)
sys.error(s"expected crash when definition not provided")
} catch {
case _: SErrorCrash => ()
cb(pkgs3)
inside(machine.run()) { case SResultError(SErrorCrash(loc, msg)) =>
loc shouldBe "com.daml.lf.speedy.Speedy.Machine.lookupVal"
msg should include(s"definition ${LfDefRef(ref)} not found")
}
case _ =>
sys.error(s"expected result to be missing definition, got $result")
fail(s"expected result to be missing definition, got $result")
}
}
}
}