Skip to content

cgen: fix enum field with const value (fix #21916) - #21919

Merged
spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_enum_decl
Jul 24, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_enum_decl

Conversation

@yuyi98

@yuyi98 yuyi98 commented Jul 24, 2024

Copy link
Copy Markdown
Member

This PR fix enum field with const value (fix #21916).

  • Fix enum field with const value.
  • Add test.
enum Foo {
	a = c
	b = 1
	c = 2
}

const c = 0

fn main() {
	mut foo := Foo.c
	foo = .a
	ret := match foo {
		.a { 'a' }
		.b { 'b' }
		.c { 'c' }
	}
	println(ret)
	assert ret == 'a'
}

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

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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 38ea5dc into vlang:master Jul 24, 2024
@yuyi98
yuyi98 deleted the fix_enum_decl branch July 24, 2024 12:23
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.

C error is constant used as enum value before it is defined

2 participants