Bug 19555 – Trait to get source location for symbol

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2019-01-07T14:15:09Z
Last change time
2019-11-14T09:08:35Z
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2019-01-07T14:15:09Z
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.
Comment #1 by dkorpel — 2019-11-14T09:08:35Z
This issue has been fixed with this PR: https://github.com/dlang/dmd/pull/10013