Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: yowl <[email protected]>
Co-authored-by: Joel Dice <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent d77a265 commit 4dab24c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions crates/csharp/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
uwrite!(
self.src,
"\
if ({previous}.IsOk) {{
if ({previous}.IsOk)
{{
var {tmp} = {previous}.AsOk;
"
);
Expand Down Expand Up @@ -272,7 +273,9 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
uwrite!(
self.src,
"\
}} else {{
}}
else
{{
throw new {exception_name}({var_name}.AsErr!, {level});
}}
"
Expand Down Expand Up @@ -317,7 +320,8 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
let tail = oks.iter().map(|_| ")").collect::<Vec<_>>().concat();
cases.push(format!(
"\
case {index}: {{
case {index}:
{{
ret = {head}{ty}.Err(({err_ty}) e.Value){tail};
break;
}}
Expand All @@ -327,7 +331,9 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
payload_is_void = result.ok.is_none();
}
if !self.results.is_empty() {
self.src.push_str("try {\n");
self.src.push_str(\"
try
{\n");
}
let head = oks.concat();
let tail = oks.iter().map(|_| ")").collect::<Vec<_>>().concat();
Expand All @@ -343,8 +349,11 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
let cases = cases.join("\n");
uwriteln!(
self.src,
r#"}} catch (WitException e) {{
switch (e.NestingLevel) {{
r#"}}
catch (WitException e)
{{
switch (e.NestingLevel)
{{
{cases}
default: throw new ArgumentException($"invalid nesting level: {{e.NestingLevel}}");
Expand Down
2 changes: 1 addition & 1 deletion crates/csharp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Opts {
#[cfg_attr(feature = "clap", arg(long))]
pub skip_support_files: bool,

/// Generates code for wit Result types instead of exceptions
/// Generate code for WIT `Result` types instead of exceptions
#[cfg_attr(feature = "clap", arg(long))]
pub with_wit_results: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/runtime/results/wasm_with_wit_results.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static Result<float, string> StringError(float a)
var result = imports.test.results.TestInterop.EnumError(a);
if (result.IsOk) {
return Result<float, ITest.E>.Ok(result.AsOk);
}else{
} else {
switch (result.AsErr){
case imports.test.results.ITest.E.A:
return Result<float, ITest.E>.Err(ITest.E.A);
Expand Down

0 comments on commit 4dab24c

Please sign in to comment.