From 33a428f966d6583d47524a5274f519d4490d0e01 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 22 Mar 2025 10:49:06 +0100 Subject: d: Improve UFCS/property error message Improves on the speller suggestions for UFCS by using the location of the suggested symbol, and considering that local functions aren't eligible for UFCS instead of making a nonsensical suggestion, such as "no property foo, did you mean foo?". gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 9d2f034398. Reviewed-on: https://github.com/dlang/dmd/pull/21046 --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/typesem.d | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'gcc/d') diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 9982d0d..0b554f1 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -94950cae582d89f5ba2720786522f669f620f9d1 +9d2f034398c33be1a28d8c60721014a6ab34d652 The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/typesem.d b/gcc/d/dmd/typesem.d index 65bad38..c5a3b83 100644 --- a/gcc/d/dmd/typesem.d +++ b/gcc/d/dmd/typesem.d @@ -3444,8 +3444,16 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla auto s2 = scope_.search_correct(ident); // UFCS if (s2 && s2.isFuncDeclaration) - errorSupplemental(loc, "did you mean %s `%s`?", - s2.kind(), s2.toChars()); + { + if (s2.ident == ident) + { + errorSupplemental(s2.loc, "cannot call %s `%s` with UFCS because it is not declared at module scope", + s2.kind(), s2.toChars()); + } + else + errorSupplemental(s2.loc, "did you mean %s `%s`?", + s2.kind(), s2.toChars()); + } else if (src.type.ty == Tpointer) { // structPtr.field @@ -3454,7 +3462,7 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla { if (auto s3 = as.search_correct(ident)) { - errorSupplemental(loc, "did you mean %s `%s`?", + errorSupplemental(s3.loc, "did you mean %s `%s`?", s3.kind(), s3.toChars()); } } -- cgit v1.1