Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add speller suggestions for UFCS and pointer fields #16673

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,28 @@
else
{
if (src)
error(loc, "no property `%s` for `%s` of type `%s`", ident.toChars(), src.toChars(), mt.toPrettyChars(true));
{
error(loc, "no property `%s` for `%s` of type `%s`",
ident.toChars(), src.toChars(), mt.toPrettyChars(true));
auto s2 = scope_.search_correct(ident);
// UFCS
if (s2 && s2.isFuncDeclaration)
errorSupplemental(loc, "did you mean %s `%s`?",

Check warning on line 3218 in compiler/src/dmd/typesem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/typesem.d#L3218

Added line #L3218 was not covered by tests
s2.kind(), s2.toChars());
else if (src.type.ty == Tpointer)
{
// structPtr.field
auto tn = (cast(TypeNext) src.type).nextOf();
if (auto as = tn.isAggregate())
{
if (auto s3 = as.search_correct(ident))
{
errorSupplemental(loc, "did you mean %s `%s`?",

Check warning on line 3228 in compiler/src/dmd/typesem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/typesem.d#L3228

Added line #L3228 was not covered by tests
s3.kind(), s3.toChars());
}
}
}
}
else
error(loc, "no property `%s` for type `%s`", ident.toChars(), mt.toPrettyChars(true));

Expand Down
13 changes: 10 additions & 3 deletions compiler/test/fail_compilation/fail347.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
EXTRA_FILES: imports/fail347a.d
TEST_OUTPUT:
---
fail_compilation/fail347.d(22): Error: undefined identifier `bbr`, did you mean variable `bar`?
fail_compilation/fail347.d(23): Error: no property `ofo` for type `S`, did you mean `fail347.S.foo`?
fail_compilation/fail347.d(24): Error: undefined identifier `strlenx`, did you mean function `strlen`?
fail_compilation/fail347.d(26): Error: undefined identifier `bbr`, did you mean variable `bar`?
fail_compilation/fail347.d(27): Error: no property `ofo` for type `S`, did you mean `fail347.S.foo`?
fail_compilation/fail347.d(29): Error: no property `fool` for `sp` of type `fail347.S*`
fail_compilation/fail347.d(29): did you mean variable `foo`?
fail_compilation/fail347.d(30): Error: undefined identifier `strlenx`, did you mean function `strlen`?
fail_compilation/fail347.d(31): Error: no property `strlenx` for `"hello"` of type `string`
fail_compilation/fail347.d(31): did you mean function `strlen`?
---
*/

Expand All @@ -21,5 +25,8 @@ void main()
S bar;
bbr.foo = 3;
bar.ofo = 4;
auto sp = &bar;
sp.fool = 5;
auto s = strlenx("hello");
auto q = "hello".strlenx();
}
Loading