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: Supply explicit type on forEach block to try preventing compiler crash #801

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ class MiddlewareExecutionGenerator(
}
""".trimIndent()
)
// Swift can't infer the generic arguments to `create` for some reason
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol Swift can't infer the generic arguments to create because it has nothing to infer from, unless you explicitly give a type for the variable the return value will be assigned to.

writer.write(
"""
config.httpInterceptorProviders.forEach { provider in
let i: any ${'$'}N<${'$'}N, ${'$'}N> = provider.create()
builder.interceptors.add(i)
}
""".trimIndent(),
ClientRuntimeTypes.Core.HttpInterceptor,
inputShape,
outputShape,
)
writer.openBlock(
"config.httpInterceptorProviders.forEach { (provider: any \$N) -> Void in",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up the multiline write() call while adding the type info to the forEach body block.

"}",
ClientRuntimeTypes.Core.HttpInterceptorProvider,
) {
writer.write(
"let i: any \$N<\$N, \$N> = provider.create()",
ClientRuntimeTypes.Core.HttpInterceptor,
inputShape,
outputShape,
)
writer.write("builder.interceptors.add(i)")
}

renderMiddlewares(ctx, op, operationStackName)

Expand Down
2 changes: 1 addition & 1 deletion smithy-swift-codegen/src/test/kotlin/EventStreamTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ extension EventStreamTestClientTypes.TestStream {
config.interceptorProviders.forEach { provider in
builder.interceptors.add(provider.create())
}
config.httpInterceptorProviders.forEach { provider in
config.httpInterceptorProviders.forEach { (provider: any ClientRuntime.HttpInterceptorProvider) -> Void in
let i: any ClientRuntime.HttpInterceptor<TestStreamOpInput, TestStreamOpOutput> = provider.create()
builder.interceptors.add(i)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ extension RestJsonProtocolClient {
config.interceptorProviders.forEach { provider in
builder.interceptors.add(provider.create())
}
config.httpInterceptorProviders.forEach { provider in
config.httpInterceptorProviders.forEach { (provider: any ClientRuntime.HttpInterceptorProvider) -> Void in
let i: any ClientRuntime.HttpInterceptor<AllocateWidgetInput, AllocateWidgetOutput> = provider.create()
builder.interceptors.add(i)
}
Expand Down
Loading