diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-28 13:38:37 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-28 13:38:37 +0100 |
| commit | 3749ba3c8d545400dc595dd9c973b6c409c27874 (patch) | |
| tree | 6cc59d2f8d0617e1ea66d33b43e16e56b72ebe23 /src | |
| parent | 2acc93baf9964a310f8341a864e10b0bfcc30b9e (diff) | |
Include unrecognised variant tag in error message
Diffstat (limited to 'src')
2 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java index 65bfdfe..5c4c22c 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/javatransient0/JavaTransient0Generator.java @@ -653,6 +653,7 @@ public class JavaTransient0Generator implements Generator { enumDefinition.type(), new JavaBlock(Stream.concat( generateDecode(ordinal, NativeTypes.INT_32, context).stream(), + // TODO: handle ordinal not in array Stream.of(new JavaReturn(new JavaArrayAccess( new JavaRef(enumValues), new JavaRef(ordinal) 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 354dfb5..46e0a5c 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 @@ -441,8 +441,11 @@ public class RustTransient0Generator implements Generator { .collect(toArrayList()); decodeMatchArms.add(new RustMatchArm( - new RustWildcardPattern(), - new RustTryPropagationExpression(generateUnrecognisedVariantResult(enumDefinition.type())) + new RustIdentifierPattern(RustIdentifier.of("tag")), + new RustTryPropagationExpression(generateUnrecognisedVariantResult( + enumDefinition.type(), + RustPath.of("tag") + )) )); return generateDecodeFunction( @@ -584,8 +587,11 @@ public class RustTransient0Generator implements Generator { .collect(toArrayList()); decodeMatchArms.add(new RustMatchArm( - new RustWildcardPattern(), - new RustTryPropagationExpression(generateUnrecognisedVariantResult(sumDefinition.type())) + new RustIdentifierPattern(RustIdentifier.of("tag")), + new RustTryPropagationExpression(generateUnrecognisedVariantResult( + sumDefinition.type(), + RustPath.of("tag") + )) )); return generateDecodeFunction( @@ -1347,7 +1353,10 @@ public class RustTransient0Generator implements Generator { ); } - private static RustCallExpression generateUnrecognisedVariantResult(Type type) { + private static RustCallExpression generateUnrecognisedVariantResult( + Type type, + RustExpression tag + ) { return new RustCallExpression( RustTypes.RESULT_ERR, List.of( @@ -1355,8 +1364,13 @@ public class RustTransient0Generator implements Generator { 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()) + new RustCallExpression( + RustPath.of("format!"), + List.of( + new RustStringLiteral("unrecognised variant tag for " + type.describe() + ": {}"), + tag + ) + ) ) ) ) |
