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

Type mismatch error for map and var assignments reports a different location #3150

Open
lenticularis39 opened this issue May 5, 2024 · 1 comment
Labels
bug Something isn't working difficulty: easy reliability Correctness and polish work

Comments

@lenticularis39
Copy link
Contributor

Assignment of an incorrect type to a map is reported at the location of the map expression, while an assignment of an incorrect type to a variable is reported at the location of the entire assignment statement:

# bpftrace -e 'BEGIN { @a = ""; @a = 1; }'
stdin:1:18-20: ERROR: Type mismatch for @a: trying to assign value of type 'int64' when map already contains a value of type 'string[1]
BEGIN { @a = ""; @a = 1; }
                 ~~
# bpftrace -e 'BEGIN { $a = ""; $a = 1; }'
stdin:1:18-24: ERROR: Type mismatch for $a: trying to assign value of type 'int64' when variable already contains a value of type 'string[1]'
BEGIN { $a = ""; $a = 1; }
                 ~~~~~~

Ideally, the reported location of the error should be consistent between these two cases.

@lenticularis39 lenticularis39 added the bug Something isn't working label May 5, 2024
@jordalgo jordalgo added difficulty: easy reliability Correctness and polish work labels May 5, 2024
@danobi
Copy link
Member

danobi commented May 6, 2024

Makes sense. I think the latter (scratch variable) diagnostic is better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working difficulty: easy reliability Correctness and polish work
Projects
None yet
Development

No branches or pull requests

3 participants