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

Configure Feed

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

improve error message for constant bit arrays with invalid segment

+43 -10
+4
CHANGELOG.md
··· 275 275 that is not a literal number. 276 276 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 277 277 278 + - Fixed a confusing error message when writing a constant bit array with an 279 + invalid segment. 280 + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 281 + 278 282 - Fixed a bug where enabling `javascript.typescript_declarations` or 279 283 `javascript.source_maps` wouldn't generate their additional files unless the 280 284 build directory was manually deleted. The compiler now automatically rebuilds
+17 -10
compiler-core/src/parse.rs
··· 3797 3797 arg_parser: &impl Fn(&mut Self) -> Result<A, ParseError>, 3798 3798 to_int_segment: &impl Fn(EcoString, BigInt, u32, u32) -> A, 3799 3799 ) -> Result<Option<BitArrayOption<A>>, ParseError> { 3800 - match self.next_tok() { 3800 + match self.tok0.take() { 3801 3801 // named segment 3802 3802 Some((start, Token::Name { name }, end)) => { 3803 + self.advance(); 3803 3804 if self.maybe_one(&Token::LeftParen).is_some() { 3804 3805 // named function segment 3805 3806 match name.as_str() { ··· 3853 3854 } 3854 3855 } 3855 3856 // int segment 3856 - Some((start, Token::Int { value, int_value }, end)) => Ok(Some(BitArrayOption::Size { 3857 - location: SrcSpan { start, end }, 3858 - value: Box::new(to_int_segment(value, int_value, start, end)), 3859 - short_form: true, 3860 - })), 3857 + Some((start, Token::Int { value, int_value }, end)) => { 3858 + self.advance(); 3859 + Ok(Some(BitArrayOption::Size { 3860 + location: SrcSpan { start, end }, 3861 + value: Box::new(to_int_segment(value, int_value, start, end)), 3862 + short_form: true, 3863 + })) 3864 + } 3861 3865 // invalid 3862 - _ => self.next_tok_unexpected(vec![ 3863 - "A valid bit array segment type".into(), 3864 - "See: https://tour.gleam.run/data-types/bit-arrays/".into(), 3865 - ]), 3866 + tok0 => { 3867 + self.tok0 = tok0; 3868 + self.next_tok_unexpected(vec![ 3869 + "A valid bit array segment type".into(), 3870 + "See: https://tour.gleam.run/data-types/bit-arrays/".into(), 3871 + ]) 3872 + } 3866 3873 } 3867 3874 } 3868 3875
+17
compiler-core/src/parse/snapshots/gleam_core__parse__tests__parsing_bit_array_constant_with_invalid_segment_type.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "pub const wibble = <<1:Upname>>" 4 + --- 5 + ----- SOURCE CODE 6 + pub const wibble = <<1:Upname>> 7 + 8 + ----- ERROR 9 + error: Syntax error 10 + ┌─ /src/parse/error.gleam:1:24 11 + 12 + 1 │ pub const wibble = <<1:Upname>> 13 + │ ^^^^^^ I was not expecting this 14 + 15 + Found a name, expected one of: 16 + - A valid bit array segment type 17 + - See: https://tour.gleam.run/data-types/bit-arrays/
+5
compiler-core/src/parse/tests.rs
··· 2379 2379 fn parsing_bit_array_constant_with_non_integer_unit() { 2380 2380 assert_module_error!("pub const wibble = <<1:unit(something)>>"); 2381 2381 } 2382 + 2383 + #[test] 2384 + fn parsing_bit_array_constant_with_invalid_segment_type() { 2385 + assert_module_error!("pub const wibble = <<1:Upname>>"); 2386 + }