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

++ (and --) not supported on non-basic types #259

Open
shokrof opened this issue Oct 20, 2019 · 5 comments
Open

++ (and --) not supported on non-basic types #259

shokrof opened this issue Oct 20, 2019 · 5 comments
Labels

Comments

@shokrof
Copy link

shokrof commented Oct 20, 2019

I am trying to run this code, It can't be compiled and the status is just "Error" without any help messages.

Job Reference: http://boa.cs.iastate.edu/boa/?q=boa/job/82449

Robert informed me that the bug is in this line committers[node.author.username]++; and he suggests to change it to 'committers[node.author.username] = 1 + lookup(committers, node.author.username, 0);'

Thanks,
Moustafa

@psybers psybers added the bug label Oct 20, 2019
@neoblizz
Copy link

Are you using comitters as a map[string] of int? I have the exact same issue.

@psybers
Copy link
Member

psybers commented Oct 24, 2019

@neoblizz if you are using a map, you have to be sure the map contains the key you are trying to read before using that value. Otherwise the value is undefined, and it leads to problems later.

Code like this is much safer for reading a value from a map: lookup(m, k, defaultValue) as this will never fail. If the value is in the map you get it, otherwise you get the default.

@psybers psybers changed the title Blank Compilation error ++ (and --) not supported on non-basic types Oct 24, 2019
@psybers
Copy link
Member

psybers commented Oct 24, 2019

This particular bug is specifically regarding the crash when using ++ on a non-basic type (things like a map).

@neoblizz
Copy link

@psybers and just to clarify, the default value is optional there, correct? So, if I wanted to get the value at k, I could just do lookup(m, k)?

@psybers
Copy link
Member

psybers commented Oct 24, 2019

@neoblizz no it is required. The default is what the lookup function returns if the key k is not already in the map. If it is in the map, it returns the value k maps to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants