Skip to content

Commit 57e154b

Browse files
authored
fix: Supply explicit type on forEach block to try preventing compiler crash (#801)
1 parent 5cfec7b commit 57e154b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/middleware/MiddlewareExecutionGenerator.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ class MiddlewareExecutionGenerator(
5858
}
5959
""".trimIndent()
6060
)
61-
// Swift can't infer the generic arguments to `create` for some reason
62-
writer.write(
63-
"""
64-
config.httpInterceptorProviders.forEach { provider in
65-
let i: any ${'$'}N<${'$'}N, ${'$'}N> = provider.create()
66-
builder.interceptors.add(i)
67-
}
68-
""".trimIndent(),
69-
ClientRuntimeTypes.Core.HttpInterceptor,
70-
inputShape,
71-
outputShape,
72-
)
61+
writer.openBlock(
62+
"config.httpInterceptorProviders.forEach { (provider: any \$N) -> Void in",
63+
"}",
64+
ClientRuntimeTypes.Core.HttpInterceptorProvider,
65+
) {
66+
writer.write(
67+
"let i: any \$N<\$N, \$N> = provider.create()",
68+
ClientRuntimeTypes.Core.HttpInterceptor,
69+
inputShape,
70+
outputShape,
71+
)
72+
writer.write("builder.interceptors.add(i)")
73+
}
7374

7475
renderMiddlewares(ctx, op, operationStackName)
7576

smithy-swift-codegen/src/test/kotlin/EventStreamTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ extension EventStreamTestClientTypes.TestStream {
218218
config.interceptorProviders.forEach { provider in
219219
builder.interceptors.add(provider.create())
220220
}
221-
config.httpInterceptorProviders.forEach { provider in
221+
config.httpInterceptorProviders.forEach { (provider: any ClientRuntime.HttpInterceptorProvider) -> Void in
222222
let i: any ClientRuntime.HttpInterceptor<TestStreamOpInput, TestStreamOpOutput> = provider.create()
223223
builder.interceptors.add(i)
224224
}

smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extension RestJsonProtocolClient {
158158
config.interceptorProviders.forEach { provider in
159159
builder.interceptors.add(provider.create())
160160
}
161-
config.httpInterceptorProviders.forEach { provider in
161+
config.httpInterceptorProviders.forEach { (provider: any ClientRuntime.HttpInterceptorProvider) -> Void in
162162
let i: any ClientRuntime.HttpInterceptor<AllocateWidgetInput, AllocateWidgetOutput> = provider.create()
163163
builder.interceptors.add(i)
164164
}

0 commit comments

Comments
 (0)