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

Bug matching types? #12

Closed
weinbe58 opened this issue Dec 1, 2023 · 3 comments
Closed

Bug matching types? #12

weinbe58 opened this issue Dec 1, 2023 · 3 comments
Labels
match syntatical pattern match related warn need a warning for this issue wontfix This will not be worked on

Comments

@weinbe58
Copy link
Collaborator

weinbe58 commented Dec 1, 2023

The following doesn't match correctly; maybe I'm doing something wrong?

result = @match Float64 begin
           Int => "here"
           Float64 => "there"
end

result evaluates to: "here"

@weinbe58 weinbe58 added bug Something isn't working match syntatical pattern match related labels Dec 1, 2023
@Roger-luo
Copy link
Owner

Ah, I think this is one of the limitations of implementing match as a macro... this is because we are not able to access the scope information of a Julia program, so the single Symbol pattern is ambiguous. Consider the following case

function foo(x, Float64)
   @match x begin
       Int => "here"
       Float64 => "there"
   end
end

foo(1.0, 1.0) # should match what?

thus the single Symbol pattern is always treated as a variable to dis-ambiguous this semantics. To do what you intended here,
you just need to "quote" the value as if you are quoting it in other Julia expression, e.g

@match Float64 begin
   $Int => "here"
   $Float64 => "there"
end

this was the & in MLStyle, but see discussion here thautwarm/MLStyle.jl#160

@Roger-luo Roger-luo added wontfix This will not be worked on and removed bug Something isn't working labels Dec 2, 2023
@Roger-luo
Copy link
Owner

also note that we automatically insert $ for you in a lot of cases when it's not ambiguous, so this is not a big deal if you find it's working. After thinking a bit more on this, I believe we should add a warning when the pattern variable has a definition in the global scope.

@Roger-luo Roger-luo added the warn need a warning for this issue label Dec 2, 2023
Roger-luo added a commit that referenced this issue Dec 2, 2023
Roger-luo added a commit that referenced this issue Dec 2, 2023
@Roger-luo
Copy link
Owner

Ok this now gives you a warning

Roger-luo added a commit that referenced this issue Dec 2, 2023
* add warning for #12

* improve error msg

* add line info to pattern compile error

* more precise line info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
match syntatical pattern match related warn need a warning for this issue wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants