Skip to content

Commit

Permalink
Merge pull request #16673 from ntrel/ufcs-spell
Browse files Browse the repository at this point in the history
Add speller suggestions for UFCS and pointer fields

Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Jul 8, 2024
2 parents 67996ab + 9da51ae commit 222d095
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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 @@ Expression getProperty(Type t, Scope* scope_, const ref Loc loc, Identifier iden
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`?",
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`?",
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();
}

0 comments on commit 222d095

Please sign in to comment.