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

C error: use of undeclared identifier 'ADDR' #16366

Closed
Andrew-Eathan opened this issue Nov 8, 2022 · 3 comments
Closed

C error: use of undeclared identifier 'ADDR' #16366

Andrew-Eathan opened this issue Nov 8, 2022 · 3 comments
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@Andrew-Eathan
Copy link

Andrew-Eathan commented Nov 8, 2022

V doctor:

OS: termux, 4.19.157-perf-g46722b073874, #1 SMP PREEMPT Sun Apr 24 16:22:22 CST 2022
Processor: 8 cpus, 64bit, little endian
CC version: clang version 15.0.3

getwd: /data/data/com.termux/files/home/downloads/v/valiant
vmodules: /data/data/com.termux/files/home/.vmodules
vroot: /data/data/com.termux/files/home/downloads/v
vexe: /data/data/com.termux/files/home/downloads/v/v
vexe mtime: 2022-11-08 22:33:04
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.2 a07f77a

Git version: git version 2.38.1
Git vroot status: weekly.2022.45-5-ga07f77ac
.git/config present: true
thirdparty/tcc status: thirdparty-unknown-unknown de82a130

What did you do?
v run . (assuming test.v and valiant.v are in the same folder)

valiant.v:

module valiant

pub struct ReqInfo {
	path string
	params map[string]string
}

pub enum ReqType {
	get
	post
	put
	delete
}

pub struct Server {
pub mut:
	routes map[ReqType] map[string] fn()
}

pub fn get(mut val Server, path string, func fn ()) {
	val.routes[ReqType.get][path] = func
	println("added")
	println(val)
}

pub fn post(val Server, path string, func fn ()) {
	
}

test.v:

module main
import valiant

fn main() {                                                   
    mut server := valiant.Server{}
    valiant.get(mut server, "/", fn () {

    })

    println(server)
    server.routes[valiant.ReqType.get]["/"]()
}

What did you expect to see?
the library i was working on

What did you see instead?

==================
   ^~~~~~~~~~~~~~~
/data/data/com.termux/files/usr/tmp/v_10318/valiant.12471257066786630704.tmp.c:12133:72: error: too many arguments provided to function-like macro invocation
        ((void (*) ())(*(voidptr*)map_get(ADDR(map, ADDR(map, server.routes), &(valiant__ReqType[]){valiant__ReqType__get}, &(voidptr[]){ new_map(sizeof(string), sizeof(anon_fn_), &map_hash_string, &map_eq_string, &map_clone_string, &map_free_string) })))), &(string[]){_SLIT("/")}, &(voidptr[]){ 0 })))();
                                                                              ^
/data/data/com.termux/files/usr/tmp/v_10318/valiant.12471257066786630704.tmp.c:180:9: note: macro 'ADDR' defined here
#define ADDR(type, expr) (&((type[]){ expr }[0]))
        ^
/data/data/com.termux/files/usr/tmp/v_10318/valiant.12471257066786630704.tmp.c:12133:36: error: use of undeclared identifier 'ADDR'
        ((void (*) ())(*(voidptr*)map_get(ADDR(map, ADDR(map, server.routes), &(valiant__ReqType[]){valiant__ReqType__get}, &(voidptr[]){ new_map(sizeof(string), sizeof(anon_fn_), &map_hash_string, &map_eq_string, &map_clone_string, &map_free_string) })))), &(string[]){_SLIT("/")}, &(voidptr[]){ 0 })))();
                                          ^
1 warning and 2 errors generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

it errors on the last line in the main function in test.v

@DevrosTheOne
Copy link

Nested maps access to function execution problem.
Simpler example of the problem (and a work around for now).

fn main() {
	mut smap := map[string]fn (){}
	mut dmap := map[string]map[string]fn (){}

	smap['one'] = fn () {
		println('One')
	}
	dmap['one']['de'] = fn () {
		println('Eine')
	}
	dmap['one']['jp'] = fn () {
		println('Ichi')
	}

	smap['one']()

	// dmap['one']['de']() //throw compile error
	temp := dmap['one']['de']
	temp()
}

@Andrew-Eathan
Copy link
Author

Andrew-Eathan commented Nov 14, 2022 via email

@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Dec 27, 2022
@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Jan 2, 2023
@felipensp
Copy link
Member

Already fixed.

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. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

4 participants