mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-07 03:06:42 +01:00
Fix undefined if
This commit is contained in:
@@ -547,6 +547,7 @@ function execFor(ctx, ast) {
|
||||
let v = exec(ctx, ast.condition);
|
||||
if (ctx.error) return;
|
||||
|
||||
if (typeof v.value != "undefined") {
|
||||
while ((v.value.neq(0))&&(!ctx.returnValue)) {
|
||||
exec(ctx, ast.body);
|
||||
if (ctx.error) return;
|
||||
@@ -557,12 +558,14 @@ function execFor(ctx, ast) {
|
||||
v = exec(ctx, ast.condition);
|
||||
if (ctx.error) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function execWhile(ctx, ast) {
|
||||
let v = exec(ctx, ast.condition);
|
||||
if (ctx.error) return;
|
||||
|
||||
if (typeof v.value != "undefined") {
|
||||
while ((v.value.neq(0))&&(!ctx.returnValue)) {
|
||||
exec(ctx, ast.body);
|
||||
if (ctx.error) return;
|
||||
@@ -570,12 +573,14 @@ function execWhile(ctx, ast) {
|
||||
v = exec(ctx, ast.condition);
|
||||
if (ctx.error) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function execIf(ctx, ast) {
|
||||
let v = exec(ctx, ast.condition);
|
||||
if (ctx.error) return;
|
||||
|
||||
if (typeof v.value != "undefined") {
|
||||
if ((v.value.neq(0))&&(!ctx.returnValue)) {
|
||||
exec(ctx, ast.then);
|
||||
if (ctx.error) return;
|
||||
@@ -585,6 +590,7 @@ function execIf(ctx, ast) {
|
||||
if (ctx.error) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
14
test/cases.js
Normal file
14
test/cases.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
const snarkjs = require("snarkjs");
|
||||
const crypto = require("crypto");
|
||||
|
||||
const compiler = require("../index.js");
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
describe("Sum test", () => {
|
||||
it("Should compile a code with an undefined if", async() => {
|
||||
await compiler(path.join(__dirname, "circuits", "undefinedif.circom"));
|
||||
});
|
||||
});
|
||||
14
test/circuits/undefinedif.circom
Normal file
14
test/circuits/undefinedif.circom
Normal file
@@ -0,0 +1,14 @@
|
||||
template X() {
|
||||
signal input i;
|
||||
signal input j;
|
||||
signal output out;
|
||||
|
||||
if (i == 0) {
|
||||
out <-- i;
|
||||
}
|
||||
else {
|
||||
out <-- j;
|
||||
}
|
||||
}
|
||||
|
||||
component main = X();
|
||||
Reference in New Issue
Block a user