Bug 13550 – [REG2.067a] Inner functions take outer function attributes erroneously
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-28T08:47:00Z
Last change time
2015-02-18T03:37:30Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-09-28T08:47:36Z
Code like this looks correct:
auto foo() @nogc {
static int[] bar() {
return new int[2];
}
return &bar;
}
void main() {
auto g = foo();
assert(g() == [0, 0]);
}
But DMD 2.067alpha gives:
test.d(3,15): Error: cannot use 'new' in @nogc function foo
Inner functions take outer function attributes even if (I think) they shouldn't.
Comment #1 by bugzilla — 2014-09-28T08:56:39Z
Actually, since the source for local functions is provided, their attributes should be inferred.
If the attributes for the local function are incompatible with the attributes for the enclosing function, and the enclosing function calls the local function, then a compile time error should be issued.
Comment #2 by bearophile_hugs — 2014-09-28T09:22:32Z
Issue created after a comment by deadalnix:
> the function could be returned and used elsewhere, where these
> attribute aren't necessary.