Skip to content

Conversation

@yuyi98
Copy link
Member

@yuyi98 yuyi98 commented May 16, 2025

This PR fix map of fixed array value in if guard. (fix #24488)

  • Fix map of fixed array value in if guard.
  • Add test.
struct Serials {
	a u8
	b u8
	c u8
pub mut:
	ids map[u8][3]u8
}

pub fn (mut s Serials) id(id u8) {
	if _ := s.ids[id] {
	} else {
		s3 := u8(s.c + s.ids.len)
		s.ids[id] = [s.a, s.a, s3]!
	}
}

fn main() {
	mut s := Serials{
		a: 1
		b: 2
	}
	s.id(u8(3))
	println(s)
	assert s.ids[3] == [u8(1), 1, 0]!

	s.id(u8(4))
	println(s)
	assert s.ids[4] == [u8(1), 1, 1]!
}

PS D:\Test\v\tt1> v run .       
Serials{
    a: 1
    b: 2
    c: 0
    ids: {3: [1, 1, 0]}
}
Serials{
    a: 1
    b: 2
    c: 0
    ids: {3: [1, 1, 0], 4: [1, 1, 1]}
}

@huly-for-github
Copy link

Connected to Huly®: V_0.6-22865

Copy link
Member

@Delta456 Delta456 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work

@spytheman spytheman merged commit d433835 into vlang:master May 16, 2025
76 of 77 checks passed
@yuyi98 yuyi98 deleted the map_with_fixed_array_value branch May 16, 2025 14:49
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 with map[u8][3]u8 (value as fixed array)

3 participants