-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
fix pattern aliases for strings when targeting erlang #2782
fix pattern aliases for strings when targeting erlang #2782
Conversation
The approach looks great to me! We do something similar to this on JavaScript. Let me know when you would like a code review, thank you. |
Ok, I think im ready for review. Ive made sure that user defined guards are working properly and I've added test to verify that |
7b67fa2
to
ac34ef2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you but we cannot introspect the algebra to learn things about the code. The code is source of information here.
Could you also add comments like the ones you removed please 🙏
compiler-core/src/pretty.rs
Outdated
Vec(docs) => docs.iter().any(|d| d.contains_string(pattern)), | ||
_ => false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this please, it's not appropriate to introspect the printing alegbra, and this isn't a correct implementation as it could be across multiple variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right, sorry
Thank you for the review I appreciate it a lot 💜 Im still not sure where this guard check should happen. Right now I made simple function in patterns module but Im not sure if its feels right. Any suggestions? |
fa2d3f1
to
66d99d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful work! Thank you very much! 💜
66d99d4
to
8589ffa
Compare
Hello, this is my attempt to fix the issue described here
#2733
Currently making aliases for string patterns doesn't work when complied to erlang. The problem is that erlang doesn't allow aliases for constant binary patterns.
My workaround is to match the number of bytes first and then write additional guard to check if matched bytes matches the provided pattern
so that this
becomes this
instead of invalid code that we have today
If this is acceptable approach I still have one issue to fix, If there are some user defined guards on the clause level I have to replace
when
withandalso
to make sure that both guards are supported