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 error for generic function over maps and arrays #21700

Closed
spytheman opened this issue Jun 19, 2024 · 1 comment · Fixed by #21712
Closed

cgen error for generic function over maps and arrays #21700

spytheman opened this issue Jun 19, 2024 · 1 comment · Fixed by #21712
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Type System Bugs/feature requests, that are related to the V types system.

Comments

@spytheman
Copy link
Member

spytheman commented Jun 19, 2024

V doctor:

V full version: V 0.4.6 c689f80.d7cc5c8
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/oo
vexe: /space/v/oo/v
vexe mtime: 2024-06-19 10:14:30

vroot: OK, value: /space/v/oo
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.2
Git vroot status: weekly.2024.24-25-gd7cc5c88
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

What did you do?
v -g -o vdbg cmd/v && vdbg a.v

fn mkey[K,V](m map[K]V) K { return K{} }
fn mvalue[K,V](m map[K]V) V { return V{} }
fn aelem[E](a []E) E { return E{} }

fn g[T](x T) {
	$if T is $map {
		dk := mkey(x)
		dv := mvalue(x)
		eprintln('default k: `${dk}` | typeof dk: ${typeof(dk).name}')
		eprintln('default v: `${dv}` | typeof dv: ${typeof(dv).name}')
		for k, v in x {
			eprintln('> k: $k | v: $v')
		}
	}
	$if T is $array {
		de := aelem(x)
		eprintln('default e: `${de}` | typeof de: ${typeof(de).name}')
		for idx, e in x {
			eprintln('> idx: $idx | e: $e')
		}
	}
}

g({'abc': 123, 'def': 456})
g([1,2,3])

// Uncommenting one of the lines below leads to a cgen error:
//g({123: 'ggg', 456: 'hhh'})
g(['xyz', 'zzz'])

What did you expect to see?

a compiled program

What did you see instead?

==================
/tmp/v_1000/a.01J0QZVMWFPXR5MVQ2HEV9TGDX.tmp.c:13203: error: '{' expected (got ";")
...
==================
(Use `v -cg` to print the entire error message)

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Type System Bugs/feature requests, that are related to the V types system. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Jun 19, 2024
@spytheman
Copy link
Member Author

Note: when the last 2 lines are commented, the program correctly prints:

default k: `` | typeof dk: string
default v: `0` | typeof dv: int
> k: abc | v: 123
> k: def | v: 456
default e: `0` | typeof de: int
> idx: 0 | e: 1
> idx: 1 | e: 2
> idx: 2 | e: 3

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. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. 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.

2 participants