Skip to content

cgen error: -(-2) translated into --2 #26813

@forchid

Description

@forchid

Describe the bug

V translates the expression -(-2) into --2 in C source!

Reproduction Steps

the test

testfiles> v conv_test.v
================== C compilation error (from tcc): ==============
cc: .../AppData/Local/Temp/v_0/conv_test.01KN93ZGHHYE13ZDTMGXHT5X09.tmp.c:8144: warning: implicit declaration of function 'GetFinalPathNameByHandleW'
cc: .../AppData/Local/Temp/v_0/conv_test.01KN93ZGHHYE13ZDTMGXHT5X09.tmp.c:8548: error: lvalue expected
...
cc: .../AppData/Local/Temp/v_0/conv_test.01KN93ZGHHYE13ZDTMGXHT5X09.tmp.c:8548: error: lvalue expected
(note: the original output was 9 lines long; it was truncated to its first 2 lines + the last line)
=================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
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 .

the source

// conv_test.v
import strconv

fn test_atoi() ! {
  i := -(-2)
  assert strconv.atoi('1')! == 1
  assert strconv.atoi('-2')! == -2
  assert strconv.atoi('+2')! == i - 1 + 1
  //assert strconv.atoi('+2')! == -(-2)
}

Expected Behavior

Compiling ok.

Current Behavior

Failed to compile.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.5.1 0c3183c

Environment details (OS name and version, etc.)

Windows 10 x64.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions