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

Strange error message with @[flag] enum #20924

Open
JalonSolov opened this issue Feb 29, 2024 · 0 comments
Open

Strange error message with @[flag] enum #20924

JalonSolov opened this issue Feb 29, 2024 · 0 comments
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: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).

Comments

@JalonSolov
Copy link
Contributor

JalonSolov commented Feb 29, 2024

Describe the bug

Tried to implement a has method on an enum, but ran into a message that it's a duplicate message.

Reproduction Steps

@[flag]
enum Flags {
	bit0
	bit1
	bit2
	bit3
	bit4
	bit5
	bit6
	bit7
}

fn (f Flags) has(f2 Flags) bool {
	return f & f2 > 0
}

Expected Behavior

Clean compile, or details of the actual problem.

Current Behavior

flag_enum.v:5:29: error: duplicate method `has`
    3 |     bit0
    4 |     bit1
    5 |     bit2
      |         ^
    6 |     bit3
    7 |     bit4

Possible Solution

Turns out, this is because flag enum are currently implemented as bitfields, so the duplication is because of bitfield.has(). However, that is not in any way obvious from the error message, regardless of the message showing the wrong section of code.

Additional Information/Context

If V is going to complain about this, then

  1. It should show the correct location in the code.
  2. It should tell what is being duplicated with more detail, instead of expecting a "treasure hunt" to figure it out.

V version

V 0.4.4 d5370bd

Environment details (OS name and version, etc.)

V full version: V 0.4.4 efa98d9.d5370bd
OS: linux, "Manjaro Linux"
Processor: 32 cpus, 64bit, little endian, AMD Ryzen 9 7950X 16-Core Processor

getwd: /home/jalon/git/vtar
vexe: /home/jalon/git/v/v
vexe mtime: 2024-02-28 13:11:32

vroot: OK, value: /home/jalon/git/v
VMODULES: OK, value: /home/jalon/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.2
Git vroot status: weekly.2024.09-3-gd5370bd2
.git/config present: true

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

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.

@JalonSolov JalonSolov added the Bug This tag is applied to issues which reports bugs. label Feb 29, 2024
@spytheman spytheman added Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Feb 29, 2024
@spytheman spytheman self-assigned this Feb 29, 2024
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: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).
Projects
None yet
Development

No branches or pull requests

2 participants