Fix constant in struct type (#965)
* add breaking test * implement from constant for uint * tweak * tweak * revert and add breaking test * implement from
This commit is contained in:
parent
c1ded67006
commit
d8ae907030
3 changed files with 23 additions and 3 deletions
11
zokrates_cli/examples/structs/constant_in_member.zok
Normal file
11
zokrates_cli/examples/structs/constant_in_member.zok
Normal file
|
@ -0,0 +1,11 @@
|
|||
const u32 SIZE = 42
|
||||
|
||||
struct Foo {
|
||||
field[SIZE] foo
|
||||
}
|
||||
|
||||
def main():
|
||||
Foo f = Foo {
|
||||
foo: [42; SIZE]
|
||||
}
|
||||
return
|
|
@ -126,7 +126,7 @@ mod tests {
|
|||
|
||||
builder
|
||||
.spawn(|| {
|
||||
for p in glob("./examples/**/!(*.sh)").expect("Failed to read glob pattern") {
|
||||
for p in glob("./examples/**/*").expect("Failed to read glob pattern") {
|
||||
let path = match p {
|
||||
Ok(x) => x,
|
||||
Err(why) => panic!("Error: {:?}", why),
|
||||
|
@ -136,6 +136,10 @@ mod tests {
|
|||
continue;
|
||||
}
|
||||
|
||||
if path.extension().expect("extension expected") == "sh" {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("Testing {:?}", path);
|
||||
assert_eq!(path.extension().expect("extension expected"), "zok");
|
||||
|
||||
|
|
|
@ -969,8 +969,13 @@ pub fn check_type<'ast, S: Clone + PartialEq + PartialEq<usize>>(
|
|||
}
|
||||
|
||||
impl<'ast, T> From<CanonicalConstantIdentifier<'ast>> for UExpression<'ast, T> {
|
||||
fn from(_: CanonicalConstantIdentifier<'ast>) -> Self {
|
||||
unreachable!("constants should have been removed in constant inlining")
|
||||
fn from(c: CanonicalConstantIdentifier<'ast>) -> Self {
|
||||
let bitwidth = match *c.ty {
|
||||
DeclarationType::Uint(bitwidth) => bitwidth,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
UExpressionInner::Identifier(Identifier::from(c.id)).annotate(bitwidth)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue