Extracting user defined attributes on function parameters

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Apr 17 17:45:47 UTC 2020


On Fri, Apr 17, 2020 at 05:33:23PM +0000, Simen Kjærås via Digitalmars-d-learn wrote:
> On Friday, 17 April 2020 at 16:54:42 UTC, Adam D. Ruppe wrote:
[...]
> > So pragma(msg) is doing something really weird, the bug doesn't
> > appear to be in Phobos per se, I think it is the compiler doing the
> > wrong thing, it seems to me it works inside a function scope but not
> > at module scope......
> 
> It's even more fascinating - the issue doesn't occur if
> ParameterDefaults is defined in the same module that it's used in, and
> it works if there's a type with the same name as the UDA. Reducing the
> code as much as I can, I get this:
[...]
> The above code works, and prints "3". If you move ParameterDefaults to
> a different module, something like this:
[...]
> Then you get an error message about 'undefined identifier S'. Add some
> kind of S to bar, and you get an error message about S not being
> readable at compile-time or things just work if it is readable. It
> seems the UDA is being looked up in the wrong context.

This is reminiscient of a bug I found recently, the ultimate cause of
which is accessing a private symbol across modules, which is verboten,
but it manifested itself in a way that appeared completely unrelated --
it turned an attribute-inferred function into @system where one expected
@safe, which percolated up the call stack and ended up as a template
mismatch error, which then shunted the template resolution into another
overload which finally generated a totally unrelated compile error (very
unhelpful!).

I wonder if the ultimate cause of the above case is ultimately caused by
the change to import semantics that hid private symbols from outside the
module. Perhaps something, somewhere, is triggering an illegal access of
a private symbol, which percolates up the call/instantiation stack and
causing what appears to be a strange compiler discrepancy.

Or perhaps it's a compiler bug. :-D


T

-- 
It is of the new things that men tire --- of fashions and proposals and improvements and change. It is the old things that startle and intoxicate. It is the old things that are young. -- G.K. Chesterton


More information about the Digitalmars-d-learn mailing list