-
-
Notifications
You must be signed in to change notification settings - Fork 888
fix js codegen allowing underscore after decimal #5125
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| source: compiler-core/src/javascript/tests/numbers.rs | ||
| expression: "\npub fn main(x) {\n -100.001e123_456_789 /. 100.001e123_456_789\n}\n" | ||
| --- | ||
| ----- SOURCE CODE | ||
|
|
||
| pub fn main(x) { | ||
| -100.001e123_456_789 /. 100.001e123_456_789 | ||
| } | ||
|
|
||
|
|
||
| ----- COMPILED JAVASCRIPT | ||
| export function main(x) { | ||
| return -Infinity / Infinity; | ||
| } |
|
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.
A very large float, as seen in this test: case x {
100.001e123_456_789 -> "bar"
_ -> "foo"
}
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. Could you share a full reproduction please? I couldn't reproduce it with that snippet.
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 generates invalid code for me with pub fn main(n: Float) {
case n {
100.001e123_456_789 -> "wibble"
_ -> "wobble"
}
}The code indeed has that export function main(n) {
if (n === inf) {
return "wibble";
} else {
return "wobble";
}
}This happens on main
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. Yep, the issue is reproducible on main, but I fixed it in f3e449e in this PR (see below). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| source: compiler-core/src/javascript/tests/numbers.rs | ||
| expression: "\npub fn main(x) {\n case x {\n 100.001e123_456_789 -> \"bar\"\n _ -> \"foo\"\n }\n}\n" | ||
| --- | ||
| ----- SOURCE CODE | ||
|
|
||
| pub fn main(x) { | ||
| case x { | ||
| 100.001e123_456_789 -> "bar" | ||
| _ -> "foo" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| ----- COMPILED JAVASCRIPT | ||
| export function main(x) { | ||
| if (x === Infinity) { | ||
| return "bar"; | ||
| } else { | ||
| return "foo"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| source: compiler-core/src/javascript/tests/numbers.rs | ||
| expression: "\npub fn main() {\n 0._1\n}\n" | ||
| --- | ||
| ----- SOURCE CODE | ||
|
|
||
| pub fn main() { | ||
| 0._1 | ||
| } | ||
|
|
||
|
|
||
| ----- COMPILED JAVASCRIPT | ||
| export function main() { | ||
| return 0.1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| source: compiler-core/src/javascript/tests/numbers.rs | ||
| expression: "\npub fn main(x) {\n case x {\n 0._1 -> \"bar\"\n _ -> \"foo\"\n }\n}\n" | ||
| --- | ||
| ----- SOURCE CODE | ||
|
|
||
| pub fn main(x) { | ||
| case x { | ||
| 0._1 -> "bar" | ||
| _ -> "foo" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| ----- COMPILED JAVASCRIPT | ||
| export function main(x) { | ||
| if (x === 0.1) { | ||
| return "bar"; | ||
| } else { | ||
| return "foo"; | ||
| } | ||
| } |
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.
This is fix for the JavaScript infinity special case