Skip to content

Commit b3ba156

Browse files
authored
Fix JMESPath integer literal handling (#4500)
## Description Smithy 1.66.0 changed JMESPath parsing to return `Long` for integer literals instead of `Double`. This broke our codegen which checked `is Double`. ## Changes - Use `expr.type` instead of `expr.value` for type matching - Use `RuntimeType.NUMBER` instead of `is Double` - Use `expr.expectNumberValue()` to get the value ## Testing - Verified tests pass with Smithy 1.63.0 (current) - Verified tests pass with Smithy 1.66.0 (the breaking version)
1 parent 9d6b6a1 commit b3ba156

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
applies_to:
3+
- client
4+
- aws-sdk-rust
5+
authors:
6+
- vcjana
7+
references:
8+
- smithy-rs#4500
9+
breaking: false
10+
new_feature: false
11+
bug_fix: true
12+
---
13+
Fix JMESPath integer literal handling in waiters to support Smithy 1.66.0, which parses integer literals as `Long` instead of `Double`.

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/waiters/RustJmespathShapeTraversalGenerator.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.waiters
66

77
import software.amazon.smithy.jmespath.ExpressionSerializer
88
import software.amazon.smithy.jmespath.JmespathExpression
9+
import software.amazon.smithy.jmespath.RuntimeType
910
import software.amazon.smithy.jmespath.ast.AndExpression
1011
import software.amazon.smithy.jmespath.ast.BinaryExpression
1112
import software.amazon.smithy.jmespath.ast.ComparatorExpression
@@ -568,23 +569,23 @@ class RustJmespathShapeTraversalGenerator(
568569

569570
private fun generateLiteral(expr: LiteralExpression): GeneratedExpression {
570571
val (outputShape, outputType) =
571-
when (expr.value) {
572-
is Boolean -> TraversedShape.Bool(null) to RustType.Reference(lifetime = null, member = RustType.Bool)
573-
is Double ->
572+
when (expr.type) {
573+
RuntimeType.BOOLEAN -> TraversedShape.Bool(null) to RustType.Reference(lifetime = null, member = RustType.Bool)
574+
RuntimeType.NUMBER ->
574575
TraversedShape.Number(null) to
575576
RustType.Reference(
576577
lifetime = null,
577578
member = RustType.Float(64),
578579
)
579580

580-
is String ->
581+
RuntimeType.STRING ->
581582
TraversedShape.String(null) to
582583
RustType.Reference(
583584
lifetime = null,
584585
member = RustType.Opaque("str"),
585586
)
586587

587-
null -> throw UnsupportedJmesPathException("Literal nulls are not supported by smithy-rs")
588+
RuntimeType.NULL -> throw UnsupportedJmesPathException("Literal nulls are not supported by smithy-rs")
588589
else -> throw UnsupportedJmesPathException("Literal expression '${ExpressionSerializer().serialize(expr)}' is not supported by smithy-rs")
589590
}
590591

@@ -598,13 +599,13 @@ class RustJmespathShapeTraversalGenerator(
598599
outputShape = outputShape,
599600
output =
600601
writable {
601-
when (val value = expr.value) {
602-
is Boolean -> rust("const $ident: &bool = &$value;")
603-
is Double -> {
604-
rust("const $ident: #T = &${fmtFloating(value)};", outputType)
602+
when (expr.type) {
603+
RuntimeType.BOOLEAN -> rust("const $ident: &bool = &${expr.expectBooleanValue()};")
604+
RuntimeType.NUMBER -> {
605+
rust("const $ident: #T = &${fmtFloating(expr.expectNumberValue())};", outputType)
605606
}
606607

607-
is String -> rust("const $ident: &str = ${value.dq()};")
608+
RuntimeType.STRING -> rust("const $ident: &str = ${expr.expectStringValue().dq()};")
608609
else -> throw RuntimeException("unreachable")
609610
}
610611
},

0 commit comments

Comments
 (0)