[CS] Check hasType in isPlaceholderVar

Patterns assert that a type is set in `getType`, check `hasType`
before querying.

rdar://146383201
This commit is contained in:
Hamish Knight
2025-06-02 13:56:02 +01:00
parent d49dd182ed
commit 9cad10ddcd
2 changed files with 26 additions and 6 deletions

View File

@@ -2744,11 +2744,13 @@ Type constraints::isPlaceholderVar(PatternBindingDecl *PB) {
return Type();
auto *pattern = PB->getPattern(0);
if (auto *typedPattern = dyn_cast<TypedPattern>(pattern)) {
auto type = typedPattern->getType();
if (type && type->hasPlaceholder())
return type;
}
auto *typedPattern = dyn_cast<TypedPattern>(pattern);
if (!typedPattern || !typedPattern->hasType())
return Type();
return Type();
auto type = typedPattern->getType();
if (!type->hasPlaceholder())
return Type();
return type;
}

View File

@@ -0,0 +1,18 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -typecheck -verify -primary-file %t/a.swift %t/b.swift -plugin-path %swift-plugin-dir
//--- a.swift
func foo() {
_ = {
let i = 0
$bar.withValue(i) {}
}
}
//--- b.swift
@TaskLocal
var bar: Int?