www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Mixin Template Function Attributes

reply jmh530 <john.michael.hall gmail.com> writes:
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.
Jan 20 2016
next sibling parent Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
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 `}`.
Jan 20 2016
prev sibling parent reply Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
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
Jan 20 2016
parent reply jmh530 <john.michael.hall gmail.com> writes:
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.
Jan 20 2016
parent jmh530 <john.michael.hall gmail.com> writes:
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.
Jan 20 2016