[ASTGen] Wrap optional binding pattern with type annotation

This commit is contained in:
Rintaro Ishizaki
2025-02-20 12:12:35 -08:00
parent a3d699241c
commit c460947a73
2 changed files with 19 additions and 0 deletions

View File

@@ -161,6 +161,14 @@ extension ASTGenVisitor {
// I'm not sure this should really be implicit.
pat.setImplicit()
if let typeAnnotation = node.typeAnnotation {
pat = BridgedTypedPattern.createParsed(
self.ctx,
pattern: pat,
type: self.generate(type: typeAnnotation.type)
).asPattern
}
let initializer: BridgedExpr
if let initNode = node.initializer {
initializer = self.generate(expr: initNode.value)

View File

@@ -116,6 +116,17 @@ func testThen() {
}
}
func intOrString() -> Int? { 1 }
func intOrString() -> String? { "" }
func testIf() {
if
let i: Int = intOrString(),
case let str? = intOrString() as String?
{
_ = (i, str)
}
}
struct GenericTypeWithYields<T> {
var storedProperty: T?