-
-
Notifications
You must be signed in to change notification settings - Fork 934
Fix bug in the codegen with a logical guard clauses. #5255
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -622,3 +622,23 @@ pub fn main() { | |
| " | ||
| ); | ||
| } | ||
|
|
||
| // https://github.com/gleam-lang/gleam/issues/5254 | ||
| #[test] | ||
| fn logical_or() { | ||
| assert_js!( | ||
| " | ||
| pub fn main() { | ||
| let a = False | ||
| let b = [] | ||
| let c = True | ||
|
|
||
| let r = case c == True { | ||
| False if a || b == [] -> \"1\" | ||
| _else -> \"0\" | ||
| } | ||
| assert r == \"0\" | ||
| } | ||
| " | ||
| ) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is quite complex, so it's hard to understand. Could you simplify it please 🙏 Is this testing what the issue reported? The title of the issue says it's related to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback, I'll work on it when I have time. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| source: compiler-core/src/javascript/tests/case_clause_guards.rs | ||
| expression: "\n pub fn main() {\n let a = False\n let b = []\n let c = True\n\n let r = case c == True {\n False if a || b == [] -> \"1\"\n _else -> \"0\"\n }\n assert r == \"0\"\n }\n " | ||
| --- | ||
| ----- SOURCE CODE | ||
|
|
||
| pub fn main() { | ||
| let a = False | ||
| let b = [] | ||
| let c = True | ||
|
|
||
| let r = case c == True { | ||
| False if a || b == [] -> "1" | ||
| _else -> "0" | ||
| } | ||
| assert r == "0" | ||
| } | ||
|
|
||
|
|
||
| ----- COMPILED JAVASCRIPT | ||
| import { toList, makeError, isEqual } from "../gleam.mjs"; | ||
|
|
||
| const FILEPATH = "src/module.gleam"; | ||
|
|
||
| export function main() { | ||
| let a = false; | ||
| let b = toList([]); | ||
| let c = true; | ||
| let _block; | ||
| let $ = c === true; | ||
| if (!$ && (a || (isEqual(b, toList([]))))) { | ||
| _block = "1"; | ||
| } else { | ||
| _block = "0"; | ||
| } | ||
| let r = _block; | ||
| let $1 = "0"; | ||
| if (!(r === $1)) { | ||
| throw makeError( | ||
| "assert", | ||
| FILEPATH, | ||
| "my/mod", | ||
| 11, | ||
| "main", | ||
| "Assertion failed.", | ||
| { | ||
| kind: "binary_operator", | ||
| operator: "==", | ||
| left: { kind: "expression", value: r, start: 224, end: 225 }, | ||
| right: { kind: "literal", value: $1, start: 229, end: 232 }, | ||
| start: 217, | ||
| end: 232, | ||
| expression_start: 224 | ||
| } | ||
| ) | ||
| } | ||
| return undefined; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ pub fn main(x, y) { | |
|
|
||
| ----- COMPILED JAVASCRIPT | ||
| export function main(x, y) { | ||
| if (!y && !x) { | ||
| if ((!y && !x)) { | ||
|
||
| return 0; | ||
| } else { | ||
| return 1; | ||
|
|
||
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.
Be more precise with the description please, this sounds like it never worked 🙏