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

Compiler bug: math operation with number|string|any with a function that return void causes C error instead of type error #23976

Open
AQMpolyface opened this issue Mar 19, 2025 · 5 comments · May be fixed by #24001
Assignees
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: Checker Bugs/feature requests, that are related to the type checker.

Comments

@AQMpolyface
Copy link

AQMpolyface commented Mar 19, 2025

V version: V 0.4.9 87b1de8, press to see full `v doctor` output
V full version V 0.4.9 f83af8a.87b1de8
OS linux, "CachyOS"
Processor 16 cpus, 64bit, little endian, AMD Ryzen 7 Pro 7735U with Radeon Graphics
Memory 2.82GB/30.12GB
V executable /home/polyface/git/v/v
V last modified time 2025-03-19 15:28:03
V home dir OK, value: /home/polyface/git/v
VMODULES OK, value: /home/polyface/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/polyface/Documents/v/bug
Git version git version 2.49.0
V git status weekly.2025.12-6-g87b1de82
.git/config present true
cc version cc (GCC) 14.2.1 20250207
gcc version gcc (GCC) 14.2.1 20250207
clang version clang version 19.1.7
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (GNU libc) 2.41

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

module main

fn main() {
	a := 1 / println('')
}

What did you see?

src/main.v:4:2: warning: unused variable: `a`
    2 | 
    3 | fn main() {
    4 |     a := 1 / println('')
      |     ^
    5 | }
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01JPQG9QA1CVBXSRKHXKXJNW00.tmp.c:1897: error: declaration of void object
=================================================================
(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 .

What did you expect to see?

compiler: mismatched types int literal and void

notes:
this also gets an error, so its not only bultin functions, or ints.

module main

fn main() {
	a := 1 - do_somth()
}

fn do_somth() {
	println('as')
}

You get a correct error when puttinf the function before 1 like

	a := do_somth() - 1 

give the correct error

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.

Copy link

Connected to Huly®: V_0.6-22371

@AQMpolyface AQMpolyface changed the title Compiler bug: math operation function that return void causes C error instead of type error Compiler bug: math operation with number|string|any with a function that return void causes C error instead of type error Mar 19, 2025
@JalonSolov
Copy link
Contributor

V should definitely give you a better error message.

The problem is that println is a void function (it doesn't return anything at all), so you are essentially dividing by 0.

@JalonSolov JalonSolov added the Bug This tag is applied to issues which reports bugs. label Mar 19, 2025
@jorgeluismireles
Copy link

As I understand the problem is that while println('') + 1 gives V error (void + int) as it should, reversing the sum as 1 + println('') gives C error instead V's (int + void).

fn main() {
	//_ := println('') + 1 // gives V error
	_ := 1 + println('') // gives C error
}

@AQMpolyface
Copy link
Author

exactly. Sorry if it wasnt clear

@Delta456
Copy link
Member

Delta456 commented Mar 19, 2025

This is the only with inbuilt functions like println.

It can be replicated with all void types

@Delta456 Delta456 self-assigned this Mar 19, 2025
@Delta456 Delta456 added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Mar 19, 2025
@Delta456 Delta456 linked a pull request Mar 21, 2025 that will close this issue
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: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants