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

Non-atom catch element reported as atom #170

Closed
paulo-ferraz-oliveira opened this issue Jan 15, 2021 · 6 comments · Fixed by #216
Closed

Non-atom catch element reported as atom #170

paulo-ferraz-oliveira opened this issue Jan 15, 2021 · 6 comments · Fixed by #216
Labels

Comments

@paulo-ferraz-oliveira
Copy link
Collaborator

paulo-ferraz-oliveira commented Jan 15, 2021

While

try
    ...
catch
    Throw -> {error, Throw}
end

is perfectly reasonable and possible, elvis still complains that atom Throw "does not respect the format ...".


Edit:

(workaround)

try
    ...
catch
    throw:Exception -> {error, Exception}
end
@elbrujohalcon
Copy link
Member

Wow! Amazing catch!

I bet it has something to do with how ktn_dodger parses that expression, but if it's treating that thing as an atom that's super-weird.

@elbrujohalcon
Copy link
Member

Nope. ktn_dodger correctly interprets that thing as a variable… there is something else going on 🤔

@elbrujohalcon
Copy link
Member

elbrujohalcon commented Jan 15, 2021

It's ktn_code:parse_tree/1's fault… it turns Throw into this weird thing…

 [#{attrs =>
        #{location => {9,5},text => "Throw",value => throw},
    type => atom},
  #{attrs =>
        #{location => {9,5},name => 'Throw',text => "Throw"},
    type => var},
  #{attrs => #{location => {9,5},name => '_',text => "Throw"},
    type => var}]

It's normalizing the rest of the pattern as throw:Throw:_, but incorrectly using the text of the first element as the atom text.
Again… nice catch, @paulo-ferraz-oliveira!

@elbrujohalcon
Copy link
Member

This is where the bug appears:

AtomName0 = ktn_code:attr(text, AtomNode),

We should use value instead of text. But the change has to be done carefully because value is an atom, not a string… and because we want to differentiate between enclosed and non-enclosed macros.

@paulo-ferraz-oliveira paulo-ferraz-oliveira self-assigned this Jan 15, 2021
@paulo-ferraz-oliveira
Copy link
Collaborator Author

I'll try to look at it one of these days, if time allows.

@jackyhui96
Copy link
Contributor

Attempted fixing this with #216
Not sure if it's the best solution but it just handles these cases by using the value attribute when it equals to throw otherwise use text attribute.
Found that just switching to use the text attribute had issues as the values were dropping off the backslashes used to escape characters in the atom.

elbrujohalcon added a commit that referenced this issue Oct 26, 2021
Fix #170 & #186: Non-atom catch element reported as atom
@paulo-ferraz-oliveira paulo-ferraz-oliveira removed their assignment Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants