Skip to content

[5.5][TypeChecker] Clear param specifiers before re-typechecking expression for completion #37310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ class SanitizeExpr : public ASTWalker {
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
if (!shouldTypeCheckInEnclosingExpression(closure))
return { false, expr };
for (auto &Param : *closure->getParameters()) {
Param->setSpecifier(swift::ParamSpecifier::Default);
}
}

// Now, we're ready to walk into sub expressions.
Expand Down
37 changes: 37 additions & 0 deletions validation-test/IDE/crashers_2_fixed/sr14494.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE -source-filename=%s | %FileCheck %s

protocol MyView {
associatedtype Body : MyView
@MyViewBuilder var body: Self.Body { get }
}

@resultBuilder public struct MyViewBuilder {
static func buildBlock() -> MyZStack<Never> { fatalError() }
static func buildBlock<Content>(_ content: Content) -> Content { content }
}

struct MyAlignment {
static let center: MyAlignment
}

struct MyZStack<Content> : MyView {
init(alignment: MyAlignment, @MyViewBuilder content: () -> Content) {
fatalError()
}

func my_updating<State>(body: (inout State) -> Void) {}
}

struct BottomMenu: MyView {
var body: some MyView {
let a = MyZStack(alignment: .#^COMPLETE^#center, content: {})
.my_updating(body: { state in
state = false
})
}
}

// CHECK: Begin completions, 2 items
// CHECK: Decl[StaticVar]/ExprSpecific/TypeRelation[Identical]: center[#MyAlignment#]; name=center
// CHECK: Decl[Constructor]/CurrNominal/TypeRelation[Identical]: init()[#MyAlignment#]; name=init()
// CHECK: End completions