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 invalid deprecated/external annotations

+99 -3
+4
CHANGELOG.md
··· 278 278 invalid segment. 279 279 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 280 280 281 + - Fixed a confusing error message when writing `@external` or `@deprecated` 282 + annotations with arguments that are not string. 283 + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 284 + 281 285 - Fixed a bug where enabling `javascript.typescript_declarations` or 282 286 `javascript.source_maps` wouldn't generate their additional files unless the 283 287 build directory was manually deleted. The compiler now automatically rebuilds
+9 -3
compiler-core/src/parse.rs
··· 4293 4293 4294 4294 // Expect a String else error 4295 4295 fn expect_string(&mut self) -> Result<(u32, EcoString, u32), ParseError> { 4296 - match self.next_tok() { 4297 - Some((start, Token::String { value }, end)) => Ok((start, value, end)), 4298 - _ => self.next_tok_unexpected(vec!["a string".into()]), 4296 + match self.tok0.take() { 4297 + Some((start, Token::String { value }, end)) => { 4298 + self.advance(); 4299 + Ok((start, value, end)) 4300 + } 4301 + tok0 => { 4302 + self.tok0 = tok0; 4303 + self.next_tok_unexpected(vec!["a string".into()]) 4304 + } 4299 4305 } 4300 4306 } 4301 4307
+18
compiler-core/src/parse/snapshots/gleam_core__parse__tests__parsing_invalid_deprecation_message.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "\n@deprecated(Upname)\nfn wibble() -> Nil\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + @deprecated(Upname) 8 + fn wibble() -> Nil 9 + 10 + 11 + ----- ERROR 12 + error: Syntax error 13 + ┌─ /src/parse/error.gleam:2:1 14 + 15 + 2 │ @deprecated(Upname) 16 + │ ^^^^^^^^^^^ A deprecation attribute must have a string message. 17 + 18 + See: https://tour.gleam.run/functions/deprecations/
+19
compiler-core/src/parse/snapshots/gleam_core__parse__tests__parsing_invalid_external_function_name.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "\n@external(erlang, \"module\", Upname)\nfn wibble() -> Nil\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + @external(erlang, "module", Upname) 8 + fn wibble() -> Nil 9 + 10 + 11 + ----- ERROR 12 + error: Syntax error 13 + ┌─ /src/parse/error.gleam:2:29 14 + 15 + 2 │ @external(erlang, "module", Upname) 16 + │ ^^^^^^ I was not expecting this 17 + 18 + Found a name, expected one of: 19 + - a string
+19
compiler-core/src/parse/snapshots/gleam_core__parse__tests__parsing_invalid_external_module_name.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "\n@external(erlang, Upname, [])\nfn wibble() -> Nil\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + @external(erlang, Upname, []) 8 + fn wibble() -> Nil 9 + 10 + 11 + ----- ERROR 12 + error: Syntax error 13 + ┌─ /src/parse/error.gleam:2:19 14 + 15 + 2 │ @external(erlang, Upname, []) 16 + │ ^^^^^^ I was not expecting this 17 + 18 + Found a name, expected one of: 19 + - a string
+30
compiler-core/src/parse/tests.rs
··· 2411 2411 fn parsing_bit_array_constant_with_invalid_segment_type() { 2412 2412 assert_module_error!("pub const wibble = <<1:Upname>>"); 2413 2413 } 2414 + 2415 + #[test] 2416 + fn parsing_invalid_external_module_name() { 2417 + assert_module_error!( 2418 + " 2419 + @external(erlang, Upname, []) 2420 + fn wibble() -> Nil 2421 + " 2422 + ); 2423 + } 2424 + 2425 + #[test] 2426 + fn parsing_invalid_external_function_name() { 2427 + assert_module_error!( 2428 + r#" 2429 + @external(erlang, "module", Upname) 2430 + fn wibble() -> Nil 2431 + "# 2432 + ); 2433 + } 2434 + 2435 + #[test] 2436 + fn parsing_invalid_deprecation_message() { 2437 + assert_module_error!( 2438 + r#" 2439 + @deprecated(Upname) 2440 + fn wibble() -> Nil 2441 + "# 2442 + ); 2443 + }