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

Configure Feed

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

improve deprecation error message

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Apr 3, 2026, 3:45 PM +0100) commit 1d5cfb32 parent 61c50768 change-id xmkukpzm
+102 -5
+26
CHANGELOG.md
··· 23 23 update syntax with variants that have no labelled fields. 24 24 ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 25 25 26 + - The error message for invalid deprecated attributes with no deprecation 27 + message has been improved. For example, the following code: 28 + 29 + ```gleam 30 + pub type HashAlgorithm { 31 + @deprecated 32 + Md5 33 + Sha224 34 + Sha512 35 + } 36 + ``` 37 + 38 + Will raise the following error: 39 + 40 + ```txt 41 + error: Syntax error 42 + ┌─ /src/parse/error.gleam:3:3 43 + 44 + 3 │ @deprecated 45 + │ ^^^^^^^^^^^ A deprecation attribute must have a string message. 46 + 47 + See: https://tour.gleam.run/functions/deprecations/ 48 + ``` 49 + 50 + ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) 51 + 26 52 - The compiler now raises a warning on the JavaScript target when defining an 27 53 integer segment with a size higher than 52 bits. For example, this code: 28 54
+5 -4
compiler-core/src/parse.rs
··· 4488 4488 self.parse_external_attribute(start, end, attributes) 4489 4489 } 4490 4490 "target" => self.parse_target_attribute(start, end, attributes), 4491 - "deprecated" => { 4492 - let _ = self.expect_one(&Token::LeftParen)?; 4493 - self.parse_deprecated_attribute(start, end, attributes) 4494 - } 4491 + "deprecated" => self.parse_deprecated_attribute(start, end, attributes), 4495 4492 "internal" => self.parse_internal_attribute(start, end, attributes), 4496 4493 _ => parse_error(ParseErrorType::UnknownAttribute, SrcSpan { start, end }), 4497 4494 }?; ··· 4553 4550 end: u32, 4554 4551 attributes: &mut Attributes, 4555 4552 ) -> Result<u32, ParseError> { 4553 + let _ = self.expect_one(&Token::LeftParen).map_err(|_| ParseError { 4554 + error: ParseErrorType::ExpectedDeprecationMessage, 4555 + location: SrcSpan { start, end }, 4556 + })?; 4556 4557 if attributes.deprecated.is_deprecated() { 4557 4558 return parse_error(ParseErrorType::DuplicateAttribute, SrcSpan::new(start, end)); 4558 4559 }
+1 -1
compiler-core/src/parse/error.rs
··· 216 216 }, 217 217 218 218 ParseErrorType::ExpectedDeprecationMessage => ParseErrorDetails { 219 - text: "".into(), 219 + text: "See: https://tour.gleam.run/functions/deprecations/".into(), 220 220 hint: None, 221 221 label_text: "A deprecation attribute must have a string message.".into(), 222 222 extra_labels: vec![],
+20
compiler-core/src/parse/snapshots/gleam_core__parse__tests__deprecation_with_no_message.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "\n@deprecated\npub fn main() -> Nil {\n Nil\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + @deprecated 8 + pub fn main() -> Nil { 9 + Nil 10 + } 11 + 12 + 13 + ----- ERROR 14 + error: Syntax error 15 + ┌─ /src/parse/error.gleam:2:1 16 + 17 + 2 │ @deprecated 18 + │ ^^^^^^^^^^^ A deprecation attribute must have a string message. 19 + 20 + See: https://tour.gleam.run/functions/deprecations/
+22
compiler-core/src/parse/snapshots/gleam_core__parse__tests__deprecation_with_no_message_on_constructor.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "\npub type HashAlgorithm {\n @deprecated\n Md5\n Sha224\n Sha512\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub type HashAlgorithm { 8 + @deprecated 9 + Md5 10 + Sha224 11 + Sha512 12 + } 13 + 14 + 15 + ----- ERROR 16 + error: Syntax error 17 + ┌─ /src/parse/error.gleam:3:3 18 + 19 + 3 │ @deprecated 20 + │ ^^^^^^^^^^^ A deprecation attribute must have a string message. 21 + 22 + See: https://tour.gleam.run/functions/deprecations/
+2
compiler-core/src/parse/snapshots/gleam_core__parse__tests__deprecation_without_message.snap
··· 16 16 17 17 2 │ @deprecated() 18 18 │ ^^^^^^^^^^^ A deprecation attribute must have a string message. 19 + 20 + See: https://tour.gleam.run/functions/deprecations/
+26
compiler-core/src/parse/tests.rs
··· 771 771 } 772 772 773 773 #[test] 774 + fn deprecation_with_no_message() { 775 + assert_module_error!( 776 + r#" 777 + @deprecated 778 + pub fn main() -> Nil { 779 + Nil 780 + } 781 + "# 782 + ); 783 + } 784 + 785 + #[test] 786 + fn deprecation_with_no_message_on_constructor() { 787 + assert_module_error!( 788 + r#" 789 + pub type HashAlgorithm { 790 + @deprecated 791 + Md5 792 + Sha224 793 + Sha512 794 + } 795 + "# 796 + ); 797 + } 798 + 799 + #[test] 774 800 fn deprecation_without_message() { 775 801 assert_module_error!( 776 802 r#"