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: improved comptime var checking with is operator and smartcasting #20315

Merged
merged 6 commits into from
Jan 1, 2024

Conversation

felipensp
Copy link
Member

Fix #20312

type TestSum = string | int

fn gen[T, R](sum T) R {
	$if T is $sumtype {
		$for v in sum.variants {
			if sum is v {
				dump(sum)
				$if sum is R {
					return sum
				}
			}
		}
	}
	return R{}
}

fn main() {
	dump(gen[TestSum, string](TestSum('foo')))
}

@felipensp felipensp changed the title v: improved comptime var checking with is operator v: improved comptime var checking with is operator Dec 31, 2023
@felipensp felipensp marked this pull request as ready for review January 1, 2024 12:03
@felipensp felipensp changed the title v: improved comptime var checking with is operator v: improved comptime var checking with is operator and smartcasting Jan 1, 2024
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 e5cf336 into vlang:master Jan 1, 2024
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
2 participants