Skip to content

checker: rewrite comptime_if_cond() to support comptime if cond evaluate#25122

Merged
spytheman merged 10 commits into
vlang:masterfrom
kbkpbot:fix-comptime-if
Aug 17, 2025
Merged

checker: rewrite comptime_if_cond() to support comptime if cond evaluate#25122
spytheman merged 10 commits into
vlang:masterfrom
kbkpbot:fix-comptime-if

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

This PR:

  1. Rewrite comptime_if_cond() in checker, fully support comptime if conditon evaluate to true/false.
  2. Add comptime iter $for support for enum/method/method params/sumtype variants/attribute.
  3. Fix issue $if in $for attribute, does not issue error when attr field not exisit #25099, $if with (same) test ||'ed seems to be silently ignored #24938.

for test vlib/v/gen/c/testdata/comp_if_unknown.vv

fn main() {
        mut x := 1
        $if glibc {
                x = 2
        } $else {
                x = 3
        }
        println('done')
}

I think the output should contain :

#if defined(__GLIBC__)
x = 2;
#else
#endif

instead of :

#if defined(__GLIBC__)
x = 2;
#else
x = 3;
#endif

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23643

Comment thread vlib/v/tests/comptime/comptime_if_glibc_test.v Outdated
Comment thread vlib/v/tests/comptime/comptime_if_glibc_test.v Outdated
Comment thread vlib/v/tests/comptime/comptime_if_glibc_test.v Outdated
Comment thread vlib/v/checker/comptime.v Outdated
Comment thread vlib/v/checker/comptime.v Outdated
Comment thread vlib/v/checker/comptime.v Outdated
Comment thread vlib/v/checker/comptime.v

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work 🙇🏻‍♂️ @kbkpbot .
Thank you very much for working on this.

@spytheman

Copy link
Copy Markdown
Contributor

This PR also has a positive effect on compiling small programs too:
image

@spytheman spytheman merged commit f55c295 into vlang:master Aug 17, 2025
83 checks passed
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