summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-02 13:23:34 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-02 13:23:34 +0100
commit399aef569ddedcb58dcb394b394d55f20c78ee83 (patch)
tree218ce477a079e8f0a96a85a98f085a8c1704dd3d /src/main/java
parent213944fe850e0770efe4a73b97d95c9f5df3c9c1 (diff)
Don't panic on unrecognised sum variant tag
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java32
1 files changed, 18 insertions, 14 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 fed710f..b70752e 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,19 +379,7 @@ public class RustTransient0Generator implements Generator {
decodeMatchArms.add(new RustMatchArm(
new RustWildcardPattern(),
- 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 for " + enumDefinition.type().describe())
- )
- )
- )
- ))
+ new RustTryPropagationExpression(generateUnrecognisedVariantResult(enumDefinition.type()))
));
return generateDecodeFunction(
@@ -512,7 +500,7 @@ public class RustTransient0Generator implements Generator {
decodeMatchArms.add(new RustMatchArm(
new RustWildcardPattern(),
- generateTodo()
+ new RustTryPropagationExpression(generateUnrecognisedVariantResult(sumDefinition.type()))
));
return generateDecodeFunction(
@@ -1104,6 +1092,22 @@ public class RustTransient0Generator implements Generator {
);
}
+ private static RustCallExpression generateUnrecognisedVariantResult(Type type) {
+ return 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 for " + type.describe())
+ )
+ )
+ )
+ );
+ }
+
private RustExpression tryIntoOrInvalidData(RustExpression value) {
return new RustTryPropagationExpression(mapErrToInvalidData(
methodCall(