Skip to content

Commit bf2be1f

Browse files
committed
Added error message and test case for using undeclared implementation parameters on functions within trait implementations
1 parent f814d0c commit bf2be1f

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

Diff for: src/resolve/impl_head.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ fn ensure_satisfies_trait_func(
138138
trait_func: &TraitFunc,
139139
impl_func: &Func,
140140
) -> Result<(), ResolveError> {
141-
let mut for_alls = ForAlls::default();
141+
if !impl_func.impl_params.params.is_empty() {
142+
return Err(ResolveError::other(
143+
"Implementation parameter is not allowed by trait definition",
144+
impl_func.source,
145+
));
146+
}
142147

148+
let mut for_alls = ForAlls::default();
143149
let mut mappings = HashMap::new();
144150
for sub in expected.values() {
145151
collect_constraints_into(&mut mappings, sub);

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

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

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11

22
pragma => adept(c"3.0")
33

4-
trait Example<$T> {
5-
#[using Speak<$T>]
6-
func invalidFunction(self $T) void
7-
}
8-
94
trait Speak<$T> {
105
func speak(self $T) void
116
}
127

13-
func main {
14-
8+
trait InvalidTrait<$T> {
9+
#[using Speak<$T>]
10+
func invalidFunction(self $T) void
1511
}
1612

13+
func main {}
14+

0 commit comments

Comments
 (0)