Skip to content

Commit 0a9c577

Browse files
authored
Merge pull request #81938 from hamishknight/hastype-6.2
[6.2] [CS] Check `hasType` in `isPlaceholderVar`
2 parents 91c9292 + 47959ac commit 0a9c577

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,11 +2744,13 @@ Type constraints::isPlaceholderVar(PatternBindingDecl *PB) {
27442744
return Type();
27452745

27462746
auto *pattern = PB->getPattern(0);
2747-
if (auto *typedPattern = dyn_cast<TypedPattern>(pattern)) {
2748-
auto type = typedPattern->getType();
2749-
if (type && type->hasPlaceholder())
2750-
return type;
2751-
}
2747+
auto *typedPattern = dyn_cast<TypedPattern>(pattern);
2748+
if (!typedPattern || !typedPattern->hasType())
2749+
return Type();
2750+
2751+
auto type = typedPattern->getType();
2752+
if (!type->hasPlaceholder())
2753+
return Type();
27522754

2753-
return Type();
2755+
return type;
27542756
}

test/Constraints/rdar146383201.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -typecheck -verify -primary-file %t/a.swift %t/b.swift -plugin-path %swift-plugin-dir
5+
6+
//--- a.swift
7+
8+
func foo() {
9+
_ = {
10+
let i = 0
11+
$bar.withValue(i) {}
12+
}
13+
}
14+
15+
//--- b.swift
16+
17+
@TaskLocal
18+
var bar: Int?

0 commit comments

Comments
 (0)