Bug 20077 – Bogus 'need this' for lambda used inside struct

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-07-23T19:45:08Z
Last change time
2024-12-13T19:04:39Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Simen Kjaeraas
Moved to GitHub: dmd#19601 →

Comments

Comment #0 by simen.kjaras — 2019-07-23T19:45:08Z
This fails with 'function `S.test!((a) => a).test` need this to access member test': struct S { pragma(msg, test!(a => a)); } int test(alias fn)() { return fn(3); } Clearly, a => a does not need access to `this` in S, and something's gone wrong in the inference here.
Comment #1 by contact — 2020-10-19T17:04:50Z
This also happens on accessing static fields on a struct. auto foobar(alias func)(string val) { return func(val); } struct S { static immutable foo = "foo"; static immutable bar = foobar!((v) => v[0])(S.foo); }
Comment #2 by contact — 2020-10-19T17:40:41Z
This seems related to what's happening on #21332. When type is explicitly known on the lambda, this doesn't happen. See this snippet here: ```d auto foobar(alias func)(string val) { return func(val); } struct S { static immutable foo = "foo"; static immutable bar = foobar!((string v) => v[0])(S.foo); } ``` This is the exact same code snippet reported on the latest comment, but the type of `v` is explicitly declared.
Comment #3 by robert.schadek — 2024-12-13T19:04:39Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19601 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB