Include @name when searching for possible matches to name in the error message. #1779

This commit is contained in:
Christoffer Lerno
2025-01-05 16:12:13 +01:00
parent ab2d223e71
commit b6e166f44d
2 changed files with 21 additions and 1 deletions

View File

@@ -18,6 +18,7 @@
- Add 'validation' setting and make dead code a warning.
- Allow compile time `$foreach` iteration over constant Strings and bytes.
- Improved error message when accessing `@private` from other modules #1769.
- Include `@name` when searching for possible matches to `name` in the error message. #1779
### Fixes
- Fix case trying to initialize a `char[*]*` from a String.

View File

@@ -546,10 +546,18 @@ static void find_closest(const char *name, int name_len, Decl **decls, int *coun
{
int best_distance = *best_distance_ref;
int count = *count_ref;
bool starts_at = name[0] == '@';
Decl *at_match = NULL;
FOREACH(Decl *, decl, decls)
{
if (decl->visibility != VISIBLE_PUBLIC) continue;
int dist = damerau_levenshtein_distance(name, name_len, decl->name, strlen(decl->name));
const char *decl_name = decl->name;
if (!starts_at && decl_name[0] == '@' && str_eq(&decl_name[1], name))
{
at_match = decl;
continue;
}
int dist = damerau_levenshtein_distance(name, name_len, decl_name, strlen(decl_name));
if (dist < best_distance)
{
matches[0] = decl;
@@ -562,6 +570,17 @@ static void find_closest(const char *name, int name_len, Decl **decls, int *coun
matches[count++] = decl;
}
}
if (at_match)
{
if (count == 3)
{
matches[0] = at_match;
}
else
{
matches[count++] = at_match;
}
}
*count_ref = count;
*best_distance_ref = best_distance;
}