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

The pattern nothing matches any expressions #60

Closed
lihebi opened this issue May 25, 2020 · 2 comments
Closed

The pattern nothing matches any expressions #60

lihebi opened this issue May 25, 2020 · 2 comments

Comments

@lihebi
Copy link

lihebi commented May 25, 2020

The pattern nothing seems to successfully match any expressions:

@match 1 begin
    nothing => true
    _ => false
end
# => true
@match "hello" begin
    nothing => true
    _ => false
end
# => true
@caseykneale
Copy link

Someone in the Julia discord found a similar bug that has a similar smell too it.

g = @match Symbol begin
    String => 1
    Symbol => 2
    _ => 3
end

will give g == 1.
Infact, you can change the type of the first match condition to anything and I believe it will always select the first condition for it's result.

Not sure what's going on in this case, the quick fix I suggested to them was to convert types to symbols and match or if/then on those.

@gafter
Copy link
Member

gafter commented Aug 3, 2023

An identifier as a pattern matches any input and binds the input to a variable of that name. nothing and String are just names that can be bound.

If you want to test for the value nothing, use the pattern $nothing.

If you want to test for the type String, use the pattern ::String.

@gafter gafter closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants