Skip to content

Commit 58e66d2

Browse files
authored
Merge pull request #85570 from hamishknight/binding-fixes-6.3
[6.3] [Sema] A couple of binding-related crasher fixes
2 parents 51d2974 + 3f30985 commit 58e66d2

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,8 @@ AnnotatedInsertionPoint
959959
ConditionalClausePatternUseScope::expandAScopeThatCreatesANewInsertionPoint(
960960
ScopeCreator &scopeCreator) {
961961
auto *initializer = sec.getInitializer();
962-
if (!isa<ErrorExpr>(initializer)) {
963-
scopeCreator
964-
.constructExpandAndInsert<ConditionalClauseInitializerScope>(
965-
this, initializer);
966-
}
962+
scopeCreator.constructExpandAndInsert<ConditionalClauseInitializerScope>(
963+
this, initializer);
967964

968965
return {this,
969966
"Succeeding code must be in scope of conditional clause pattern bindings"};

lib/Sema/CSGen.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,16 @@ namespace {
31533153
}
31543154

31553155
case PatternKind::Expr: {
3156+
// Make sure we invalidate any nested VarDecls early since generating
3157+
// constraints for a `where` clause may happen before we've generated
3158+
// constraints for the ExprPattern. We'll record a fix when visiting
3159+
// the UnresolvedPatternExpr.
3160+
// FIXME: We ought to use a conjunction for switch cases, then we
3161+
// wouldn't need this logic.
3162+
auto *EP = cast<ExprPattern>(pattern);
3163+
EP->getSubExpr()->forEachUnresolvedVariable([&](VarDecl *VD) {
3164+
CS.setType(VD, ErrorType::get(CS.getASTContext()));
3165+
});
31563166
// We generate constraints for ExprPatterns in a separate pass. For
31573167
// now, just create a type variable.
31583168
return setType(CS.createTypeVariable(CS.getConstraintLocator(locator),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// {"kind":"typecheck","signature":"swift::constraints::ConstraintSystem::getTypeOfReferencePre(swift::constraints::OverloadChoice, swift::DeclContext*, swift::constraints::ConstraintLocatorBuilder, swift::constraints::PreparedOverloadBuilder*)","signatureAssert":"Assertion failed: (func->isOperator() && \"Lookup should only find operators\"), function getTypeOfReferencePre"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
{
4+
switch if .random() else {
5+
}
6+
{
7+
case let !a where a:
8+
}
9+
}

validation-test/compiler_crashers/ConstraintWalker-walkToExprPost-c956e0.swift renamed to validation-test/compiler_crashers_fixed/ConstraintWalker-walkToExprPost-c956e0.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","original":"1562769e","signature":"(anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
enum c
44
func d() e {
55
if let
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// {"kind":"typecheck","signature":"swift::constraints::TypeVarRefCollector::walkToStmtPre(swift::Stmt*)","signatureAssert":"Assertion failed: (result), function getClosureType"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
{
4+
guard let a = (a if{
5+
return
6+
}
7+
) "
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// {"kind":"typecheck","signature":"swift::constraints::TypeVarRefCollector::walkToStmtPre(swift::Stmt*)","signatureAssert":"Assertion failed: (result), function getClosureType"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
{
4+
switch if <#expression#> {
5+
return
6+
}
7+
{
8+
case let !a where a:
9+
}
10+
}

0 commit comments

Comments
 (0)