v
v copied to clipboard
vweb C error when trying to run the following code
V doctor:
OS: macos, macOS, 12.1, 21C52
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
CC version: Apple clang version 12.0.0 (clang-1200.0.31.1)
getwd: /Users/florian/Desktop/Code/v/server
vmodules: /Users/florian/.vmodules
vroot: /Users/florian/Desktop/Code/v/v
vexe: /Users/florian/Desktop/Code/v/v/v
vexe mtime: 2022-08-27 13:37:43
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 d75c62b
Git version: git version 2.24.3 (Apple Git-128)
Git vroot status: weekly.2022.34-38-gd75c62b8
.git/config present: true
thirdparty/tcc status: thirdparty-macos-amd64 46662e20
What did you do?
v -g -o vdbg cmd/v && vdbg server.v
module main
import vweb
struct App {
vweb.Context
}
pub fn main() {
vweb.run<&App>(index(), 8003)
}
fn index() &App {
mut app:=&App{}
app.text("test")
println("request successful")
return app
}
What did you expect to see?
the server responding with "test"
What did you see instead?
==================
/tmp/v_501/server.8222058182704005005.tmp.c:3020:58: error: expected identifier or '('
typedef struct thread_arg_vweb__handle_conn_T_main__App* {
^
/tmp/v_501/server.8222058182704005005.tmp.c:3024:3: error: must use 'struct' tag to refer to type 'thread_arg_vweb__handle_conn_T_main__App'
} thread_arg_vweb__handle_conn_T_main__App*;
^
struct
/tmp/v_501/server.8222058182704005005.tmp.c:3024:44: error: expected identifier or '('
} thread_arg_vweb__handle_conn_T_main__App*;
^
/tmp/v_501/server.8222058182704005005.tmp.c:3025:36: error: expected ';' after top level declarator
void* vweb__handle_conn_T_main__App*_thread_wrapper(thread_arg_vweb__handle_conn_T_main__App* *arg);
...
==================
(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`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
You might want to change your code into
module main
import vweb
struct App {
vweb.Context
}
fn main() {
vweb.run(&App{}, 8083)
}
pub fn (mut app App) index() vweb.Result {
println("request successful")
return app.text("test")
}
to anyone: please correct me if I'm wrong.
Here's what I understand about the above code:
vweb.run
expects an instance of vweb.Context
or struct App
in this case. Then, you need to implement the index
function as the method of the App
struct.
The code will compile and give the expected response when you send a request to /
.
this works, thanks! just reported that, because the compiler told me to do so :-)
My pleasure. I think we can close this issue, no?
yes, we can! Thanks!
I wouldn't close this issue. C errors should be fixed! Or @floscodes you can close this issue and create a new one with bug label.
I wouldn't close this issue. C errors should be fixed! Or @floscodes you can close this issue and create a new one with bug label.
Ok, then I will leave it open.