Skip to content

Commit

Permalink
Merge branch 'master' into josh/fix_function_slab_gc
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty authored Sep 18, 2024
2 parents 7cc28ce + e82c72b commit cddd31a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
26 changes: 17 additions & 9 deletions sway-core/src/semantic_analysis/type_check_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,27 +1700,35 @@ impl<'a> TypeCheckContext<'a> {
0,
)))
}
(num_type_params, num_type_args) => {
let type_arguments_span = type_arguments
.iter()
.map(|x| x.span.clone())
.reduce(|s1: Span, s2: Span| Span::join(s1, &s2))
.unwrap_or_else(|| value.name().span());
(_, num_type_args) => {
// a trait decl is passed the self type parameter and the corresponding argument
// but it would be confusing for the user if the error reporting mechanism
// reported the number of arguments including the implicit self, hence
// we adjust it below
let adjust_for_trait_decl = value.has_self_type_param() as usize;
let num_type_params = num_type_params - adjust_for_trait_decl;
let non_parent_type_params = value
.type_parameters()
.iter()
.filter(|x| !x.is_from_parent)
.count()
- adjust_for_trait_decl;

let num_type_args = num_type_args - adjust_for_trait_decl;
if num_type_params != num_type_args {
if non_parent_type_params != num_type_args {
let type_arguments_span = type_arguments
.iter()
.map(|x| x.span.clone())
.reduce(|s1: Span, s2: Span| Span::join(s1, &s2))
.unwrap_or_else(|| value.name().span());

return Err(handler.emit_err(make_type_arity_mismatch_error(
value.name().clone(),
type_arguments_span,
num_type_args,
num_type_params,
non_parent_type_params,
)));
}

for type_argument in type_arguments.iter_mut() {
type_argument.type_id = self
.resolve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ impl MyEq for Data3 {
}
}

// This tests it is still possible to call generic methods
// where its parent has constraints
// https://github.com/FuelLabs/sway/issues/6384

trait MyTrait { }
struct S<T> { }

struct M1 {}
impl MyTrait for M1 { }

impl<T> S<T> where T: MyTrait {
fn bar<M>() {
}
}

fn issue_6384() {
let _x = S::<M1>::bar::<M1>();
}

fn main() -> u64 {
let s = Data { x: 42 };
assert(s.contains(42));
Expand Down Expand Up @@ -116,5 +135,7 @@ fn main() -> u64 {
assert(!d4.contains5(Data2 { x: 41, y: Data3 { x: 42 } }));
*/

issue_6384();

10
}

0 comments on commit cddd31a

Please sign in to comment.