Bug 18840 – static foreach over an object's tupleof gives wrong information for const variables

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-05-07T13:22:45Z
Last change time
2023-05-05T09:50:28Z
Assigned to
No Owner
Creator
Ethan Watson

Attachments

IDFilenameSummaryContent-TypeSize
1691test.dSimple test struct with a foreach and a static foreach outputting details at compile timetext/plain647

Comments

Comment #0 by gooberman — 2018-05-07T13:22:45Z
Created attachment 1691 Simple test struct with a foreach and a static foreach outputting details at compile time I have only tested this with two traits so far, but it does make generating automated bindings/equivalent objects inaccurate. At a minimum, the wrong __traits information gets returned from: * identifier - returns the name of the static foreach iteration variable * parent - returns the parent of said variable rather than the object type Accessing the variables directly from object.tupleof[ index ] works just fine. The attached test.d shows the issue. Current output when compiling that file: foreach pass: foo has parent SomeStruct bar has parent SomeStruct anotherConst has parent SomeStruct notAConst has parent SomeStruct static foreach pass: var has parent main() bar has parent SomeStruct var has parent main() notAConst has parent SomeStruct Expected output when compiling that file: foreach pass: foo has parent SomeStruct bar has parent SomeStruct anotherConst has parent SomeStruct notAConst has parent SomeStruct static foreach pass: foo has parent SomeStruct bar has parent SomeStruct anotherConst has parent SomeStruct notAConst has parent SomeStruct
Comment #1 by razvan.nitu1305 — 2023-05-05T09:50:28Z
I cannot reproduce this. With latest master I get: foreach pass: foo has parent SomeStruct bar has parent SomeStruct anotherConst has parent SomeStruct notAConst has parent SomeStruct static foreach pass: foo has parent SomeStruct bar has parent SomeStruct anotherConst has parent SomeStruct notAConst has parent SomeStruct which is the correct result.