Skip to content

parser: allow map cast syntax map[k]v(expr)#23401

Merged
spytheman merged 1 commit into
vlang:masterfrom
felipensp:fix_map_cast_syntax
Jan 7, 2025
Merged

parser: allow map cast syntax map[k]v(expr)#23401
spytheman merged 1 commit into
vlang:masterfrom
felipensp:fix_map_cast_syntax

Conversation

@felipensp

@felipensp felipensp commented Jan 7, 2025

Copy link
Copy Markdown
Member

Allow

fn foo() map[int]int {
	return {
		1: 2
	}
}

fn test_main() {
	a := ?map[int]int(none)
	assert a == none

	b := ?map[int]int({
		1: 2
	})
	assert b?[1] == 2

	c := ?map[int]map[string]string({
		1: {
			'foo': 'bar'
		}
	})
	assert c?[1]['foo'] == 'bar'

	d := ?map[int]int(foo())
	assert d?[1] == 2
}

Huly®: V_0.6-21832

@felipensp felipensp marked this pull request as ready for review January 7, 2025 17:30

@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 9fc8352 into vlang:master Jan 7, 2025
@felipensp felipensp deleted the fix_map_cast_syntax branch January 8, 2025 18:33
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.

2 participants