Skip to content

Failed to compile the assert expression with the sub expression -(-2) or +2Β #26815

@forchid

Description

@forchid

Describe the bug

In the expression assert, failed to compile those simple math sub expressions such as -(-2) , +2.

Reproduction Steps

the test

testfiles> v conv_test.v
conv_test.v:8:33: error: invalid expression: unexpected token `==`
    6 |   assert strconv.atoi('-2')! == -2
    7 |   assert strconv.atoi('+2')! == i - 1 + 1
    8 |   assert strconv.atoi('+2')! == -(-2)
      |                                 ^
    9 |   assert strconv.atoi('+2')! == +2
   10 | }
testfiles> v conv_test.v
conv_test.v:9:33: error: invalid expression: unexpected token `+`
    7 |   assert strconv.atoi('+2')! == i - 1 + 1
    8 |   //assert strconv.atoi('+2')! == -(-2)
    9 |   assert strconv.atoi('+2')! == +2
      |                                 ^
   10 | }
testfiles>

the test source

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)
  assert strconv.atoi('+2')! == +2
}

Expected Behavior

Compiling ok.

Current Behavior

Failed to compile it.

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

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