[Issue 19555] New: Trait to get source location for symbol

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 7 14:15:09 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19555

          Issue ID: 19555
           Summary: Trait to get source location for symbol
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: simen.kjaras at gmail.com

Occasionally, one wants to print an error message regarding a symbol that is
not defined in one's own code. An example would be a function that requires its
parameter types have a certain @attribute:

struct Foo {}

void fun(T)(T t) {
    import std.traits : hasUDA;
    static if (!hasUDA!(T, "a")) {
        pragma(msg, "Type "~T.stringof~" does not have necessary @attribute");
    }
}

unittest {
    fun(Foo());
}

In this case, the best thing the pragma(msg) can do is print the line on which
fun was invoked, but the actual issue is on the line where Foo is defined, and
it would be beneficial if the error message actually stated this.

The exact issue that prompted this suggestion is issue 19554, which does
essentially what's happening above - a confusing error message is created
because it refers to a problem that is actually in a different location from
where its effects occur.

--


More information about the Digitalmars-d-bugs mailing list