Hello, I have this problem:
static int i;
void bar(T)(){
static if(is(T == int))
(()@system => 1)();
static if(is(T == float))
i = 42;
}
void foo(T)(){
bar!T();
}
void main()@safe pure{
foo!long();
foo!float(); //Error: `pure` function `D main` cannot call impure function `onlineapp.foo!float.foo`
foo!int(); //Error: `@safe` function `D main` cannot call `@system` function `onlineapp.foo!int.foo`
}
When template function foo is called and its inferred attributes are not compatible with attributes of main, errors are not really useful. Compiler print that foo!float is not pure or foo!int is not @safe but doesn't tell why. Is in dmd some flag that print errors similarly to this?:
void main()@safe pure{
foo!long();
foo!float();
//Error: `pure` function `D main` cannot call impure function `onlineapp.foo!float.foo`
//Error: potentially `pure` function `onlineapp.foo!float.foo` cannot call impure function `onlineapp.bar!float.bar`
//Error: potentially `pure` function `onlineapp.bar!float.bar` cannot access mutable static data `i`
foo!int();
//Error: `@safe` function `D main` cannot call `@system` function `onlineapp.foo!int.foo`
//Error: potentially `@safe` function `onlineapp.foo!int.foo` cannot call `@system` function `onlineapp.bar!int.bar`
//Error: potentially `@safe` function `onlineapp.bar!int.bar` cannot call `@system` delegate `onlineapp.bar!int.bar.__lambda1`
}