Skip to content

Commit eb07d54

Browse files
authored
Merge pull request #40512 from CodaFi/art-decl
Fully Check Decls in Result Builders
2 parents 0a427a3 + 232c51c commit eb07d54

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,15 @@ class BuilderClosureRewriter
11221122
if (!resultTarget)
11231123
continue;
11241124

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

@@ -1226,13 +1231,15 @@ class BuilderClosureRewriter
12261231
// Skip variable declarations; they're always part of a pattern
12271232
// binding.
12281233
if (isa<VarDecl>(decl)) {
1234+
TypeChecker::typeCheckDecl(decl);
12291235
newElements.push_back(decl);
12301236
continue;
12311237
}
12321238

12331239
// Handle pattern bindings.
12341240
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
12351241
finishPatternBindingDecl(patternBinding);
1242+
TypeChecker::typeCheckDecl(decl);
12361243
newElements.push_back(decl);
12371244
continue;
12381245
}

test/Constraints/result_builder_diags.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,14 @@ func test_missing_member_in_optional_context() {
815815
}
816816
}
817817
}
818+
819+
func test_redeclations() {
820+
tuplify(true) { c in
821+
let foo = 0 // expected-note {{'foo' previously declared here}}
822+
let foo = foo // expected-error {{invalid redeclaration of 'foo'}}
823+
}
824+
825+
tuplify(true) { c in
826+
let (foo, foo) = (5, 6) // expected-error {{invalid redeclaration of 'foo'}} expected-note {{'foo' previously declared here}}
827+
}
828+
}

0 commit comments

Comments
 (0)