Skip to content

Conversation

@Mittagskogel
Copy link

This PR fixes a bug in _track_local_constants/exploit_locally_constant_variables() for Block_Nonlabel_Do_Construct and Block_Label_Do_Construct loops. Instead of explicitly calling _track_local_constants() separately for each op in the do block, we let the recursive call iterate through the list by itself. This means that the buffer of locally constant variables persists between individual lines of the do block and something like the following works:

do i=1, 5
  out = 14.4
  out = out * i  ! can be simplified: out = 14.4 * i
end do

The modification to test_exploit_locally_constant_variables() checks for this condition. Additionally, the test checks whether unmodified constant variables set outside the loop are propagated inside, although this already worked before the fix.

This PR also makes a similar simplification in the same function for Assignment_Stmt. It is unnecessary to call _inject_knowns() individually for the left and right sides because this is already handled by _inject_knowns() itself. Note that this simplification is not a fix, so no additional tests are needed.

All 49 tests in ast_desugaring_test.py pass.

@Mittagskogel Mittagskogel marked this pull request as draft October 27, 2025 16:28
@Mittagskogel Mittagskogel marked this pull request as ready for review November 4, 2025 08:29
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.

1 participant