Skip to content

Commit

Permalink
fix(tiny-go): fix generated code in type_flags function (#911)
Browse files Browse the repository at this point in the history
* add testcase for when flags have dashes

Signed-off-by: Rajat Jindal <rajatjindal83@gmail.com>

* fix(tiny-go): fix generated code in type_flags function

Signed-off-by: Rajat Jindal <rajatjindal83@gmail.com>

---------

Signed-off-by: Rajat Jindal <rajatjindal83@gmail.com>
  • Loading branch information
rajatjindal committed Mar 28, 2024
1 parent b4b56c0 commit ed26dbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/go/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,17 +1179,19 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.src.push_str(&format!("type {name} uint64\n"));
self.src.push_str("const (\n");
for (i, flag) in flags.flags.iter().enumerate() {
let case_flag = flag.name.to_upper_camel_case();

if i == 0 {
self.src.push_str(&format!(
" {name}_{flag} {name} = 1 << iota\n",
name = name,
flag = flag.name.to_uppercase(),
flag = case_flag,
));
} else {
self.src.push_str(&format!(
" {name}_{flag}\n",
name = name,
flag = flag.name.to_uppercase(),
flag = case_flag,
));
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/codegen/flags.wit
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ interface %flags {
b56, b57, b58, b59, b60, b61, b62, b63,
}

flags withdashes {
with-dashes,
}

roundtrip-flag1: func(x: flag1) -> flag1;
roundtrip-flag2: func(x: flag2) -> flag2;
roundtrip-flag4: func(x: flag4) -> flag4;
Expand Down

0 comments on commit ed26dbf

Please sign in to comment.