Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix aliases of array insert(...)/prepend(...) (fix #22323) #22324

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 27, 2024

This PR fix aliases of array insert(...)/prepend(...) (fix #22323).

  • Fix aliases of array insert(...)/prepend(...).
  • Add test.
type Strings = []string

fn main() {
	mut strs := Strings(['hi', '1', '5', '3'])
	strs.insert(0, ['33', '22'])
	println(strs)
	strs.prepend('44')
	println(strs)
}

PS D:\Test\v\tt1> v run .
['33', '22', 'hi', '1', '5', '3']
['44', '33', '22', 'hi', '1', '5', '3']

is_arg2_array := arg2_sym.kind == .array
&& node.args[1].typ.clear_flag(.variadic) == node.left_type
&& node.args[1].typ.clear_flag(.variadic) in [node.left_type, g.table.unaliased_type(node.left_type)]
Copy link
Member

Choose a reason for hiding this comment

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

would not just g.table.unaliased_type(node.left_type) work?

Copy link
Member Author

Choose a reason for hiding this comment

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

strs.insert(0, Strings(['22', '33']) needs node.left_type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll optimize it.

Copy link
Member

@spytheman spytheman left a comment

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
Member

The CI failures are not related to the PR.

@spytheman spytheman merged commit c7bdc0a into vlang:master Sep 27, 2024
73 of 78 checks passed
@yuyi98 yuyi98 deleted the fix_array_aliases_insert branch September 27, 2024 04:55
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.

Aliases of array insert()/prepend() generate wrong c codes
2 participants