Skip to content

Commit af9ddf6

Browse files
committed
Started adding support for specified generics at function call sites
1 parent 8afcbb9 commit af9ddf6

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

Diff for: src/resolve/expr/call/cast.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@ pub fn cast(
2020
args: Vec<TypedExpr>,
2121
source: Source,
2222
) -> Result<Result<TypedExpr, Vec<TypedExpr>>, ResolveError> {
23-
if !call.generics.is_empty() {
24-
return Err(ResolveError::other(
25-
"Resolution of casting call with generics is not implemented yet",
26-
source,
27-
));
28-
}
29-
30-
if !call.name.namespace.is_empty() || args.len() != 1 {
23+
if !call.name.namespace.is_empty() || args.len() != 1 || !call.generics.is_empty() {
24+
// No match
3125
return Ok(Err(args));
3226
}
3327

Diff for: src/resolve/expr/call/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ pub fn resolve_call_expr(
2424
call: &ast::Call,
2525
source: Source,
2626
) -> Result<TypedExpr, ResolveError> {
27-
if !call.generics.is_empty() {
28-
return Err(ResolveError::other(
29-
"Resolution of calls with generics is not implemented yet",
30-
source,
31-
));
32-
}
33-
3427
let mut args = Vec::with_capacity(call.args.len());
3528
for arg in call.args.iter() {
3629
args.push(resolve_expr(
@@ -49,7 +42,7 @@ pub fn resolve_call_expr(
4942

5043
let callee = ctx
5144
.func_haystack
52-
.find(ctx, &call.name, &args[..], source)
45+
.find(ctx, &call.name, call.generics.as_slice(), &args[..], source)
5346
.map_err(|reason| {
5447
ResolveErrorKind::FailedToFindFunction {
5548
signature: format!(

Diff for: src/resolve/expr/static_member.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ pub fn resolve_static_member_call_named(
183183
.into_iter()
184184
.copied()
185185
.flat_map(|func_ref| {
186-
FuncHaystack::fits(ctx, func_ref, &args, Some(catalog.clone()), *call_source)
186+
FuncHaystack::fits(
187+
ctx,
188+
func_ref,
189+
static_member_call.call.generics.as_slice(),
190+
&args,
191+
Some(catalog.clone()),
192+
*call_source,
193+
)
187194
});
188195

189196
let callee = only_match.next().ok_or_else(|| {

Diff for: src/resolve/func_haystack.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::{
88
};
99
use crate::{
1010
asg::{self, Callee, TypeKind, TypedExpr},
11+
ast::TypeArg,
1112
name::{Name, ResolvedName},
1213
resolve::conform::Perform,
1314
source_files::Source,
@@ -42,14 +43,15 @@ impl FuncHaystack {
4243
&self,
4344
ctx: &ResolveExprCtx,
4445
name: &Name,
46+
generics: &[TypeArg],
4547
arguments: &[TypedExpr],
4648
source: Source,
4749
) -> Result<Callee, FindFunctionError> {
4850
let resolved_name = ResolvedName::new(self.fs_node_id, name);
4951

50-
self.find_local(ctx, &resolved_name, arguments, source)
51-
.or_else(|| self.find_remote(ctx, &name, arguments, source))
52-
.or_else(|| self.find_imported(ctx, &name, arguments, source))
52+
self.find_local(ctx, &resolved_name, generics, arguments, source)
53+
.or_else(|| self.find_remote(ctx, &name, generics, arguments, source))
54+
.or_else(|| self.find_imported(ctx, &name, generics, arguments, source))
5355
.unwrap_or(Err(FindFunctionError::NotDefined))
5456
}
5557

@@ -95,6 +97,7 @@ impl FuncHaystack {
9597
pub fn fits(
9698
ctx: &ResolveExprCtx,
9799
func_ref: asg::FuncRef,
100+
generics: &[TypeArg],
98101
args: &[TypedExpr],
99102
existing_catalog: Option<PolyCatalog>,
100103
source: Source,
@@ -104,6 +107,10 @@ impl FuncHaystack {
104107

105108
let mut catalog = existing_catalog.unwrap_or_default();
106109

110+
if generics.len() != 0 {
111+
todo!("FuncHaystack::fits does not support specified generics yet");
112+
}
113+
107114
if !params.is_cstyle_vararg && args.len() != params.required.len() {
108115
return None;
109116
}
@@ -167,6 +174,7 @@ impl FuncHaystack {
167174
&self,
168175
ctx: &ResolveExprCtx,
169176
resolved_name: &ResolvedName,
177+
generics: &[TypeArg],
170178
arguments: &[TypedExpr],
171179
source: Source,
172180
) -> Option<Result<Callee, FindFunctionError>> {
@@ -175,7 +183,7 @@ impl FuncHaystack {
175183
.get(&resolved_name)
176184
.into_iter()
177185
.flatten()
178-
.flat_map(|f| Self::fits(ctx, *f, arguments, None, source));
186+
.flat_map(|f| Self::fits(ctx, *f, generics, arguments, None, source));
179187

180188
local_matches.next().map(|found| {
181189
if local_matches.next().is_some() {
@@ -190,6 +198,7 @@ impl FuncHaystack {
190198
&self,
191199
ctx: &ResolveExprCtx,
192200
name: &Name,
201+
generics: &[TypeArg],
193202
arguments: &[TypedExpr],
194203
source: Source,
195204
) -> Option<Result<Callee, FindFunctionError>> {
@@ -211,7 +220,7 @@ impl FuncHaystack {
211220
.into_iter()
212221
})
213222
.flatten()
214-
.flat_map(|f| Self::fits(ctx, *f, arguments, None, source));
223+
.flat_map(|f| Self::fits(ctx, *f, generics, arguments, None, source));
215224

216225
remote_matches.next().map(|found| {
217226
if remote_matches.next().is_some() {
@@ -226,6 +235,7 @@ impl FuncHaystack {
226235
&self,
227236
ctx: &ResolveExprCtx,
228237
name: &Name,
238+
generics: &[TypeArg],
229239
arguments: &[TypedExpr],
230240
source: Source,
231241
) -> Option<Result<Callee, FindFunctionError>> {
@@ -281,7 +291,7 @@ impl FuncHaystack {
281291
.into_iter()
282292
.flatten()
283293
})
284-
.flat_map(|f| Self::fits(ctx, *f, arguments, None, source));
294+
.flat_map(|f| Self::fits(ctx, *f, generics, arguments, None, source));
285295

286296
matches.next().map(|found| {
287297
if matches.next().is_some() {

0 commit comments

Comments
 (0)