Don't show unresolved-field diagnostic for missing names

This commit is contained in:
Ryo Yoshida 2023-07-06 20:35:54 +09:00
parent e95644e279
commit 827a0530bc
No known key found for this signature in database
GPG key ID: E25698A930586171
3 changed files with 27 additions and 1 deletions

View file

@ -1449,6 +1449,13 @@ impl InferenceContext<'_> {
fn infer_field_access(&mut self, tgt_expr: ExprId, receiver: ExprId, name: &Name) -> Ty {
let receiver_ty = self.infer_expr_inner(receiver, &Expectation::none());
if name.is_missing() {
// Bail out early, don't even try to look up field. Also, we don't issue an unresolved
// field diagnostic because this is a syntax error rather than a semantic error.
return self.err_ty();
}
match self.lookup_field(&receiver_ty, name) {
Some((ty, field_id, adjustments, is_public)) => {
self.write_expr_adj(receiver, adjustments);