diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_ty/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 67 |
2 files changed, 28 insertions, 40 deletions
diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index d6df48db2..ce257dc0b 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml | |||
@@ -32,3 +32,4 @@ chalk-ir = { version = "0.15.0" } | |||
32 | 32 | ||
33 | [dev-dependencies] | 33 | [dev-dependencies] |
34 | insta = "0.16.0" | 34 | insta = "0.16.0" |
35 | expect = { path = "../expect" } | ||
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index e9f785383..6f34aaf17 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -151,16 +151,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
151 | fn validate_call(&mut self, db: &dyn HirDatabase, call_id: ExprId, expr: &Expr) -> Option<()> { | 151 | fn validate_call(&mut self, db: &dyn HirDatabase, call_id: ExprId, expr: &Expr) -> Option<()> { |
152 | // Check that the number of arguments matches the number of parameters. | 152 | // Check that the number of arguments matches the number of parameters. |
153 | 153 | ||
154 | // Due to shortcomings in the current type system implementation, only emit this diagnostic | 154 | // FIXME: Due to shortcomings in the current type system implementation, only emit this |
155 | // if there are no type mismatches in the containing function. | 155 | // diagnostic if there are no type mismatches in the containing function. |
156 | if self.infer.type_mismatches.iter().next().is_some() { | 156 | if self.infer.type_mismatches.iter().next().is_some() { |
157 | return Some(()); | 157 | return Some(()); |
158 | } | 158 | } |
159 | 159 | ||
160 | let is_method_call; | 160 | let is_method_call = matches!(expr, Expr::MethodCall { .. }); |
161 | let (callee, args) = match expr { | 161 | let (callee, args) = match expr { |
162 | Expr::Call { callee, args } => { | 162 | Expr::Call { callee, args } => { |
163 | is_method_call = false; | ||
164 | let callee = &self.infer.type_of_expr[*callee]; | 163 | let callee = &self.infer.type_of_expr[*callee]; |
165 | let (callable, _) = callee.as_callable()?; | 164 | let (callable, _) = callee.as_callable()?; |
166 | let callee = match callable { | 165 | let callee = match callable { |
@@ -173,7 +172,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
173 | (callee, args.clone()) | 172 | (callee, args.clone()) |
174 | } | 173 | } |
175 | Expr::MethodCall { receiver, args, .. } => { | 174 | Expr::MethodCall { receiver, args, .. } => { |
176 | is_method_call = true; | ||
177 | let callee = self.infer.method_resolution(call_id)?; | 175 | let callee = self.infer.method_resolution(call_id)?; |
178 | let mut args = args.clone(); | 176 | let mut args = args.clone(); |
179 | args.insert(0, *receiver); | 177 | args.insert(0, *receiver); |
@@ -389,13 +387,14 @@ pub fn record_pattern_missing_fields( | |||
389 | 387 | ||
390 | #[cfg(test)] | 388 | #[cfg(test)] |
391 | mod tests { | 389 | mod tests { |
392 | use insta::assert_snapshot; | 390 | use expect::{expect, Expect}; |
393 | use ra_db::fixture::WithFixture; | 391 | use ra_db::fixture::WithFixture; |
394 | 392 | ||
395 | use crate::{diagnostics::MismatchedArgCount, test_db::TestDB}; | 393 | use crate::{diagnostics::MismatchedArgCount, test_db::TestDB}; |
396 | 394 | ||
397 | fn check_diagnostic_message(ra_fixture: &str) -> String { | 395 | fn check_diagnostic(ra_fixture: &str, expect: Expect) { |
398 | TestDB::with_single_file(ra_fixture).0.diagnostic::<MismatchedArgCount>().0 | 396 | let msg = TestDB::with_single_file(ra_fixture).0.diagnostic::<MismatchedArgCount>().0; |
397 | expect.assert_eq(&msg); | ||
399 | } | 398 | } |
400 | 399 | ||
401 | fn check_no_diagnostic(ra_fixture: &str) { | 400 | fn check_no_diagnostic(ra_fixture: &str) { |
@@ -407,55 +406,43 @@ mod tests { | |||
407 | 406 | ||
408 | #[test] | 407 | #[test] |
409 | fn simple_free_fn_zero() { | 408 | fn simple_free_fn_zero() { |
410 | assert_snapshot!(check_diagnostic_message( | 409 | check_diagnostic( |
411 | r" | 410 | r" |
412 | fn zero() {} | 411 | fn zero() {} |
413 | 412 | fn f() { zero(1); } | |
414 | fn f() { | 413 | ", |
415 | zero(1); | 414 | expect![["\"zero(1)\": Expected 0 arguments, found 1\n"]], |
416 | } | 415 | ); |
417 | " | ||
418 | ), | ||
419 | @"\"zero(1)\": Expected 0 arguments, found 1\n"); | ||
420 | 416 | ||
421 | check_no_diagnostic( | 417 | check_no_diagnostic( |
422 | r" | 418 | r" |
423 | fn zero() {} | 419 | fn zero() {} |
424 | 420 | fn f() { zero(); } | |
425 | fn f() { | ||
426 | zero(); | ||
427 | } | ||
428 | ", | 421 | ", |
429 | ); | 422 | ); |
430 | } | 423 | } |
431 | 424 | ||
432 | #[test] | 425 | #[test] |
433 | fn simple_free_fn_one() { | 426 | fn simple_free_fn_one() { |
434 | assert_snapshot!(check_diagnostic_message( | 427 | check_diagnostic( |
435 | r" | 428 | r" |
436 | fn one(arg: u8) {} | 429 | fn one(arg: u8) {} |
437 | 430 | fn f() { one(); } | |
438 | fn f() { | 431 | ", |
439 | one(); | 432 | expect![["\"one()\": Expected 1 argument, found 0\n"]], |
440 | } | 433 | ); |
441 | " | ||
442 | ), | ||
443 | @"\"one()\": Expected 1 argument, found 0\n"); | ||
444 | 434 | ||
445 | check_no_diagnostic( | 435 | check_no_diagnostic( |
446 | r" | 436 | r" |
447 | fn one(arg: u8) {} | 437 | fn one(arg: u8) {} |
448 | 438 | fn f() { one(1); } | |
449 | fn f() { | ||
450 | one(1); | ||
451 | } | ||
452 | ", | 439 | ", |
453 | ); | 440 | ); |
454 | } | 441 | } |
455 | 442 | ||
456 | #[test] | 443 | #[test] |
457 | fn method_as_fn() { | 444 | fn method_as_fn() { |
458 | assert_snapshot!(check_diagnostic_message( | 445 | check_diagnostic( |
459 | r" | 446 | r" |
460 | struct S; | 447 | struct S; |
461 | impl S { | 448 | impl S { |
@@ -465,9 +452,9 @@ mod tests { | |||
465 | fn f() { | 452 | fn f() { |
466 | S::method(); | 453 | S::method(); |
467 | } | 454 | } |
468 | " | 455 | ", |
469 | ), | 456 | expect![["\"S::method()\": Expected 1 argument, found 0\n"]], |
470 | @"\"S::method()\": Expected 1 argument, found 0\n"); | 457 | ); |
471 | 458 | ||
472 | check_no_diagnostic( | 459 | check_no_diagnostic( |
473 | r" | 460 | r" |
@@ -486,7 +473,7 @@ mod tests { | |||
486 | 473 | ||
487 | #[test] | 474 | #[test] |
488 | fn method_with_arg() { | 475 | fn method_with_arg() { |
489 | assert_snapshot!(check_diagnostic_message( | 476 | check_diagnostic( |
490 | r" | 477 | r" |
491 | struct S; | 478 | struct S; |
492 | impl S { | 479 | impl S { |
@@ -496,9 +483,9 @@ mod tests { | |||
496 | fn f() { | 483 | fn f() { |
497 | S.method(); | 484 | S.method(); |
498 | } | 485 | } |
499 | " | 486 | ", |
500 | ), | 487 | expect![["\"S.method()\": Expected 1 argument, found 0\n"]], |
501 | @"\"S.method()\": Expected 1 argument, found 0\n"); | 488 | ); |
502 | 489 | ||
503 | check_no_diagnostic( | 490 | check_no_diagnostic( |
504 | r" | 491 | r" |