Crash resolving a method on Foo[2] when Foo is distinct #2042.

This commit is contained in:
Christoffer Lerno
2025-03-12 15:45:43 +01:00
parent d5b211a786
commit c9dbd86d82
4 changed files with 12 additions and 3 deletions

View File

@@ -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.

View File

@@ -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));
}

View File

@@ -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);
}

View File

@@ -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()
{}