Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 20, 2016 Mixin Template Function Attributes | ||||
---|---|---|---|---|
| ||||
I was thinking about using mixin templates to put some module-level default information in a single file so that it doesn't clutter up other files. It works for imports, but it doesn't seem to propagate for function attributes. module_default.d ------------------- module module_default; mixin template module_default() { import std.traits : functionAttributes; import std.stdio : writeln; @safe: } app.d ------------------- import module_default; mixin module_default; int foo(int x) { return x; } void main() { writeln(functionAttributes!foo); } Compiled with dmd app.d module_default.d on Windows 7 64bit. The output is system, when I would expect it to be safe. I'm not sure if this is how the behavior is supposed to be or if it is a bug. |
January 20, 2016 Re: Mixin Template Function Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | On Wednesday, 20 January 2016 at 16:37:31 UTC, jmh530 wrote:
> I'm not sure if this is how the behavior is supposed to be or if it is a bug.
It's not a bug. The `@attribute:` syntax applies to all following declarations _inside the current scope_, i.e. until your mixin templates closing `}`.
|
January 20, 2016 Re: Mixin Template Function Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | On Wednesday, 20 January 2016 at 16:37:31 UTC, jmh530 wrote: > I'm not sure if this is how the behavior is supposed to be or if it is a bug. I believe, however, that it _is_ a bug that the imported symbols are visible outside the template. Most likely related to the infamous https://issues.dlang.org/show_bug.cgi?id=314 |
January 20, 2016 Re: Mixin Template Function Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Wednesday, 20 January 2016 at 19:19:04 UTC, Marc Schütz wrote:
> On Wednesday, 20 January 2016 at 16:37:31 UTC, jmh530 wrote:
>> I'm not sure if this is how the behavior is supposed to be or if it is a bug.
>
> I believe, however, that it _is_ a bug that the imported symbols are visible outside the template. Most likely related to the infamous https://issues.dlang.org/show_bug.cgi?id=314
Thanks. The fact that one worked and the other didn't was what I found weird.
|
January 20, 2016 Re: Mixin Template Function Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | On Wednesday, 20 January 2016 at 19:48:04 UTC, jmh530 wrote: > On Wednesday, 20 January 2016 at 19:19:04 UTC, Marc Schütz wrote: >> On Wednesday, 20 January 2016 at 16:37:31 UTC, jmh530 wrote: >>> I'm not sure if this is how the behavior is supposed to be or if it is a bug. >> >> I believe, however, that it _is_ a bug that the imported symbols are visible outside the template. Most likely related to the infamous https://issues.dlang.org/show_bug.cgi?id=314 > > Thanks. The fact that one worked and the other didn't was what I found weird. It looks like this issue covers it https://issues.dlang.org/show_bug.cgi?id=12735 It appears that there is a pull request in the works to fix the behavior. |
Copyright © 1999-2021 by the D Language Foundation