Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Fix bug with bit array float slice and `Number` constructor

author
Gears
committer
Louis Pilfold
date (Jul 24, 2026, 11:28 AM +0100) commit b59d5d8b parent 6e6af3a6 change-id wyzozmmw
+107 -32
+5
CHANGELOG.md
··· 13 13 whose line broke in the middle of a multi-byte UTF-8 character. 14 14 ([John Downey](https://github.com/jtdowney)) 15 15 16 + - Fixed a bug where invalid JavaScript would be generated for code which used a 17 + bit array pattern to extract a `Float` and had a constructor called `Number`. 18 + ([Surya Rose](https://github.com/GearsDatapacks)) 19 + 20 + 16 21 ## v1.18.0-rc1 - 2026-07-21 17 22 18 23 ### Compiler
+1 -1
compiler-core/src/javascript/decision.rs
··· 1414 1414 1415 1415 docvec![ 1416 1416 arena, 1417 - NUMBER_DOT_IS_FINITE_OPEN_PAREN_DOCUMENT, 1417 + GLOBAL_THIS_DOT_NUMBER_DOT_IS_FINITE_OPEN_PAREN_DOCUMENT, 1418 1418 check, 1419 1419 CLOSE_PAREN_DOCUMENT 1420 1420 ]
+19
compiler-core/src/javascript/tests/case.rs
··· 1108 1108 }"# 1109 1109 ) 1110 1110 } 1111 + 1112 + // https://github.com/gleam-lang/gleam/issues/6029 1113 + #[test] 1114 + fn bit_array_slice_float_with_number_constructor() { 1115 + assert_js!( 1116 + " 1117 + pub type Number { 1118 + Number(Int) 1119 + } 1120 + 1121 + pub fn go(bit_array) { 1122 + case bit_array { 1123 + <<f:float>> -> f 1124 + _ -> 0.0 1125 + } 1126 + } 1127 + " 1128 + ); 1129 + }
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float.snap
··· 18 18 export function go(x) { 19 19 if ( 20 20 x.bitSize >= 64 && 21 - Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 22 22 x.bitSize === 72 23 23 ) { 24 24 let a = bitArraySliceToFloat(x, 0, 64, true);
+4 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float_16_bit.snap
··· 16 16 import { bitArraySliceToFloat } from "../gleam.mjs"; 17 17 18 18 export function go(x) { 19 - if (x.bitSize === 16 && Number.isFinite(bitArraySliceToFloat(x, 0, 16, true))) { 19 + if ( 20 + x.bitSize === 16 && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 16, true)) 22 + ) { 20 23 let a = bitArraySliceToFloat(x, 0, 16, true); 21 24 return a; 22 25 } else {
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float_big_endian.snap
··· 18 18 export function go(x) { 19 19 if ( 20 20 x.bitSize >= 64 && 21 - Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 22 22 x.bitSize === 72 23 23 ) { 24 24 let a = bitArraySliceToFloat(x, 0, 64, true);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float_little_endian.snap
··· 18 18 export function go(x) { 19 19 if ( 20 20 x.bitSize >= 64 && 21 - Number.isFinite(bitArraySliceToFloat(x, 0, 64, false)) && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, false)) && 22 22 x.bitSize === 72 23 23 ) { 24 24 let a = bitArraySliceToFloat(x, 0, 64, false);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float_sized.snap
··· 18 18 export function go(x) { 19 19 if ( 20 20 x.bitSize >= 32 && 21 - Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 22 22 x.bitSize === 40 23 23 ) { 24 24 let a = bitArraySliceToFloat(x, 0, 32, true);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float_sized_big_endian.snap
··· 18 18 export function go(x) { 19 19 if ( 20 20 x.bitSize >= 32 && 21 - Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 22 22 x.bitSize === 40 23 23 ) { 24 24 let a = bitArraySliceToFloat(x, 0, 32, true);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__case_match_float_sized_little_endian.snap
··· 18 18 export function go(x) { 19 19 if ( 20 20 x.bitSize >= 32 && 21 - Number.isFinite(bitArraySliceToFloat(x, 0, 32, false)) && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, false)) && 22 22 x.bitSize === 40 23 23 ) { 24 24 let a = bitArraySliceToFloat(x, 0, 32, false);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float.snap
··· 19 19 let b; 20 20 if ( 21 21 x.bitSize >= 64 && 22 - Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 23 23 x.bitSize === 72 24 24 ) { 25 25 a = bitArraySliceToFloat(x, 0, 64, true);
+4 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float_16_bit.snap
··· 16 16 17 17 export function go(x) { 18 18 let a; 19 - if (x.bitSize === 16 && Number.isFinite(bitArraySliceToFloat(x, 0, 16, true))) { 19 + if ( 20 + x.bitSize === 16 && 21 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 16, true)) 22 + ) { 20 23 a = bitArraySliceToFloat(x, 0, 16, true); 21 24 } else { 22 25 throw makeError(
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float_big_endian.snap
··· 19 19 let b; 20 20 if ( 21 21 x.bitSize >= 64 && 22 - Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) && 23 23 x.bitSize === 72 24 24 ) { 25 25 a = bitArraySliceToFloat(x, 0, 64, true);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float_little_endian.snap
··· 19 19 let b; 20 20 if ( 21 21 x.bitSize >= 64 && 22 - Number.isFinite(bitArraySliceToFloat(x, 0, 64, false)) && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, false)) && 23 23 x.bitSize === 72 24 24 ) { 25 25 a = bitArraySliceToFloat(x, 0, 64, false);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float_sized.snap
··· 19 19 let b; 20 20 if ( 21 21 x.bitSize >= 32 && 22 - Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 23 23 x.bitSize === 40 24 24 ) { 25 25 a = bitArraySliceToFloat(x, 0, 32, true);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float_sized_big_endian.snap
··· 19 19 let b; 20 20 if ( 21 21 x.bitSize >= 32 && 22 - Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true)) && 23 23 x.bitSize === 40 24 24 ) { 25 25 a = bitArraySliceToFloat(x, 0, 32, true);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_float_sized_little_endian.snap
··· 19 19 let b; 20 20 if ( 21 21 x.bitSize >= 32 && 22 - Number.isFinite(bitArraySliceToFloat(x, 0, 32, false)) && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, false)) && 23 23 x.bitSize === 40 24 24 ) { 25 25 a = bitArraySliceToFloat(x, 0, 32, false);
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_32_float_minus_infinity_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 32) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 255 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_32_float_minus_infinity_still_reachable_2.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 32) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 255 && x.byteAt(1) === 128 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_32_float_nan_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 32) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_32_float_nan_still_reachable_2.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 32) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 && x.byteAt(1) === 192 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_32_float_plus_infinity_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 32) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_32_float_plus_infinity_still_reachable_2.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 32) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 32, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 && x.byteAt(1) === 128 &&
+4 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_float_is_unreachable.snap
··· 17 17 import { bitArraySliceToFloat } from "../gleam.mjs"; 18 18 19 19 export function go(x) { 20 - if (x.bitSize === 64 && Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 20 + if ( 21 + x.bitSize === 64 && 22 + globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true)) 23 + ) { 21 24 return "Float"; 22 25 } else { 23 26 return "Other";
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_int_is_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else { 24 24 return "Int";
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_minus_infinity_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 255 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_minus_infinity_still_reachable_2.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 255 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_nan_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_nan_still_reachable_2.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_plus_infinity_still_reachable.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 &&
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_matching_on_64_float_plus_infinity_still_reachable_2.snap
··· 18 18 19 19 export function go(x) { 20 20 if (x.bitSize === 64) { 21 - if (Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 21 + if (globalThis.Number.isFinite(bitArraySliceToFloat(x, 0, 64, true))) { 22 22 return "Float"; 23 23 } else if ( 24 24 x.byteAt(0) === 127 &&
+42
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case__bit_array_slice_float_with_number_constructor.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/case.rs 3 + expression: "\npub type Number {\n Number(Int)\n}\n\npub fn go(bit_array) {\n case bit_array {\n <<f:float>> -> f\n _ -> 0.0\n }\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub type Number { 8 + Number(Int) 9 + } 10 + 11 + pub fn go(bit_array) { 12 + case bit_array { 13 + <<f:float>> -> f 14 + _ -> 0.0 15 + } 16 + } 17 + 18 + 19 + ----- COMPILED JAVASCRIPT 20 + import { CustomType as $CustomType, bitArraySliceToFloat } from "../gleam.mjs"; 21 + 22 + export class Number extends $CustomType { 23 + constructor($0) { 24 + super(); 25 + this[0] = $0; 26 + } 27 + } 28 + export const Number$Number = ($0) => new Number($0); 29 + export const Number$isNumber = (value) => value instanceof Number; 30 + export const Number$Number$0 = (value) => value[0]; 31 + 32 + export function go(bit_array) { 33 + if ( 34 + bit_array.bitSize === 64 && 35 + globalThis.Number.isFinite(bitArraySliceToFloat(bit_array, 0, 64, true)) 36 + ) { 37 + let f = bitArraySliceToFloat(bit_array, 0, 64, true); 38 + return f; 39 + } else { 40 + return 0.0; 41 + } 42 + }
+3 -3
pretty-arena/src/lib.rs
··· 839 839 const_str!(SPACE_GT_EQ_ZERO_DOCUMENT, " >= 0", 5); 840 840 const_str!(SPACE_GT_EQ_SPACE_DOCUMENT, " >= ", 4); 841 841 const_str!( 842 - NUMBER_DOT_IS_FINITE_OPEN_PAREN_DOCUMENT, 843 - "Number.isFinite(", 844 - 16 842 + GLOBAL_THIS_DOT_NUMBER_DOT_IS_FINITE_OPEN_PAREN_DOCUMENT, 843 + "globalThis.Number.isFinite(", 844 + 27 845 845 ); 846 846 const_str!(SPACE_INSTANCE_OF_SPACE_DOCUMENT, " instanceof ", 12); 847 847 const_str!(