diff --git a/releasenotes.md b/releasenotes.md index 589a95008..e14a9450a 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -41,6 +41,7 @@ - `"+".to_float()` would panic. - `import` can now both be @public and @norecurse. - Crash when trying to convert a struct slice to a vector #2039. +- Crash resolving a method on `Foo[2]` when `Foo` is distinct #2042. ### Stdlib changes - `new_*` functions in general moved to version without `new_` prefix. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index dacc9f1c4..0119216a1 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -1180,8 +1180,7 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig, if (method_parent && !vec_size(params)) { RETURN_SEMA_ERROR(decl, "A method must start with an argument of the type " - "it is a method of, e.g. 'fn void %s.%s(%s* self)', " - "unless it is a 'construct' method,", + "it is a method of, e.g. 'fn void %s.%s(%s* self)'.", type_to_error_string(method_parent->type), decl->name, type_to_error_string(method_parent->type)); } diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 0e837dd8a..9a370272f 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -480,7 +480,7 @@ static inline bool sema_resolve_type(SemaContext *context, TypeInfo *type_info, case TYPE_INFO_SLICE: case TYPE_INFO_ARRAY: case TYPE_INFO_VECTOR: - if (!sema_resolve_array_type(context, type_info, resolve_kind)) + if (!sema_resolve_array_type(context, type_info, resolve_kind & ~RESOLVE_TYPE_NO_CHECK_DISTINCT)) { return type_info_poison(type_info); } diff --git a/test/test_suite/methods/distinct_arr_method_resolution.c3 b/test/test_suite/methods/distinct_arr_method_resolution.c3 new file mode 100644 index 000000000..05573c744 --- /dev/null +++ b/test/test_suite/methods/distinct_arr_method_resolution.c3 @@ -0,0 +1,9 @@ +module abc; +distinct Foo = int; +distinct Bar = int; +fn void Foo[2].foo(&self) {} +// Same with: +macro Bar[2].bar(&self) {} + +fn void main() +{} \ No newline at end of file