mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Fix undefined if
This commit is contained in:
42
src/exec.js
42
src/exec.js
@@ -547,15 +547,17 @@ function execFor(ctx, ast) {
|
|||||||
let v = exec(ctx, ast.condition);
|
let v = exec(ctx, ast.condition);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
|
||||||
while ((v.value.neq(0))&&(!ctx.returnValue)) {
|
if (typeof v.value != "undefined") {
|
||||||
exec(ctx, ast.body);
|
while ((v.value.neq(0))&&(!ctx.returnValue)) {
|
||||||
if (ctx.error) return;
|
exec(ctx, ast.body);
|
||||||
|
if (ctx.error) return;
|
||||||
|
|
||||||
exec(ctx, ast.step);
|
exec(ctx, ast.step);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
|
||||||
v = exec(ctx, ast.condition);
|
v = exec(ctx, ast.condition);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,12 +565,14 @@ function execWhile(ctx, ast) {
|
|||||||
let v = exec(ctx, ast.condition);
|
let v = exec(ctx, ast.condition);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
|
||||||
while ((v.value.neq(0))&&(!ctx.returnValue)) {
|
if (typeof v.value != "undefined") {
|
||||||
exec(ctx, ast.body);
|
while ((v.value.neq(0))&&(!ctx.returnValue)) {
|
||||||
if (ctx.error) return;
|
exec(ctx, ast.body);
|
||||||
|
if (ctx.error) return;
|
||||||
|
|
||||||
v = exec(ctx, ast.condition);
|
v = exec(ctx, ast.condition);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,13 +580,15 @@ function execIf(ctx, ast) {
|
|||||||
let v = exec(ctx, ast.condition);
|
let v = exec(ctx, ast.condition);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
|
||||||
if ((v.value.neq(0))&&(!ctx.returnValue)) {
|
if (typeof v.value != "undefined") {
|
||||||
exec(ctx, ast.then);
|
if ((v.value.neq(0))&&(!ctx.returnValue)) {
|
||||||
if (ctx.error) return;
|
exec(ctx, ast.then);
|
||||||
} else {
|
|
||||||
if (ast.else) {
|
|
||||||
exec(ctx, ast.else);
|
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
} else {
|
||||||
|
if (ast.else) {
|
||||||
|
exec(ctx, ast.else);
|
||||||
|
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