Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @length-constrained collection shapes whose members are not constrained #2103

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.next.toml
Expand Up @@ -9,4 +9,10 @@
# message = "Fix typos in module documentation for generated crates"
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"
# author = "rcoh"

[[smithy-rs]]
message = "In 0.52, `@length`-constrained collection shapes whose members are not constrained made the server code generator crash. This has been fixed."
references = ["smithy-rs#2103"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "server"}
author = "david-perez"
12 changes: 8 additions & 4 deletions codegen-core/common-test-models/constraints.smithy
Expand Up @@ -837,21 +837,25 @@ list RecursiveList {
}

list ConBList {
member: LengthList
member: ConBListInner
}

list ConBListInner {
member: ConB
}

@length(max: 69)
list LengthList {
member: ConB
member: String
}

// TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is
// just a `list` shape with `uniqueItems`, which hasn't been implemented yet.
// set ConBSet {
// member: NestedSet
// member: ConBSetInner
// }
//
// set NestedSet {
// set ConBSetInner {
// member: String
// }

Expand Down
Expand Up @@ -106,7 +106,9 @@ class ConstraintViolationSymbolProvider(
}

override fun toSymbol(shape: Shape): Symbol {
check(shape.canReachConstrainedShape(model, base))
check(shape.canReachConstrainedShape(model, base)) {
"`ConstraintViolationSymbolProvider` was called on shape that does not reach a constrained shape: $shape"
}

return when (shape) {
is MapShape, is CollectionShape, is UnionShape -> {
Expand Down
Expand Up @@ -89,8 +89,6 @@ class UnconstrainedCollectionGenerator(
}

private fun renderTryFromUnconstrainedForConstrained(writer: RustWriter) {
val innerConstraintViolationSymbol = constraintViolationSymbolProvider.toSymbol(innerShape)

writer.rustBlock("impl std::convert::TryFrom<$name> for #{T}", constrainedSymbol) {
rust("type Error = #T;", constraintViolationSymbol)

Expand All @@ -106,6 +104,7 @@ class UnconstrainedCollectionGenerator(
} else {
constrainedShapeSymbolProvider.toSymbol(innerShape)
}
val innerConstraintViolationSymbol = constraintViolationSymbolProvider.toSymbol(innerShape)

rustTemplate(
"""
Expand Down