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

checker, cgen: fix arrays alias built-in methods call(fix #19896) #19910

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Nov 17, 2023

  1. Fixed it keyword does not work for an aliased array,  #19896
  2. Fixed built-in methods: filter, map, any, all, sort, sorted, contains.
  3. Add tests.
enum MsgType {
	null  = 0
	text  = 1
	ctrl  = 2
	frame = 3
}

struct Msg {
	msg_type MsgType
	payload  []u8
}

type Msgs = []Msg

fn main() {
	msgs0 := [Msg{
		msg_type: .null
	}, Msg{
		msg_type: .text
	}, Msg{
		msg_type: .null
	}, Msg{
		msg_type: .frame
	}]

	// it works without aliased msg
	msgs1 := msgs0.clone()
	null_msgs1 := msgs1.filter(it.msg_type == .null)
	dump(null_msgs1)

	// with aliased array
	msgs2 := Msgs(msgs0)
	null_msgs2 := msgs2.filter(it.msg_type == .null)
	dump(null_msgs2)
}

outputs:

[a.v:29] null_msgs1: [Msg{
    msg_type: null
    payload: []
}, Msg{
    msg_type: null
    payload: []
}]
[a.v:34] null_msgs2: Msgs([Msg{
    msg_type: null
    payload: []
}, Msg{
    msg_type: null
    payload: []
}])

@shove70 shove70 marked this pull request as draft November 17, 2023 10:38
@shove70 shove70 changed the title checker, cgen: make arrays alias can call built-in methods(fix #19896) checker, cgen: fix arrays alias built-in methods call(fix #19896) Nov 17, 2023
@shove70 shove70 marked this pull request as ready for review November 17, 2023 14:14
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 spytheman merged commit aa502c2 into vlang:master Nov 18, 2023
54 checks passed
@shove70 shove70 deleted the alias_it branch November 18, 2023 11:14
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.

it keyword does not work for an aliased array,
2 participants