diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-02 13:20:14 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-02 13:20:14 +0100 |
| commit | bca17d7fd0be82de7701b74a5384febe71bc12ef (patch) | |
| tree | c4047625e76edf48daaeb2e37f90c353c2a11a74 /src | |
| parent | 157675d122e806bb1dd9f655135f1b856090bbbd (diff) | |
Don't panic on unrecognised enum variant tag
Diffstat (limited to 'src')
2 files changed, 16 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java index 20b21de..ec39245 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java @@ -379,7 +379,19 @@ public class RustTransient0Generator implements Generator { decodeMatchArms.add(new RustMatchArm( new RustWildcardPattern(), - generateTodo() + new RustTryPropagationExpression(new RustCallExpression( + RustTypes.RESULT_ERR, + List.of( + new RustCallExpression( + RustTypes.IO_ERROR.addSegment(RustPathSegment.of("new")), + List.of( + RustTypes.IO_ERROR_KIND_INVALID_DATA, + // TODO: include variant tag + new RustStringLiteral("unrecognised variant tag") + ) + ) + ) + )) )); return generateDecodeFunction( diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java index 5e6303a..3c5ab6c 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java @@ -49,6 +49,9 @@ public class RustTypes { public static RustPath NONE = RustPath.global("std", "option", "Option", "None"); public static RustPath SOME = RustPath.global("std", "option", "Option", "Some"); + public static RustPath RESULT = RustPath.global("std", "result", "Result"); + public static RustPath RESULT_ERR = RESULT.addSegment(RustPathSegment.of("Err")); + public static RustPath STRING = RustPath.global("std", "string", "String"); public static RustPath ARC = RustPath.global("std", "sync", "Arc"); |
