1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00

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:
Thibaut Schaeffer 2021-08-16 10:44:00 +02:00 committed by GitHub
parent c1ded67006
commit d8ae907030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -0,0 +1,11 @@
const u32 SIZE = 42
struct Foo {
field[SIZE] foo
}
def main():
Foo f = Foo {
foo: [42; SIZE]
}
return

View file

@ -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");

View file

@ -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)
}
}