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

for loop not possible for indexexpr with sumtype of array types in coma separated match branch #18548

Closed
ttytm opened this issue Jun 24, 2023 · 0 comments · Fixed by #19988
Closed
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@ttytm
Copy link
Member

ttytm commented Jun 24, 2023

Describe the bug

type MySumType = []MyStructA | []MyStructB

struct ParentStruct {
	parent_field string
}

struct MyStructA {
	ParentStruct
}

struct MyStructB {
	ParentStruct
}

fn check(mut t MySumType) {
	match mut t {
		[]MyStructA, []MyStructB {
			// println(t[0].parent_field) // possible now, thanks felipe
			for v in t {
				println(v.parent_field)
			}
		}
	}
}

fn main() {
	s := MyStructA{
		parent_field: 'common'
	}

	mut t := MySumType([s])

	check(mut t)
	assert true
}

Expected Behavior

Looping the array variant is possible.

Current Behavior

sum_arr.v:19:13: error: for in: cannot index `([]MyStructA | []MyStructB)`
   17 |         []MyStructA, []MyStructB {
   18 |             // println(t[0].parent_field) // possible
   19 |             for v in t {
      |                      ^
   20 |                 println(v.parent_field)
   21 |             }
sum_arr.v:20:15: error: `v` does not return a value
   18 |             // println(t[0].parent_field) // possible
   19 |             for v in t {
   20 |                 println(v.parent_field)
      |                           ~~~~~~~~~~~~
   21 |             }
   22 |         }

Reproduction Steps

Possible Solution

No response

Additional Information/Context

No response

V version

0.3.4

Environment details (OS name and version, etc.)

V full version: V 0.3.4 34ac326.ad10282
OS: linux, "Manjaro Linux"
Processor: 16 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz

getwd: /home/turiiya/Dev/vlang/v
vexe: /home/turiiya/Dev/vlang/v/v
vexe mtime: 2023-06-24 23:31:07

vroot: OK, value: /home/turiiya/Dev/vlang/v
VMODULES: OK, value: /home/turiiya/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.41.0
Git vroot status: weekly.2023.25-32-gad102829 (3 commit(s) behind V master)
.git/config present: true

CC version: cc (GCC) 13.1.1 20230429
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
@ttytm ttytm added the Bug This tag is applied to issues which reports bugs. label Jun 24, 2023
@felipensp felipensp added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Jun 25, 2023
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: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants