From 74aa0ab9f79490c862e48a4e6b3dad9e4073817f Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 9 Jul 2020 18:24:02 +0200 Subject: arg count mismatch: handle tuple ctors --- crates/ra_hir_ty/src/expr.rs | 51 +++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 6f34aaf17..72577d114 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs @@ -13,7 +13,7 @@ use crate::{ MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, MissingPatFields, }, utils::variant_data, - ApplicationTy, CallableDef, InferenceResult, Ty, TypeCtor, + ApplicationTy, InferenceResult, Ty, TypeCtor, _match::{is_useful, MatchCheckCtx, Matrix, PatStack, Usefulness}, }; @@ -162,35 +162,24 @@ impl<'a, 'b> ExprValidator<'a, 'b> { Expr::Call { callee, args } => { let callee = &self.infer.type_of_expr[*callee]; let (callable, _) = callee.as_callable()?; - let callee = match callable { - CallableDef::FunctionId(func) => func, - // FIXME: Handle tuple struct/variant constructor calls. - _ => return None, - }; - - (callee, args.clone()) + (callable, args.clone()) } Expr::MethodCall { receiver, args, .. } => { let callee = self.infer.method_resolution(call_id)?; let mut args = args.clone(); args.insert(0, *receiver); - (callee, args) + (callee.into(), args) } _ => return None, }; - let loc = callee.lookup(db.upcast()); - let ast = loc.source(db.upcast()); - let params = ast.value.param_list()?; + let sig = db.callable_item_signature(callee); + let params = sig.value.params(); - let mut param_count = params.params().count(); + let mut param_count = params.len(); let mut arg_count = args.len(); - if params.self_param().is_some() { - param_count += 1; - } - if arg_count != param_count { let (_, source_map) = db.body_with_source_map(self.func.into()); if let Ok(source_ptr) = source_map.expr_syntax(call_id) { @@ -501,4 +490,32 @@ mod tests { ", ); } + + #[test] + fn tuple_struct() { + check_diagnostic( + r" + struct Tup(u8, u16); + fn f() { + Tup(0); + } + ", + expect![["\"Tup(0)\": Expected 2 arguments, found 1\n"]], + ) + } + + #[test] + fn enum_variant() { + check_diagnostic( + r" + enum En { + Variant(u8, u16), + } + fn f() { + En::Variant(0); + } + ", + expect![["\"En::Variant(0)\": Expected 2 arguments, found 1\n"]], + ) + } } -- cgit v1.2.3