Address review comments

This commit is contained in:
Jonas Schievink 2020-07-09 17:33:49 +02:00
parent 984b6889eb
commit f4a9d9a00f
3 changed files with 29 additions and 40 deletions

1
Cargo.lock generated
View file

@ -1104,6 +1104,7 @@ dependencies = [
"chalk-ir", "chalk-ir",
"chalk-solve", "chalk-solve",
"ena", "ena",
"expect",
"insta", "insta",
"itertools", "itertools",
"log", "log",

View file

@ -32,3 +32,4 @@ chalk-ir = { version = "0.15.0" }
[dev-dependencies] [dev-dependencies]
insta = "0.16.0" insta = "0.16.0"
expect = { path = "../expect" }

View file

@ -151,16 +151,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
fn validate_call(&mut self, db: &dyn HirDatabase, call_id: ExprId, expr: &Expr) -> Option<()> { fn validate_call(&mut self, db: &dyn HirDatabase, call_id: ExprId, expr: &Expr) -> Option<()> {
// Check that the number of arguments matches the number of parameters. // Check that the number of arguments matches the number of parameters.
// Due to shortcomings in the current type system implementation, only emit this diagnostic // FIXME: Due to shortcomings in the current type system implementation, only emit this
// if there are no type mismatches in the containing function. // diagnostic if there are no type mismatches in the containing function.
if self.infer.type_mismatches.iter().next().is_some() { if self.infer.type_mismatches.iter().next().is_some() {
return Some(()); return Some(());
} }
let is_method_call; let is_method_call = matches!(expr, Expr::MethodCall { .. });
let (callee, args) = match expr { let (callee, args) = match expr {
Expr::Call { callee, args } => { Expr::Call { callee, args } => {
is_method_call = false;
let callee = &self.infer.type_of_expr[*callee]; let callee = &self.infer.type_of_expr[*callee];
let (callable, _) = callee.as_callable()?; let (callable, _) = callee.as_callable()?;
let callee = match callable { let callee = match callable {
@ -173,7 +172,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
(callee, args.clone()) (callee, args.clone())
} }
Expr::MethodCall { receiver, args, .. } => { Expr::MethodCall { receiver, args, .. } => {
is_method_call = true;
let callee = self.infer.method_resolution(call_id)?; let callee = self.infer.method_resolution(call_id)?;
let mut args = args.clone(); let mut args = args.clone();
args.insert(0, *receiver); args.insert(0, *receiver);
@ -389,13 +387,14 @@ pub fn record_pattern_missing_fields(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use insta::assert_snapshot; use expect::{expect, Expect};
use ra_db::fixture::WithFixture; use ra_db::fixture::WithFixture;
use crate::{diagnostics::MismatchedArgCount, test_db::TestDB}; use crate::{diagnostics::MismatchedArgCount, test_db::TestDB};
fn check_diagnostic_message(ra_fixture: &str) -> String { fn check_diagnostic(ra_fixture: &str, expect: Expect) {
TestDB::with_single_file(ra_fixture).0.diagnostic::<MismatchedArgCount>().0 let msg = TestDB::with_single_file(ra_fixture).0.diagnostic::<MismatchedArgCount>().0;
expect.assert_eq(&msg);
} }
fn check_no_diagnostic(ra_fixture: &str) { fn check_no_diagnostic(ra_fixture: &str) {
@ -407,55 +406,43 @@ mod tests {
#[test] #[test]
fn simple_free_fn_zero() { fn simple_free_fn_zero() {
assert_snapshot!(check_diagnostic_message( check_diagnostic(
r" r"
fn zero() {} fn zero() {}
fn f() { zero(1); }
fn f() { ",
zero(1); expect![["\"zero(1)\": Expected 0 arguments, found 1\n"]],
} );
"
),
@"\"zero(1)\": Expected 0 arguments, found 1\n");
check_no_diagnostic( check_no_diagnostic(
r" r"
fn zero() {} fn zero() {}
fn f() { zero(); }
fn f() {
zero();
}
", ",
); );
} }
#[test] #[test]
fn simple_free_fn_one() { fn simple_free_fn_one() {
assert_snapshot!(check_diagnostic_message( check_diagnostic(
r" r"
fn one(arg: u8) {} fn one(arg: u8) {}
fn f() { one(); }
fn f() { ",
one(); expect![["\"one()\": Expected 1 argument, found 0\n"]],
} );
"
),
@"\"one()\": Expected 1 argument, found 0\n");
check_no_diagnostic( check_no_diagnostic(
r" r"
fn one(arg: u8) {} fn one(arg: u8) {}
fn f() { one(1); }
fn f() {
one(1);
}
", ",
); );
} }
#[test] #[test]
fn method_as_fn() { fn method_as_fn() {
assert_snapshot!(check_diagnostic_message( check_diagnostic(
r" r"
struct S; struct S;
impl S { impl S {
@ -465,9 +452,9 @@ mod tests {
fn f() { fn f() {
S::method(); S::method();
} }
" ",
), expect![["\"S::method()\": Expected 1 argument, found 0\n"]],
@"\"S::method()\": Expected 1 argument, found 0\n"); );
check_no_diagnostic( check_no_diagnostic(
r" r"
@ -486,7 +473,7 @@ mod tests {
#[test] #[test]
fn method_with_arg() { fn method_with_arg() {
assert_snapshot!(check_diagnostic_message( check_diagnostic(
r" r"
struct S; struct S;
impl S { impl S {
@ -496,9 +483,9 @@ mod tests {
fn f() { fn f() {
S.method(); S.method();
} }
" ",
), expect![["\"S.method()\": Expected 1 argument, found 0\n"]],
@"\"S.method()\": Expected 1 argument, found 0\n"); );
check_no_diagnostic( check_no_diagnostic(
r" r"