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

vweb C error when trying to run the following code #15565

Open
floscodes opened this issue Aug 27, 2022 · 6 comments
Open

vweb C error when trying to run the following code #15565

floscodes opened this issue Aug 27, 2022 · 6 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@floscodes
Copy link
Contributor

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

@alwint3r
Copy link
Contributor

alwint3r commented Aug 27, 2022

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 /.

@floscodes
Copy link
Contributor Author

this works, thanks! just reported that, because the compiler told me to do so :-)

@alwint3r
Copy link
Contributor

My pleasure. I think we can close this issue, no?

@floscodes
Copy link
Contributor Author

yes, we can! Thanks!

@WoodyAtHome
Copy link
Contributor

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.

@floscodes
Copy link
Contributor Author

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.

@JalonSolov JalonSolov added the Bug This tag is applied to issues which reports bugs. label Aug 28, 2022
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.
Projects
None yet
Development

No branches or pull requests

4 participants