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: allow comptime-for to iterate over comptime variables + add $string comptime type + cleanup #20233

Merged
merged 5 commits into from
Dec 22, 2023

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Dec 20, 2023

This PR allow to iterate on compile-time variables (related to #20176):

  • Feature: $for t in var.variants {
  • Add $string compile-time type
  • Cleanup ast.Table
type TestSum = int | string

struct Bar {
    y int
}

struct Foo {
mut:
	a TestSum
    b int   
    c string
    d Bar
}

fn main() {
    $for f in Foo.fields {
        $if f.typ is $sumtype {
            dump(f)
            $for f2 in f.variants {
                dump(f2)
                $if f2.typ is $int {
                    dump('int')
                } $else $if f2.typ is $string {
                    dump('string')
                }
            }
        } $else $if f.typ is Bar {
            $for f3 in f.fields {
                println(f3)
            }
        }
    }
}

copilot:summary

copilot:walkthrough

@felipensp felipensp changed the title v: allow comptime for on comptime variables v: allow comptime for on comptime variables + add $string comptime type Dec 20, 2023
@felipensp felipensp changed the title v: allow comptime for on comptime variables + add $string comptime type v: allow comptime-for to iterate over comptime variables + add $string comptime type + cleanup Dec 20, 2023
@felipensp felipensp marked this pull request as ready for review December 22, 2023 01:33
@@ -144,6 +144,7 @@ pub enum ComptimeTypeKind {
alias
function
option
string
Copy link
Member

Choose a reason for hiding this comment

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

Wow, I could have swear, that string was here already. Good addition.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Excellent work.

@spytheman spytheman merged commit 5043e14 into vlang:master Dec 22, 2023
54 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.

2 participants