diff --git a/dora-frontend/src/typeck/call.rs b/dora-frontend/src/typeck/call.rs index 64f94b5fe..637775e1d 100644 --- a/dora-frontend/src/typeck/call.rs +++ b/dora-frontend/src/typeck/call.rs @@ -275,31 +275,32 @@ fn check_expr_call_fct( type_params: SourceTypeArray, arguments: CallArguments, ) -> SourceType { + let fct = ck.sa.fct(fct_id); + if !fct_accessible_from(ck.sa, fct_id, ck.module_id) { let msg = ErrorMessage::NotAccessible; ck.sa.report(ck.file_id, e.span, msg); } - let arg_types = arguments.assume_all_positional(ck); - - let lookup = MethodLookup::new(ck.sa, ck.file_id, ck.type_param_definition) - .span(e.span) - .callee(fct_id) - .args(&arg_types) - .fct_type_params(&type_params) - .find(); - - let ty = if lookup.find() { - let call_type = CallType::Fct(fct_id, type_params.clone()); - ck.analysis.map_calls.insert(e.id, Arc::new(call_type)); - - lookup.found_ret().unwrap() + let ty = if typeparamck::check( + ck.sa, + &ck.type_param_definition, + fct, + &type_params, + ck.file_id, + e.span, + ) { + check_args_compatible_fct(ck, fct, arguments, &type_params, None); + specialize_type(ck.sa, fct.return_type(), &type_params) } else { ty_error() }; ck.analysis.set_ty(e.id, ty.clone()); + let call_type = CallType::Fct(fct_id, type_params.clone()); + ck.analysis.map_calls.insert(e.id, Arc::new(call_type)); + ty } diff --git a/dora-frontend/src/typeck/lookup.rs b/dora-frontend/src/typeck/lookup.rs index 5877f0ea8..432488fc9 100644 --- a/dora-frontend/src/typeck/lookup.rs +++ b/dora-frontend/src/typeck/lookup.rs @@ -56,7 +56,6 @@ impl MethodLookupResult { enum LookupKind { Method(SourceType), Static(SourceType), - Callee(FctDefinitionId), } pub struct MethodLookup<'a> { @@ -94,11 +93,6 @@ impl<'a> MethodLookup<'a> { } } - pub fn callee(mut self, fct_id: FctDefinitionId) -> MethodLookup<'a> { - self.kind = Some(LookupKind::Callee(fct_id)); - self - } - pub fn parent(mut self, parent: FctParent) -> MethodLookup<'a> { self.fct_parent = Some(parent); self @@ -146,8 +140,6 @@ impl<'a> MethodLookup<'a> { let mut result = MethodLookupResult::new(); let fct_id = match kind { - LookupKind::Callee(fct_id) => Some(fct_id), - LookupKind::Method(ref obj) => { let name = self.name.expect("name not set"); self.find_method(&mut result, obj.clone(), name, false) @@ -168,7 +160,6 @@ impl<'a> MethodLookup<'a> { let name = self.sa.interner.str(name).to_string(); let msg = match kind { - LookupKind::Callee(_) => unreachable!(), LookupKind::Method(ref obj) => { let type_name = self.ty_name(obj); @@ -195,7 +186,6 @@ impl<'a> MethodLookup<'a> { LookupKind::Method(_) | LookupKind::Static(_) => { result.found_container_type_params.clone().unwrap() } - _ => SourceTypeArray::empty(), }; let fct_tps: SourceTypeArray = if let Some(fct_tps) = self.fct_tps { diff --git a/dora-frontend/src/typeck/tests.rs b/dora-frontend/src/typeck/tests.rs index 2e80fabef..9c11bf69a 100644 --- a/dora-frontend/src/typeck/tests.rs +++ b/dora-frontend/src/typeck/tests.rs @@ -439,30 +439,22 @@ fn type_function_params() { " fn foo() {} fn f() { foo(1i32); }", - (3, 18), - ErrorMessage::ParamTypesIncompatible("foo".into(), vec![], vec!["Int32".into()]), + (3, 22), + ErrorMessage::SuperfluousArgument, ); err( " fn foo(a: Int32) {} fn f() { foo(true); }", - (3, 18), - ErrorMessage::ParamTypesIncompatible( - "foo".into(), - vec!["Int32".into()], - vec!["Bool".into()], - ), + (3, 22), + ErrorMessage::WrongTypeForArgument("Int32".into(), "Bool".into()), ); err( " fn foo(a: Int32, b: Bool) {} fn f() { foo(1i32, 2i32); }", - (3, 18), - ErrorMessage::ParamTypesIncompatible( - "foo".into(), - vec!["Int32".into(), "Bool".into()], - vec!["Int32".into(), "Int32".into()], - ), + (3, 28), + ErrorMessage::WrongTypeForArgument("Bool".into(), "Int32".into()), ); } @@ -1198,8 +1190,8 @@ fn test_new_call_fct() { fn test_new_call_fct_wrong_params() { err( "fn g() {} fn f() { g(1i32); }", - (1, 20), - ErrorMessage::ParamTypesIncompatible("g".into(), Vec::new(), vec!["Int32".into()]), + (1, 22), + ErrorMessage::SuperfluousArgument, ); } @@ -2544,8 +2536,8 @@ fn variadic_parameter() { f(true); } ", - (4, 13), - ErrorMessage::ParamTypesIncompatible("f".into(), vec!["Int32".into()], vec!["Bool".into()]), + (4, 15), + ErrorMessage::WrongTypeForArgument("Int32".into(), "Bool".into()), ); ok(" fn f(x: Int32, y: Int32...) {} @@ -2563,11 +2555,7 @@ fn variadic_parameter() { } ", (4, 13), - ErrorMessage::ParamTypesIncompatible( - "f".into(), - vec!["Int32".into(), "Int32".into()], - Vec::new(), - ), + ErrorMessage::MissingArguments(1, 0), ); err( "fn f(x: Int32..., y: Int32) {}", @@ -2649,8 +2637,8 @@ fn check_wrong_number_type_params() { fn foo() { bar[Int32](false); } fn bar[T](x: T) {} ", - (2, 24), - ErrorMessage::ParamTypesIncompatible("bar".into(), vec!["T".into()], vec!["Bool".into()]), + (2, 35), + ErrorMessage::WrongTypeForArgument("Int32".into(), "Bool".into()), ); } @@ -4672,7 +4660,10 @@ fn call_with_named_arguments() { f(1, 2, y = 3); } ", - &[((4, 21), ErrorMessage::UnexpectedNamedArgument)], + &[ + ((4, 21), ErrorMessage::UnexpectedNamedArgument), + ((4, 21), ErrorMessage::SuperfluousArgument), + ], ); }