Skip to content

checker: check error for sumtype in array (fix #19170) - #19183

Merged
medvednikov merged 1 commit into
vlang:masterfrom
yuyi98:check_mismatch_in_array
Aug 19, 2023
Merged

medvednikov merged 1 commit into
vlang:masterfrom
yuyi98:check_mismatch_in_array

Conversation

@yuyi98

@yuyi98 yuyi98 commented Aug 19, 2023

Copy link
Copy Markdown
Member

This PR check error for sumtype in array (fix #19170).

  • Check error for sumtype in array.
  • Add test.
struct OtherType {
	foo string
	bar string
}

type RuneAlias = rune
type RuneAliasOrOtherType = OtherType | RuneAlias

const whitespace = [rune(0x0009), 0x000a, 0x000c, 0x000d, 0x0020]

fn main() {
	mut x := RuneAliasOrOtherType(RuneAlias(rune(`!`)))
	match x {
		RuneAlias {
			if x in whitespace {
				// doing `if x as RuneAlias in whitepsace` here
				// works but it should be doing that automatically
				// since I'm inside the RuneAlias match condition.
			}
		}
		else {
			// do something else
		}
	}
}

PS D:\Test\v\tt1> v run .       
tt1.v:15:7: error: left operand to `in` does not match the array element type: expected `rune`, not `RuneAliasOrOtherType`
   13 |     match x {
   14 |         RuneAlias {
   15 |             if x in whitespace {
      |                ~~~~~~~~~~~~~~~
   16 |                 // doing `if x as RuneAlias in whitepsace` here
   17 |                 // works but it should be doing that automatically

@medvednikov
medvednikov merged commit 52e481a into vlang:master Aug 19, 2023
@yuyi98
yuyi98 deleted the check_mismatch_in_array branch August 20, 2023 03:08
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.

sumtype not being auto converted back to original type inside match statement and C error

2 participants