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 sumtype with embedded struct of option field (fix #22984) #22996

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Nov 28, 2024

This PR fix sumtype with embedded struct of option field (fix #22984).

  • Fix sumtype with embedded struct of option field.
  • Add test.
struct Value {
	x int
}

struct BValue {
	v ?Value
}

struct Word {
	BValue
}

struct Long {
	BValue
}

struct Variadic {
	BValue
}

type Param = Word | Long | Variadic

fn main() {
	a := [Param(Word{}), Long{}, Variadic{}]
	dump(a)
	f := a[0]
	v := f.v
	dump(v)
	assert v == none
}

PS D:\Test\v\tt1> v run .
[.\\tt1.v:25] a: [Param(Word{
    BValue: BValue{
        v: Option(none)
    }
}), Param(Long{
    BValue: BValue{
        v: Option(none)
    }
}), Param(Variadic{
    BValue: BValue{
        v: Option(none)
    }
})]
[.\\tt1.v:28] v: Option(none)

Huly®: V_0.6-21437

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 4a7f8cc into vlang:master Nov 28, 2024
72 checks passed
@yuyi98 yuyi98 deleted the fix_sumtype_with_option_field branch November 28, 2024 13:20
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.

cgen error when trying to use an embedded struct value, defined in all variant types of a sumtype
2 participants