Skip to content

execute global initialization after all the other declarations have finished#2740

Merged
jurgenvinju merged 2 commits intomainfrom
fix/global-init
Apr 1, 2026
Merged

execute global initialization after all the other declarations have finished#2740
jurgenvinju merged 2 commits intomainfrom
fix/global-init

Conversation

@jurgenvinju
Copy link
Copy Markdown
Member

@jurgenvinju jurgenvinju commented Mar 31, 2026

This PR partially fixes this situation:

module X

default int f(int _) = 42;
int x = f(0);
int f(0) = 0;

test bool testF() = f(0) == 0 && x == 0;

Because at the time of running the initialization for x the second overload is not there yet, the answer to f(0) will be 42 (and the f will be cached but that is for #2741). While the test is running, both x and f(0) will return the wrong number.

It is the goal of this PR to fix the value of x. The fix for f(0) in the test is in #2741

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46%. Comparing base (30cf1b2) to head (b27fe91).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##              main   #2740   +/-   ##
=======================================
- Coverage       46%     46%   -1%     
+ Complexity    6721    6719    -2     
=======================================
  Files          794     794           
  Lines        65905   65910    +5     
  Branches      9884    9887    +3     
=======================================
- Hits         30827   30819    -8     
- Misses       32690   32700   +10     
- Partials      2388    2391    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jurgenvinju
Copy link
Copy Markdown
Member Author

ok a test was added. I'm merging as soon as it builds here.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 1, 2026

@jurgenvinju jurgenvinju merged commit d11f490 into main Apr 1, 2026
9 checks passed
@jurgenvinju jurgenvinju deleted the fix/global-init branch April 1, 2026 08:49
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.

2 participants