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.
Comment #3 by k.hara.pg — 2014-09-29T01:36:12Z
Comment #4 by k.hara.pg — 2014-09-29T03:23:56Z
Comment #5 by github-bugzilla — 2014-09-29T06:58:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d8df4bff8bf5862ad8f30bdfd12881df5fdaeef5 fix Issue 13550 - Inner functions take outer function attributes erroneously https://github.com/D-Programming-Language/dmd/commit/5118d69286588d18f14bf0b4d0a4e90c822c82dc Merge pull request #4031 from 9rnsr/fix13550 [REG2.067a] Issue 13550 - Inner functions take outer function attributes erroneously
Comment #6 by github-bugzilla — 2015-02-18T03:37:30Z