Skip to content

[Diagnostics] Detect and diagnose type mismatches related to function… #33298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,11 @@ bool ContextualFailure::diagnoseAsError() {
return true;
}

case ConstraintLocator::FunctionBuilderBodyResult: {
diagnostic = *getDiagnosticFor(CTP_Initialization, toType);
break;
}

default:
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4420,6 +4420,12 @@ bool ConstraintSystem::repairFailures(
getConstraintLocator(anchor, path));
}

case ConstraintLocator::FunctionBuilderBodyResult: {
conversionsOrFixes.push_back(ContextualMismatch::create(
*this, lhs, rhs, getConstraintLocator(locator)));
break;
}

default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,11 @@ void constraints::simplifyLocator(ASTNode &anchor,
break;
}

case ConstraintLocator::FunctionBuilderBodyResult: {
path = path.slice(1);
break;
}

default:
// FIXME: Lots of other cases to handle.
break;
Expand Down
4 changes: 4 additions & 0 deletions test/Constraints/function_builder_diags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,8 @@ struct MyView {
case . // expected-error {{expected ':' after 'case'}}
} // expected-error {{expected identifier after '.' expression}}
}

@TupleBuilder var invalidConversion: Int { // expected-error {{cannot convert value of type 'String' to specified type 'Int'}}
""
}
}