diff --git a/lib/Sema/CSSyntacticElement.cpp b/lib/Sema/CSSyntacticElement.cpp index 36bdcd3c2f224..b5bd5cb5663f9 100644 --- a/lib/Sema/CSSyntacticElement.cpp +++ b/lib/Sema/CSSyntacticElement.cpp @@ -2744,11 +2744,13 @@ Type constraints::isPlaceholderVar(PatternBindingDecl *PB) { return Type(); auto *pattern = PB->getPattern(0); - if (auto *typedPattern = dyn_cast(pattern)) { - auto type = typedPattern->getType(); - if (type && type->hasPlaceholder()) - return type; - } + auto *typedPattern = dyn_cast(pattern); + if (!typedPattern || !typedPattern->hasType()) + return Type(); + + auto type = typedPattern->getType(); + if (!type->hasPlaceholder()) + return Type(); - return Type(); + return type; } diff --git a/test/Constraints/rdar146383201.swift b/test/Constraints/rdar146383201.swift new file mode 100644 index 0000000000000..1e26e05741375 --- /dev/null +++ b/test/Constraints/rdar146383201.swift @@ -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?