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

checker: fix const from comptime if expr (fix #19169) #19179

Merged
merged 1 commit into from Aug 19, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Aug 19, 2023

This PR fix const from comptime if expr (fix #19169).

  • Fix const from comptime if expr.
  • Add test.
import term

const (
	color = $if windows {
		term.bright_cyan('WINDOWS')
	} $else {
		term.bright_green('UNIX')
	}
)

fn main() {
	salutation := 'hello'
	// works if you add `'' +` before 'color'
	val := match salutation {
		'hello' { color + ' some text' }
		'goodbyte' { color + ' some other text' }
		else { 'invalid' }
	}
	println(val)
	assert true
}

PS D:\Test\v\tt1> v run .
WINDOWS some text

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.

Great!

@spytheman spytheman merged commit 8b96175 into vlang:master Aug 19, 2023
48 checks passed
@yuyi98 yuyi98 deleted the fix_infix_expr_in_match branch August 19, 2023 09:26
Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
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 thinks string type is void and produces compile error
2 participants