Skip to content

Commit 8e46880

Browse files
authored
Merge pull request #33298 from xedin/rdar-65413640
[Diagnostics] Detect and diagnose type mismatches related to function…
2 parents 977196f + 9800790 commit 8e46880

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
@@ -3852,6 +3852,11 @@ void constraints::simplifyLocator(ASTNode &anchor,
38523852
break;
38533853
}
38543854

3855+
case ConstraintLocator::FunctionBuilderBodyResult: {
3856+
path = path.slice(1);
3857+
break;
3858+
}
3859+
38553860
default:
38563861
// FIXME: Lots of other cases to handle.
38573862
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)