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

Allow same enum value #22221

Closed
2 tasks
kbkpbot opened this issue Sep 14, 2024 · 2 comments · Fixed by #22224
Closed
2 tasks

Allow same enum value #22221

kbkpbot opened this issue Sep 14, 2024 · 2 comments · Fixed by #22224
Assignees
Labels
Feature Request This issue is made to request a feature.

Comments

@kbkpbot
Copy link
Contributor

kbkpbot commented Sep 14, 2024

Describe the feature

As in C/C++, enum can has same values

typedef enum
{
    SimdWarpAffineDefault = 0, /*!< Default Warp Affine flags. */
    SimdWarpAffineChannelByte = 0, /*!<  8-bit integer channel type. */
    SimdWarpAffineChannelMask = 1, /*!< Bit mask of channel type. */
    SimdWarpAffineInterpNearest = 0, /*!< Nearest pixel interpolation method. */
    SimdWarpAffineInterpBilinear = 2, /*!< Bilinear pixel interpolation method. */
    SimdWarpAffineInterpMask = 2, /*!< Bit mask of pixel interpolation options. */
    SimdWarpAffineBorderConstant = 0, /*!< Nearest pixel interpolation method. */
    SimdWarpAffineBorderTransparent = 4, /*!< Bilinear pixel interpolation method. */
    SimdWarpAffineBorderMask = 4, /*!< Bit mask of pixel interpolation options. */
} SimdWarpAffineFlags;

But in v, this will cause compile error:

module main

enum SimdWarpAffineFlags {
        simd_warp_affine_default            = 0
        simd_warp_affine_channel_byte       = 0
        simd_warp_affine_channel_mask       = 1
        simd_warp_affine_interp_nearest     = 0
        simd_warp_affine_interp_bilinear    = 2
        simd_warp_affine_interp_mask        = 2
        simd_warp_affine_border_constant    = 0
        simd_warp_affine_border_transparent = 4
        simd_warp_affine_border_mask        = 4
}

fn main() {
}
test.v:5:40: error: enum value `0` already exists
    3 | enum SimdWarpAffineFlags {
    4 |     simd_warp_affine_default            = 0
    5 |     simd_warp_affine_channel_byte       = 0
      |                                           ^
    6 |     simd_warp_affine_channel_mask       = 1
    7 |     simd_warp_affine_interp_nearest     = 0
test.v:7:40: error: enum value `0` already exists
    5 |     simd_warp_affine_channel_byte       = 0
    6 |     simd_warp_affine_channel_mask       = 1
    7 |     simd_warp_affine_interp_nearest     = 0
      |                                           ^
    8 |     simd_warp_affine_interp_bilinear    = 2
    9 |     simd_warp_affine_interp_mask        = 2
test.v:9:40: error: enum value `2` already exists
    7 |     simd_warp_affine_interp_nearest     = 0
    8 |     simd_warp_affine_interp_bilinear    = 2
    9 |     simd_warp_affine_interp_mask        = 2
      |                                           ^
   10 |     simd_warp_affine_border_constant    = 0
   11 |     simd_warp_affine_border_transparent = 4
test.v:10:40: error: enum value `0` already exists
    8 |     simd_warp_affine_interp_bilinear    = 2
    9 |     simd_warp_affine_interp_mask        = 2
   10 |     simd_warp_affine_border_constant    = 0
      |                                           ^
   11 |     simd_warp_affine_border_transparent = 4
   12 |     simd_warp_affine_border_mask        = 4
test.v:12:40: error: enum value `4` already exists
   10 |     simd_warp_affine_border_constant    = 0
   11 |     simd_warp_affine_border_transparent = 4
   12 |     simd_warp_affine_border_mask        = 4
      |                                           ^
   13 | }
   14 |

I think v can also support same values in enum.

Use Case

When rewrite some C/C++ code, it need the same enum values.

Proposed Solution

Fix cgen/checker?

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V full version: V 0.4.7 6e8124f.62ab1be

Environment details (OS name and version, etc.)

V full version: V 0.4.7 6e8124f.62ab1be
OS: linux, Ubuntu 24.04.1 LTS
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz

getwd: /media/HD/github/algo/Simd/src/Simd
vexe: /media/HD/github/lang/v/v
vexe mtime: 2024-09-11 14:36:36

vroot: OK, value: /media/HD/github/lang/v
VMODULES: OK, value: /home/mars/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.0
Git vroot status: weekly.2024.36-47-ge0422de8 (16 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

@kbkpbot kbkpbot added the Feature Request This issue is made to request a feature. label Sep 14, 2024
@spytheman
Copy link
Member

Use @[_allow_multiple_values] to tag the enum.

@Delta456
Copy link
Member

This attribute isn't documented and a hint must be given when this error occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants