feat: add diagnostic for E0422#22393
Conversation
| // Find the relevant variant | ||
| let (adt_ty, Some(variant)) = self.resolve_variant(expr.into(), path, false) else { | ||
| // FIXME: Emit an error. | ||
| self.push_diagnostic(InferenceDiagnostic::UnresolvedRecordExpr { expr }); |
There was a problem hiding this comment.
I know there was a FIXME, but I think the error should go inside resolve_variant(), which will also fix it for patterns.
| @@ -0,0 +1,45 @@ | |||
| use either::Either; | |||
| use syntax::{AstNode, ast::Expr}; | |||
There was a problem hiding this comment.
By convention we don't use specific ast nodes, instead we refer to them as ast::Node.
| "cannot find struct, variant or union type in this scope".to_owned(), | ||
| crate::adjusted_display_range(ctx, d.expr, &|expr| match expr { | ||
| Either::Left(Expr::RecordExpr(it)) => it.path().map(|p| p.syntax().text_range()), | ||
| _ => None, |
There was a problem hiding this comment.
If you emit the error in resolve_variant(), you also need to account for ast::Pat::{RecordPat,TupleStructPat}.
| let (resolution, unresolved) = if value_ns { | ||
| let Some(res) = path_ctx.resolve_path_in_value_ns(HygieneId::ROOT) else { | ||
| drop(ctx); | ||
| self.push_diagnostic(InferenceDiagnostic::UnresolvedVariant { id: node }); |
There was a problem hiding this comment.
Sorry about this, but IMO this is still not the right place. We should emit an error in resolve_path_in_X(), and I don't know if we should do it yet.
There was a problem hiding this comment.
Also there are more cases in this method after resolution.
There was a problem hiding this comment.
Sorry about this, but IMO this is still not the right place. We should emit an error in
resolve_path_in_X(), and I don't know if we should do it yet.
I found that if I emit diagnostics in resolve_path_in_value_ns and resolve_path_in_type_ns, different call sites need different error code (for example, another resolve_path_in_type_ns call site need E0425 rather than E0422). I feel like there is no proper place for now.
There was a problem hiding this comment.
First, the error codes are not set in stone. The code organization is more important. Second, we can pass this information from the outside.
But as I said, I am not sure we should do this yet.
Related to #22140