Skip to content

Commit

Permalink
Include @name when searching for possible matches to name in the …
Browse files Browse the repository at this point in the history
…error message. #1779
  • Loading branch information
lerno committed Jan 5, 2025
1 parent ab2d223 commit b6e166f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 20 additions & 1 deletion src/compiler/sema_name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit b6e166f

Please sign in to comment.