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.8k stars 2.17k forks source link

import m where src/m/m.v has just "module m" will crash c #22711

Open markfirmware opened 1 week ago

markfirmware commented 1 week ago

V doctor:

V full version: V 0.4.8 df4c6ac.6cfa84c
OS: linux, Debian GNU/Linux 12 (bookworm) (VM)
Processor: 1 cpus, 64bit, little endian, DO-Premium-AMD

getwd: /home/user/github.com/markfirmware/line2
vexe: /home/user/github.com/vlang/v/v
vexe mtime: 2024-10-31 02:29:00

vroot: OK, value: /home/user/github.com/vlang/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.5
Git vroot status: weekly.2024.44-7-g6cfa84c9
.git/config present: true

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

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

// Also required is src/line/line.v which contains one line, the module declaration:
//
//   module line

module main
import line

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

What did you expect to see?

What did you see instead?

src/main.v:6:8: warning: module 'line' is imported but never used
    4 | 
    5 | module main
    6 | import line
      |        ~~~~
    7 | 
    8 | fn main() {
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01JBG6GYKAY46Z4S5EAF39S55P.tmp.c:707: error: ';' expected (got "None__")
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto 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.

Huly®: V_0.6-21159

spytheman commented 1 week ago

That worked for me πŸ€”, there were no cgen errors:

#0 07:23:34 ^ opt_fixes /v/oo>mkdir -p mmm
#0 07:23:39 ^ opt_fixes /v/oo>cd mmm/
#0 07:23:40 ^ opt_fixes /v/oo/mmm>mkdir -p src/
#0 07:24:30 ^ opt_fixes /v/oo/mmm>cat src/main.v
cat: src/main.v: No such file or directory
#1 07:24:35 ^ opt_fixes /v/oo/mmm>cat > src/main.v
module main
import line

fn main() {
        println('Hello World!')
}
#0 07:24:40 ^ opt_fixes /v/oo/mmm>mkdir -p src/line/
#0 07:24:48 ^ opt_fixes /v/oo/mmm>cat > src/line/line.v
module line
#0 07:25:03 ^ opt_fixes /v/oo/mmm>v src/main.v
src/main.v:2:8: warning: module 'line' is imported but never used
    1 | module main
    2 | import line
      |        ~~~~
    3 |
    4 | fn main() {
#0 07:25:08 ^ opt_fixes /v/oo/mmm>cat src/line/line.v
module line
#0 07:25:26 ^ opt_fixes /v/oo/mmm>
#0 07:25:26 ^ opt_fixes /v/oo/mmm>cat src/main.v
module main
import line

fn main() {
        println('Hello World!')
}
#0 07:25:31 ^ opt_fixes /v/oo/mmm>tree
.
└── src
    β”œβ”€β”€ line
    β”‚Β Β  └── line.v
    β”œβ”€β”€ main
    └── main.v

2 directories, 3 files
#0 07:25:36 ^ opt_fixes /v/oo/mmm>

I am on a branch that is a few commits after current master though.

spytheman commented 1 week ago

It works on latest master too:

#0 07:27:50 ^ opt_fixes /v/oo>git co master
Switched to branch 'master'
#0 07:28:18 ^ master /v/oo>git pull
Already up to date.
#0 07:28:23 ^ master /v/oo>./v self
V self compiling ...
V built successfully as executable "v".
#0 07:28:27 ^ master /v/oo>./v version
V 0.4.8 4e9b21f
#0 07:28:29 ^ master /v/oo>cd mmm/
#0 07:28:31 ^ master /v/oo/mmm>v run src/main.v
src/main.v:2:8: warning: module 'line' is imported but never used
    1 | module main
    2 | import line
      |        ~~~~
    3 |
    4 | fn main() {
Hello World!
#0 07:28:45 ^ master /v/oo/mmm>

I think there may be another factor involved πŸ€” .

Can you please check, if there are sibling folders, named line or src in one of the parent folders of your project?

spytheman commented 1 week ago

Another thing to try is v -print-v-files src/main.v . (v -print-v-files . can work too, but will need a local v.mod file)

markfirmware commented 1 week ago

A fresh entry with m in top worked, then I mv m src and it crashed c.

I ran v . from top, not from src

markfirmware commented 1 week ago

Moving m from src back to top and it works again (running v . when in top folder.)

markfirmware commented 1 week ago

So what I have is

src/main.v

module main import m

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

src/m/m.v

module m