Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Code generation for >i is incorrect #456

Closed
mttrbrts opened this issue Sep 18, 2018 · 2 comments
Closed

Code generation for >i is incorrect #456

mttrbrts opened this issue Sep 18, 2018 · 2 comments
Labels
Type: Bug 🐛 Something isn't working

Comments

@mttrbrts
Copy link
Member

mttrbrts commented Sep 18, 2018

When the value of request.value is 1 the following executes as expected

enforce integerToDouble(request.value) > 0.0 else
      throw ErgoErrorResponse{ message: "The IOU's value must be non-negative." };

but the following returns the error response.

enforce request.value >i 0 else
      throw ErgoErrorResponse{ message: "The IOU's value must be non-negative." };

The full template including unit tests is available at https://github.com/mttrbrts/cordapp-example/tree/mr-cicero/cicero-source/corda-iou

The first example compiles to:

        var vp1 = deref(unbrand(vrequest), "value");
        var t2;
        if (!((floatOfNat(vp1) > 0.0))) {
          t2 = {"right" : brand(["org.accordproject.ergo.stdlib.ErgoErrorResponse"],{"message": "The IOU's value must be non-negative."})};
        } else {
          t2 = {"left" : concat(concat({"response": brand(["org.accordproject.cicero.runtime.Response"],{})}, {"state": vlstate}), {"emit": vlemit})};
        }

The second example compiles to:

        var t2;
        if (!(!((compare(deref(unbrand(vrequest), "value"),{"nat": 0.0}) <= 0)))) {
          t2 = {"right" : brand(["org.accordproject.ergo.stdlib.ErgoErrorResponse"],{"message": "The IOU's value must be non-negative."})};
        } else {
          t2 = {"left" : concat(concat({"response": brand(["org.accordproject.cicero.runtime.Response"],{})}, {"state": vlstate}), {"emit": vlemit})};
        }

I'm not able to reproduce this in the REPL.

@mttrbrts mttrbrts added the Type: Bug 🐛 Something isn't working label Sep 18, 2018
@jeromesimeon
Copy link
Member

jeromesimeon commented Sep 19, 2018

I'll assume the issue title should say incorrect

The run-time for integer operations has several issues due to assumptions on the JSON serialization (which can be seen in the {"nat": 0.0} part of the generated code.

Some improvements on the JS code generation in Qcert should help (see #191) but for the time being, we should be able to fix it by revising the ergo runtime for Integer operations.

@mttrbrts mttrbrts changed the title Code generation for >i is correct Code generation for >i is incorrect Sep 19, 2018
@jeromesimeon
Copy link
Member

In PR #458

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants