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 accepts &int as a key for map[int]int #23069

Open
Krotki opened this issue Dec 5, 2024 · 2 comments
Open

Compiler accepts &int as a key for map[int]int #23069

Krotki opened this issue Dec 5, 2024 · 2 comments
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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Type System Bugs/feature requests, that are related to the V types system.

Comments

@Krotki
Copy link
Contributor

Krotki commented Dec 5, 2024

Describe the bug

Compiler accepts &int as a key for map[int]int instead of pointing out to the developer type difference. This leads to unexpected behavior, because pointer is also a number.

Reproduction Steps

a := 10
ptr := &a
mut m := map[int]int{}
m[ptr] = 1
println(m)

It will print something like {-925552672: 1} which is probably something unexpected by developer.

Expected Behavior

Error from compiler pointing out that I passed &int type, but map expects int.
Additional +10 to stats for suggesting that you can deref it with * f.i.: did you mean m[*ptr] ?

Current Behavior

Compiler accepts pointer and does not show any warning/error.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 e8e6c76

Environment details (OS name and version, etc.)

OS: linux, Linux Mint 21.3
Processor: 20 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i9-12900H

getwd: /home/jakub
vexe: /home/jakub/programy/v/v
vexe mtime: 2024-12-05 09:56:49

vroot: OK, value: /home/jakub/programy/v
VMODULES: OK, value: /home/jakub/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.34.1
Git vroot status: weekly.2024.45-265-ge8e6c760 (1 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
emcc version: N/A
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.
@Krotki Krotki added Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Dec 5, 2024
@spytheman
Copy link
Member

Thank you. Good find.

@spytheman spytheman added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Type System Bugs/feature requests, that are related to the V types system. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Dec 5, 2024
@islonely
Copy link
Contributor

I'm not familiar with how it all works behind the scenes, but this seems to be the same thing happening in #6061 on the surface.

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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Type System Bugs/feature requests, that are related to the V types system.
Projects
None yet
Development

No branches or pull requests

3 participants