Skip to content

Commit 9800790

Browse files
committed
[Diagnostics] Detect and diagnose type mismatches related to function builder result
Generic requirement failures are already covered but general type mismatches have to be handled separately. Resolves: rdar://problem/65413640
1 parent aa6e600 commit 9800790

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,11 @@ bool ContextualFailure::diagnoseAsError() {
21862186
return true;
21872187
}
21882188

2189+
case ConstraintLocator::FunctionBuilderBodyResult: {
2190+
diagnostic = *getDiagnosticFor(CTP_Initialization, toType);
2191+
break;
2192+
}
2193+
21892194
default:
21902195
return false;
21912196
}

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,12 @@ bool ConstraintSystem::repairFailures(
44204420
getConstraintLocator(anchor, path));
44214421
}
44224422

4423+
case ConstraintLocator::FunctionBuilderBodyResult: {
4424+
conversionsOrFixes.push_back(ContextualMismatch::create(
4425+
*this, lhs, rhs, getConstraintLocator(locator)));
4426+
break;
4427+
}
4428+
44234429
default:
44244430
break;
44254431
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,11 @@ void constraints::simplifyLocator(ASTNode &anchor,
38533853
break;
38543854
}
38553855

3856+
case ConstraintLocator::FunctionBuilderBodyResult: {
3857+
path = path.slice(1);
3858+
break;
3859+
}
3860+
38563861
default:
38573862
// FIXME: Lots of other cases to handle.
38583863
break;

test/Constraints/function_builder_diags.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,8 @@ struct MyView {
613613
case . // expected-error {{expected ':' after 'case'}}
614614
} // expected-error {{expected identifier after '.' expression}}
615615
}
616+
617+
@TupleBuilder var invalidConversion: Int { // expected-error {{cannot convert value of type 'String' to specified type 'Int'}}
618+
""
619+
}
616620
}

0 commit comments

Comments
 (0)