Skip to content

cgen: simplify fixed arr return#18380

Merged
medvednikov merged 4 commits intovlang:masterfrom
felipensp:simplify_fixed_arr
Jun 9, 2023
Merged

cgen: simplify fixed arr return#18380
medvednikov merged 4 commits intovlang:masterfrom
felipensp:simplify_fixed_arr

Conversation

@felipensp
Copy link
Copy Markdown
Member

@felipensp felipensp commented Jun 8, 2023

Fix #18377

struct Test {}

fn (t Test) conversion_error(value u16) [4]u8 {
	return conversion_error(value)
}

fn conversion_error(value u16) [4]u8 {
	mut return_value := [4]u8{}
	for i := 0; i < 4; i++ {
		return_value[i] = u8(value)
	}
	return return_value
}


fn main() {
	// -- Block below works fine
	value := conversion_error(42)
	println(value)

	value2 := Test{}.conversion_error(42)
	println(value)
	// -- Block above works fine
	println(conversion_error(42))
	println(Test{}.conversion_error(42))

	y := dump(conversion_error(42))
	dump(y)

	y2 := dump(Test{}.conversion_error(42))
	dump(y2)

	a := [1,2]!
	assert dump(a) == [1,2]!
}

copilot:summary

copilot:walkthrough

@felipensp felipensp marked this pull request as ready for review June 8, 2023 20:36
@medvednikov medvednikov merged commit 7a25c03 into vlang:master Jun 9, 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.

builder error: Cannot convert 'unsigned char [4]' to 'struct _v_Array_fixed_u8_4' on println(function())

3 participants