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

it keyword does not work for an aliased array, #19896

Closed
blackshirt opened this issue Nov 16, 2023 · 1 comment · Fixed by #19910
Closed

it keyword does not work for an aliased array, #19896

blackshirt opened this issue Nov 16, 2023 · 1 comment · Fixed by #19910
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Type System Bugs/feature requests, that are related to the V types system.

Comments

@blackshirt
Copy link
Contributor

blackshirt commented Nov 16, 2023

Describe the bug

Code: https://vosca.dev/p/e14c8149cd

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)
}

Reproduction Steps

See example code above

Expected Behavior

i think, it or other way, like closure, should support too for aliased array type

Current Behavior

Output:

code.v:33:29: error: undefined ident: `it`
   31 |     // with aliased array
   32 |     msgs2 := Msgs(msgs0)
   33 |     null_msgs2 := msgs2.filter(it.msg_type == .null)
      |                                ~~
   34 |     dump(null_msgs2)
   35 | }
Exited with error status 1

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.2 fc4c431.fae46a8

Environment details (OS name and version, etc.)

V full version: V 0.4.2 fc4c431.fae46a8
OS: linux, Ubuntu 22.04.2 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz

getwd: /home/pmakhnev/playground
vexe: /home/pmakhnev/v/v
vexe mtime: 2023-10-03 12:00:09

vroot: OK, value: /home/pmakhnev/v
VMODULES: OK, value: /root/.vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.34.1
Git vroot status: 0.4.2-20-gfae46a8d-dirty (343 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@blackshirt blackshirt added the Bug This tag is applied to issues which reports bugs. label Nov 16, 2023
@ArtemkaKun ArtemkaKun added Unit: Type System Bugs/feature requests, that are related to the V types system. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Nov 16, 2023
@shove70
Copy link
Contributor

shove70 commented Nov 17, 2023

Some of built-in methods for array aliases are not yet supported, I think it's because the return type of some methods is not easy to determine, such as:

Alias([]int).filter() => What type is returned?    []int?or Alias([]int)?
Alias([]int).clone()  => ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Type System Bugs/feature requests, that are related to the V types system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants