Skip to content

cgen: fix code generated for generic option fixed array return type - #20479

Merged
spytheman merged 1 commit into
vlang:masterfrom
felipensp:fix_generic_ret_fixed_array
Jan 11, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
felipensp:fix_generic_ret_fixed_array

Conversation

@felipensp

Copy link
Copy Markdown
Member

Fix #20465

fn example[T]() ?T {
	return T{}
}

fn test_main() {
	dump(example[[1]int]())

	a := example[[1]int]()
	assert a? == [0]!
}

@felipensp
felipensp marked this pull request as ready for review January 11, 2024 01:37

@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

Copy link
Copy Markdown
Contributor

A very similar test, also produces a cgen error, not sure if it is related/easy to fix:

fn example[T]() !T {
	return T{}
}

fn test_main() {
	dump(example[[1]int]()!)

	a := example[[1]int]()!
	assert a == [0]!
}

@spytheman
spytheman merged commit 781d97d into vlang:master Jan 11, 2024
@felipensp
felipensp deleted the fix_generic_ret_fixed_array branch January 11, 2024 12:17
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: Generic Result/Option Function Return Fixed Array

2 participants