Skip to content

Conversation

@leonerd
Copy link
Contributor

@leonerd leonerd commented Dec 22, 2025

An initial attempt to solve #24028.

The code relies on some inner knowledge of how the PERL_MAGIC_lvref magic structure works, so it isn't great, but it solves the problem for now. Most importantly, it adds more unit tests to assert the behaviour we want.

My intention is to rework the implementation of foreach on refalias variables after this is merged, so it would be a neater solution to this problem, and also would be nicer to work out for #24027 as well.

As it is a bugfix to some behaviour on a still-experimental feature, I don't believe this needs a perldelta entry.

@leonerd
Copy link
Contributor Author

leonerd commented Dec 22, 2025

I don't overly like the code as it currently stands, because it means now the implementation of foreach loops has to have a deep understanding of how lvref magic works. But then, I don't really like that foreach on a refalias variable uses lvref magic at all. That seems like an awkward conflation of layers, and this issue would be easier to solve if the pp_*iter family understood refalias directly. Not only would it solve this issue (#24028) much nicer, but it would also be a necessary step towards solving #24027 as well.

@leonerd leonerd marked this pull request as ready for review December 23, 2025 12:47
@leonerd
Copy link
Contributor Author

leonerd commented Dec 23, 2025

Actually, having thought about it, it would be good to get this unit-test merged anyway, before having a go at that larger rework to solve this in a better way while also addressing #24027. So I'd like to merge this one first, just to get the unit tests, while accepting that the code might just be totally changed soon.

@khwilliamson khwilliamson merged commit 059a773 into Perl:blead Dec 23, 2025
33 checks passed
@tonycoz
Copy link
Contributor

tonycoz commented Dec 23, 2025

I'm surprised a SAVE*() can't do this, though I don't have the time to look at it right now.

@leonerd
Copy link
Contributor Author

leonerd commented Dec 23, 2025

I'm surprised a SAVE*() can't do this, though I don't have the time to look at it right now.

Oh something SAVE-based almost certainly can, but currently the SAVE macros aren't used at all for any of the implicit localisation around foreach loops. Actually that's something I'm probably going to look into as part of fixing #24027

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants