Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v: implement $for comptime T.variants #20193

Merged
merged 2 commits into from
Dec 16, 2023

Conversation

felipensp
Copy link
Member

Fix #20176

type TestSum = int | string

fn gen[T](val T) {
    $if val is $sumtype {
        $for f in T.variants {
            dump(f)
            dump(f.typ)
            $if f.typ is $int {
                dump('is int')
            } $else $if f.typ is string {
                dump('is string')
            }
        }
    }
}

fn main() {
    a := TestSum(123)
    gen(a)
}

copilot:summary

copilot:walkthrough

@felipensp felipensp changed the title v: implement for-variants comptime v: implement $for comptime T.variants Dec 16, 2023
@felipensp felipensp marked this pull request as ready for review December 16, 2023 13:15
@medvednikov medvednikov merged commit 81bfc2f into vlang:master Dec 16, 2023
54 checks passed
@felipensp felipensp deleted the for_variant_comptime branch December 20, 2023 19:23
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.

compiler: support for $for G in field_value.$variants { and $if field_value is G {
2 participants