Skip to content

Commit f814d0c

Browse files
committed
Added error test case for #[using] on trait functions, and made minor code improvements
1 parent 472fdf9 commit f814d0c

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

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

+20-15
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,29 @@ pub fn infer_callee_missing_impl_args(
2525
continue;
2626
};
2727

28-
let from_env = caller.impl_params.params.iter().filter(|(_, param_trait)| {
29-
if catalog
30-
.extend_if_match_all_types(ctx, &expected_trait.args, &param_trait.args)
31-
.is_err()
32-
{
33-
return false;
34-
}
28+
let from_env = caller
29+
.impl_params
30+
.params
31+
.iter()
32+
.filter_map(|(param_name, param_trait)| {
33+
if catalog
34+
.extend_if_match_all_types(ctx, &expected_trait.args, &param_trait.args)
35+
.is_err()
36+
{
37+
return None;
38+
}
3539

36-
catalog
37-
.resolver()
38-
.resolve_trait(expected_trait)
39-
.map_or(false, |expected_trait| {
40-
param_trait.trait_ref == expected_trait.trait_ref
41-
})
42-
});
40+
catalog
41+
.resolver()
42+
.resolve_trait(expected_trait)
43+
.ok()
44+
.and_then(|expected_trait| {
45+
(param_trait.trait_ref == expected_trait.trait_ref).then_some(param_name)
46+
})
47+
});
4348

4449
match from_env.exactly_one() {
45-
Ok((param_name, _)) => {
50+
Ok(param_name) => {
4651
if catalog
4752
.polymorphs
4853
.insert(expected_name.into(), PolyValue::PolyImpl(param_name.into()))

Diff for: src/resolve/polymorph/matcher.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ impl<'a, 'b, 'c> TypeMatcher<'a, 'b, 'c> {
162162
}
163163
}
164164

165-
self.partial
166-
.insert(name.to_string(), PolyValue::Type(new_type.clone()));
165+
assert!(self
166+
.partial
167+
.insert(name.to_string(), PolyValue::Type(new_type.clone()))
168+
.is_none());
167169

168170
Ok(())
169171
}

Diff for: tests/error/using_trait_on_trait_func/main.adept

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
pragma => adept(c"3.0")
3+
4+
trait Example<$T> {
5+
#[using Speak<$T>]
6+
func invalidFunction(self $T) void
7+
}
8+
9+
trait Speak<$T> {
10+
func speak(self $T) void
11+
}
12+
13+
func main {
14+
15+
}
16+

0 commit comments

Comments
 (0)