Bug 20786 – do attribute inference for member functions inside nested aggregates

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-29T04:41:55Z
Last change time
2024-12-13T19:08:22Z
Assigned to
No Owner
Creator
Steven Schveighoffer
See also
https://issues.dlang.org/show_bug.cgi?id=13567
Moved to GitHub: dmd#19698 →

Comments

Comment #0 by schveiguy — 2020-04-29T04:41:55Z
All nested functions have available source for the compiler, so there is no reason not to infer attributes. This already happens inside @safe functions, it makes no sense for it not to happen for all nested functions. Note the post from Walter here: https://forum.dlang.org/post/[email protected] Also, this is related to issue 13567, but it's slightly different, and there is better precedent.
Comment #1 by razvan.nitu1305 — 2020-05-05T01:59:22Z
One problem with this request is that a lot of code will fail. I just tried implementing this locally and there are a lot of cases in druntime where nested functions with no attributes are declared and used as arguments to functions that receive an attribute-less function as parameter. Imposing attributes on functions where you don't actually care about them is annoying IMHO.
Comment #2 by schveiguy — 2020-05-05T02:30:07Z
Shouldn't that work though? This compiles just fine: void x(void function() foo) { foo(); } void bar() @nogc pure nothrow @safe {} void main() { x(&bar); } I guess a good counter case would be helpful here.
Comment #3 by razvan.nitu1305 — 2020-05-05T02:53:55Z
(In reply to Steven Schveighoffer from comment #2) > Shouldn't that work though? > > This compiles just fine: > > void x(void function() foo) { foo(); } > > void bar() @nogc pure nothrow @safe {} > > void main() > { > x(&bar); > } > > I guess a good counter case would be helpful here. Argh, you are right. I messed up the patch, sorry! It seems dmd does attribute inference for nested functions, except if the the function is the member of a nested aggregate declaration.
Comment #4 by schveiguy — 2020-05-05T03:35:01Z
(In reply to RazvanN from comment #3) > It seems dmd does > attribute inference for nested functions, except if the the function is the > member of a nested aggregate declaration. Oh interesting! I just tested that and you are right, I just assumed it would all be the same. Changing the title appropriately. It's curious that nested member functions are not inferred (except inside @safe functions) when straight nested functions are.
Comment #5 by robert.schadek — 2024-12-13T19:08:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19698 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB