Skip to content

Commit 80f8731

Browse files
authored
Merge pull request #33299 from xedin/rdar-65413640-5.3
[5.3][Diagnostics] Detect and diagnose type mismatches related to function…
2 parents 94929b6 + 6ccd013 commit 80f8731

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
@@ -2107,6 +2107,11 @@ bool ContextualFailure::diagnoseAsError() {
21072107
return true;
21082108
}
21092109

2110+
case ConstraintLocator::FunctionBuilderBodyResult: {
2111+
diagnostic = *getDiagnosticFor(CTP_Initialization, toType);
2112+
break;
2113+
}
2114+
21102115
default:
21112116
return false;
21122117
}

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,6 +4264,12 @@ bool ConstraintSystem::repairFailures(
42644264
break;
42654265
}
42664266

4267+
case ConstraintLocator::FunctionBuilderBodyResult: {
4268+
conversionsOrFixes.push_back(ContextualMismatch::create(
4269+
*this, lhs, rhs, getConstraintLocator(locator)));
4270+
break;
4271+
}
4272+
42674273
default:
42684274
break;
42694275
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,6 +3531,11 @@ void constraints::simplifyLocator(Expr *&anchor,
35313531
continue;
35323532
}
35333533

3534+
case ConstraintLocator::FunctionBuilderBodyResult: {
3535+
path = path.slice(1);
3536+
break;
3537+
}
3538+
35343539
default:
35353540
// FIXME: Lots of other cases to handle.
35363541
break;

test/Constraints/function_builder_diags.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,8 @@ struct MyView {
602602
case . // expected-error {{expected ':' after 'case'}}
603603
} // expected-error {{expected identifier after '.' expression}}
604604
}
605+
606+
@TupleBuilder var invalidConversion: Int {
607+
"" // expected-error {{cannot convert value of type 'String' to specified type 'Int'}}
608+
}
605609
}

0 commit comments

Comments
 (0)