Regression issue? #2002
-
I'm very new and going through https://noir-by-example.org/examples/comptime/. This particular one gave unexpected result, and I'm a bit lost where it's better to report among repos. fn main() -> pub Field {
let known_at_compile_time: comptime Field = 1;
// let inferred_known = 2;
let mut bad_var: comptime Field = 3;
bad_var = 4;
// known_at_compile_time + inferred_known
known_at_compile_time + bad_var
}
#[test]
fn test_main() {
assert(main() == 5);
} devbox@pop-os:~/projects/hello_world$ nargo test --show-output
Running 1 test functions...
Testing test_main...
ok
All tests passed Ran both with plain |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Seems that it's behaving as it should be (i.e. 1 + 4 = 5)? |
Beta Was this translation helpful? Give feedback.
-
I think this may be an error in the docs as A better example would be if you had a program similar to below fn main(runtime_var: Field) -> pub Field {
let known_at_compile_time: comptime Field = 1;
// let inferred_known = 2;
let bad_var: comptime Field = runtime_var;
// known_at_compile_time + inferred_known
known_at_compile_time + bad_var
} As |
Beta Was this translation helpful? Give feedback.
I think this may be an error in the docs as
bad_var
's value is known for every step of program execution at compile time (the definition of acomptime
variable).A better example would be if you had a program similar to below
As
runtime_var
is a argument to the circuit it cannot be known at compile time and so assigning it to acomptime
variable should fail. A circuit's arguments is the only way in which non-comptime variables can…