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

sumtype smartcast: bug 1 #20308

Closed
enghitalo opened this issue Dec 30, 2023 · 0 comments
Closed

sumtype smartcast: bug 1 #20308

enghitalo opened this issue Dec 30, 2023 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Dec 30, 2023

Describe the bug

#20270

Reproduction Steps

type TestSum = int | string

struct Abc {
	s TestSum
}

fn gen[T](struc T) {
	$if T is $struct {
		$for field in T.fields {
			field_value := struc.$(field.name)
			$if field_value is $sumtype {
				$for v in field_value.variants {
					if field_value is v { // smartcast
						// works beautifully
						dump(field_value)
						// Not Works
						$if field_value is string {
							println('text') // bug
						} $else $if field_value is int {
							println('text')
						} $else {
							println('text')
						}
					}
				}
			}
		}
	}
}

fn main() {
	a := Abc{TestSum(123)}
	b := Abc{TestSum('foo')}
	gen[Abc](a)
	gen[Abc](b)
}

Expected Behavior

[discardable.v:15] field_value: 123
text
[discardable.v:15] field_value: foo
text

Current Behavior

discardable.v:19:8: cgen error: checker bug; print arg.typ is 0
   17 |                         $if field_value is string {
   18 |                             // dump(field_value)
   19 |                             println('text')
      |                             ~~~~~~~~~~~~~~~
   20 |                         } $else $if field_value is int {
   21 |                             println('text')

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 4690fec

Environment details (OS name and version, etc.)

Ubuntu

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@enghitalo enghitalo added the Bug This tag is applied to issues which reports bugs. label Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant