vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.56k stars 2.15k forks source link

Compiler Bug raised when trying to compile my code #20889

Open gthvn1 opened 4 months ago

gthvn1 commented 4 months ago

V doctor:

V full version: V 0.4.4 27e6fef.667f65b
OS: linux, Debian GNU/Linux 12 (bookworm)
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz

getwd: /home/gthvn1/devel/vervet/src
vexe: /home/gthvn1/git/v/v
vexe mtime: 2024-02-22 17:23:15

vroot: OK, value: /home/gthvn1/git/v
VMODULES: OK, value: /home/gthvn1/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.2
Git vroot status: 667f65bb
.git/config present: true

CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

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

import lexer

fn main() {
    println('Hello sailor!!!')
}

What did you expect to see?

Hello sailor!!!

What did you see instead?

main.v:1:8: warning: module 'lexer' is imported but never used
    1 | import lexer
      |        ~~~~~
    2 | 
    3 | fn main() {
lexer/lexer.v:3:8: warning: module 'token (src.token)' is imported but never used
    1 | module lexer
    2 | 
    3 | import token
      |        ~~~~~
    4 | 
    5 | struct Lexer {
==================
/tmp/v_1000/main.01HQ8XGEXWDCCVGDTJGFP41SG5.tmp.c:673: error: ';' expected (got "MessageError")
...
==================
(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

[!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.

gthvn1 commented 4 months ago

I was just playing with V to discover the language that I found really interesting so my code is probably wrong but it seems that there is a bug in the compiler so I reported the issue as asked in the output log :). The code is available here : https://github.com/gthvn1/vervet/tree/bug_report It is more a playground but it seems that I messed with module..

Hope this will help,

GGRei commented 4 months ago

I cloned your project and tried it based on the information you provided, but I couldn't reproduce the problem, everything works for me. I'm on Ubuntu 23.10 and I used tcc / gcc and clang for the test.

Maybe because I'm on Ubuntu?

Have other people managed to reproduce the problem?

gthvn1 commented 4 months ago

@GGRei thanks for trying to reproduce :+1: . you tried with the branch bug_report I guess? The other point that maybe is not clear is that if I run v run . at the toplevel of the repository it is working. But if I run it in the src/ directory then I see the issue reported. Note that to fix that (as I continue to test) I just moved the v.mod to src/ and it works. So I think that the error is because I don't use tool as expected but as it generates an error when compiling to C code maybe it is interesting.

GGRei commented 4 months ago

@gthvn1 Okay! I didn't realize you were using the v run . command.

Ok, I do see the problem now. Thank you for the additional information!

felipensp commented 3 months ago

Running with clang it shows:

/tmp/v_1000/vervet.01HT5PYW7BQ3NTNS1J0GMAB6ZD.tmp.c:684:3: error: unknown type name 'MessageError'
                MessageError* _MessageError;
                ^
/tmp/v_1000/vervet.01HT5PYW7BQ3NTNS1J0GMAB6ZD.tmp.c:688:2: error: unknown type name 'string'
        string* msg;
        ^
/tmp/v_1000/vervet.01HT5PYW7BQ3NTNS1J0GMAB6ZD.tmp.c:703:2: error: unknown type name 'ArrayFlags'
        ArrayFlags flags;
        ^
/tmp/v_1000/vervet.01HT5PYW7BQ3NTNS1J0GMAB6ZD.tmp.c:724:2: error: must use 'struct' tag to refer to type 'DenseArray'
        DenseArray key_values;
        ^