Skip to content

Fully Check Decls in Result Builders #40512

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
Dec 16, 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
9 changes: 8 additions & 1 deletion lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,15 @@ class BuilderClosureRewriter
if (!resultTarget)
continue;

// FIXME: It's unfortunate that we're duplicating code from CSApply here.
// If there were a request for the fully-typechecked initializer of a
// pattern binding we may be able to eliminate the duplication here.
patternBinding->setPattern(
index, resultTarget->getInitializationPattern(),
resultTarget->getDeclContext());
resultTarget->getDeclContext(),
/*isFullyValidated=*/true);
patternBinding->setInit(index, resultTarget->getAsExpr());
patternBinding->setInitializerChecked(index);
}
}

Expand Down Expand Up @@ -1226,13 +1231,15 @@ class BuilderClosureRewriter
// Skip variable declarations; they're always part of a pattern
// binding.
if (isa<VarDecl>(decl)) {
TypeChecker::typeCheckDecl(decl);
newElements.push_back(decl);
continue;
}

// Handle pattern bindings.
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
finishPatternBindingDecl(patternBinding);
TypeChecker::typeCheckDecl(decl);
newElements.push_back(decl);
continue;
}
Expand Down
11 changes: 11 additions & 0 deletions test/Constraints/result_builder_diags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,14 @@ func test_missing_member_in_optional_context() {
}
}
}

func test_redeclations() {
tuplify(true) { c in
let foo = 0 // expected-note {{'foo' previously declared here}}
let foo = foo // expected-error {{invalid redeclaration of 'foo'}}
}

tuplify(true) { c in
let (foo, foo) = (5, 6) // expected-error {{invalid redeclaration of 'foo'}} expected-note {{'foo' previously declared here}}
}
}