Bug 16137 – Better error message: function literal accessing class variable

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-07T16:04:15Z
Last change time
2024-12-13T18:48:23Z
Assigned to
No Owner
Creator
Johan Engelen
Moved to GitHub: dmd#19142 →

Comments

Comment #0 by jbc.engelen — 2016-06-07T16:04:15Z
This code ``` class A { int i; void foo() { auto a = function() { i++; }; // Line 6 } } ``` gives the error (DMD 2.071): foo.d(6): Error: need 'this' for 'i' of type 'int' I think it should be improved, but I do not have a great idea for it. It think instead of mentioning "need 'this'" it should mention something about "delegate" or "function literal needs access to object data", ... Thanks, Johan
Comment #1 by robert.schadek — 2024-12-13T18:48:23Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19142 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB