Skip to content

Comments

fix #21456: foreach over associative array allows incompatible types for key and value#21469

Merged
thewilsonator merged 1 commit intodlang:masterfrom
rainers:issue_21456
Jun 23, 2025
Merged

fix #21456: foreach over associative array allows incompatible types for key and value#21469
thewilsonator merged 1 commit intodlang:masterfrom
rainers:issue_21456

Conversation

@rainers
Copy link
Member

@rainers rainers commented Jun 22, 2025

fix the lambda parameter type to correspond to key or value

…ypes for key and value

fix the lambda parameter type to correspond to key or value
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @rainers!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#21469"

@thewilsonator thewilsonator added Merge:auto-merge Druntime:AA Specific to Associative Arrays labels Jun 22, 2025
@thewilsonator thewilsonator merged commit d234a54 into dlang:master Jun 23, 2025
42 checks passed
Statement s = new ExpStatement(fs.loc, v);
fs._body = new CompoundStatement(fs.loc, s, fs._body);
if (taa)
p.type = i == 1 || fs.parameters.length == 1 ? taa.nextOf() : taa.index;
Copy link
Contributor

@kinke kinke Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a similar case for autodecoding too:

void main() {
    import core.stdc.stdio;
    foreach (int i, dchar c; "abc")
        printf("%d: %c\n", i, c);
}

druntime's _aApplycd2() helper passes the pointers to (original size_t) index and value to the generated foreach-function. And that function then loads a 32-bit integer from the passed index pointer - so truncating to 32-bits on little-endian, but using the 32 upper bits for 64-bit big-endian targets. We have an LDC-specific fix for this (introduced in ldc-developers/ldc@bbdf473); we might be able to fuse these 2 fixes to a single one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #21705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Druntime:AA Specific to Associative Arrays Merge:auto-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

foreach over associative array allows incompatible types for key and value

4 participants