Bug 21165 – Spurious @nogc error with delegate taking `immutable size_t`

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-08-15T21:47:35Z
Last change time
2024-12-13T19:11:04Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#19773 →

Comments

Comment #0 by andy-hanson — 2020-08-15T21:47:35Z
This particular code fails with a compile error that it shouldn't. ``` @nogc: void main() { int x = 0; f((int, immutable size_t) { int y = x; }); } void f(T)(scope void delegate(T, immutable size_t) @nogc cb) { cb(0, 0); } ``` When I run `dmd app.d` this fails with: ``` app.d(3): Error: function D main is @nogc yet allocates closures with the GC app.d(5): app.main.__lambda1 closes over variable x at app.d(4) ``` There is no compile error if: * The second delegate parameter is something other than `immutable size_t` (such as `size_t` or `immutable bool`). * An explicit type argument is given to `f`, as in `f!int`. * The delegate parameters are named, as in `f((int a, immutable size_t b) {`.
Comment #1 by ag0aep6g — 2020-08-16T10:42:29Z
(In reply to andy.pj.hanson from comment #0) > f((int, immutable size_t) { > int y = x; > }); [...] > * The delegate parameters are named, as in `f((int a, immutable size_t b) {`. Note that the second parameter is actually already named in the non-working version. It's called "size_t". What's missing is the type. By adding "b", size_t gets recognized as the type as intended. Slightly more reduced test case: ---- @nogc: void main() { int x = 0; f((int, b) { int y = x; }); } void f(T)(scope void delegate(T, immutable int) @nogc cb) {} ---- Also happens with other qualifiers (const, shared) instead of immutable.
Comment #2 by robert.schadek — 2024-12-13T19:11:04Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19773 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB