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

cgen: fix comptime if expr T.typ is type (fix #13118) #13135

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jan 11, 2022

This PR fix comptime if expr T.typ is type (fix #13118).

  • Fix comptime if expr T.typ is type.
  • Add test.
module main

fn write<T>(out T) string {
	$if T.typ is bool {
		println('FOO')
		return 'FOO'
	} $else $if T.typ !is bool {
		println('BAR')
		return 'BAR'
	}
	return 'EMPTY'
}

fn main() {
	mut val := false
	ret := write<bool>(val)
	assert ret == 'FOO'
}

PS D:\Test\v\tt1> v run .
FOO

@spytheman spytheman merged commit f3d8bbd into vlang:master Jan 11, 2022
spytheman added a commit to jeffmikels/v that referenced this pull request Jan 11, 2022
* origin:
  ci: vfmt fmt.v ...
  cgen: fix `$if T.typ is Type {` (vlang#13135)
  parser: add support for mutable if guards (vlang#13132)
  tests: test with valgrind rune.bytes(), fix leak in .str_escaped()
  builtin: reduce allocations in `rune.bytes()`
  builtin: allow msvc users to link against a custom compiled Boehm library (vlang#13133)
  cgen: fix cast in the index of reference fixed array (fix vlang#13128) (vlang#13131)
  builtin: add a rune.bytes() convenience method (vlang#13129)
  checker: check error for match conditions with parenthesis (vlang#13130)
@yuyi98 yuyi98 deleted the fix_comptime_if_t_typ branch January 11, 2022 22:43
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.

comptime if bug (T.typ is ...)
2 participants