Bug 1223 – .tupleof tries to access protected members
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-05-09T04:03:00Z
Last change time
2016-08-27T23:37:14Z
Keywords
rejects-valid
Assigned to
nobody
Creator
hhasemann
Comments
Comment #0 by hhasemann — 2007-05-09T04:03:32Z
.tupleof should only count accessible members, it seems to correctly
handle private ones (with ignoring them) but always tries to access protected ones, which leads to a "member bar not accessible" error at compile time.
The following example reproduces this error on dmd 1.014:
--- foo.d ---
module foo;
class Foo { protected Foo bar=null; }
--- main.d ---
import foo;
void main() {
auto test=(new foo).tupleof[0];
}
Comment #1 by andrei — 2008-02-16T21:29:04Z
I think tupleof should actually access all nonstatic members, or that at least there should be a way to access all members. It's essentially a way to unencapsulate objects for e.g. serialization and introspection purposes.
Comment #2 by jarrett.billingsley — 2008-02-25T17:35:01Z
I just tested, and it fails with private members too. Just replace 'protected' with 'private' in the original and try.
Happens with structs and unions too.
Comment #3 by andrej.mitrovich — 2016-08-27T23:37:14Z
(In reply to Andrei Alexandrescu from comment #1)
> I think tupleof should actually access all nonstatic members, or that at
> least there should be a way to access all members. It's essentially a way to
> unencapsulate objects for e.g. serialization and introspection purposes.
This is an ancient issue by now (D1), but I don't think we should change .tupleof in any case. Typically low-level code uses .tupleof, for example it might use it to send a data structure over the network and you wouldn't want to lose private members in the process. :)
I think this is fair to close as wontfix.