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

Configure Feed

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

Improve parser diagnostics for incomplete @external attributes

+53 -1
+11
CHANGELOG.md
··· 39 39 deprecated. 40 40 ([Surya Rose](https://github.com/GearsDatapacks)) 41 41 42 + - The compiler now gives a better error message when an `@external` 43 + attribute is incomplete. For example: 44 + 45 + ```gleam 46 + @external 47 + pub fn wibble() 48 + ``` 49 + 50 + now points to the attribute itself and explains that it is incomplete. 51 + ([Asish Kumar](https://github.com/officialasishkumar)) 52 + 42 53 ### Build tool 43 54 44 55 - The build tool now generates Hexdocs URLs using the new format of
+4 -1
compiler-core/src/parse.rs
··· 4594 4594 4595 4595 let end = match name.as_str() { 4596 4596 "external" => { 4597 - let _ = self.expect_one(&Token::LeftParen)?; 4597 + let _ = self.maybe_one(&Token::LeftParen).ok_or(ParseError { 4598 + error: ParseErrorType::ExpectedExternalArguments, 4599 + location: SrcSpan { start, end }, 4600 + })?; 4598 4601 self.parse_external_attribute(start, end, attributes) 4599 4602 } 4600 4603 "target" => self.parse_target_attribute(start, end, attributes),
+8
compiler-core/src/parse/error.rs
··· 91 91 ExpectedValue, // no value after "=" 92 92 ExpectedDefinition, // after attributes 93 93 ExpectedDeprecationMessage, // after "deprecated" 94 + ExpectedExternalArguments, // after "@external" 94 95 ExpectedFunctionDefinition, // after function-only attributes 95 96 ExpectedTargetName, // after "@target(" 96 97 ExprLparStart, // it seems "(" was used to start an expression ··· 251 252 text: "See: https://tour.gleam.run/functions/deprecations/".into(), 252 253 hint: None, 253 254 label_text: "A deprecation attribute must have a string message.".into(), 255 + extra_labels: vec![], 256 + }, 257 + 258 + ParseErrorType::ExpectedExternalArguments => ParseErrorDetails { 259 + text: "".into(), 260 + hint: Some("See https://tour.gleam.run/advanced-features/externals/".into()), 261 + label_text: "This attribute is incomplete".into(), 254 262 extra_labels: vec![], 255 263 }, 256 264
+19
compiler-core/src/parse/snapshots/gleam_core__parse__tests__external_with_no_arguments.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "\n@external\npub fn one(x: Int) -> Int {\n todo\n}" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + @external 8 + pub fn one(x: Int) -> Int { 9 + todo 10 + } 11 + 12 + ----- ERROR 13 + error: Syntax error 14 + ┌─ /src/parse/error.gleam:2:1 15 + 16 + 2 │ @external 17 + │ ^^^^^^^^^ This attribute is incomplete 18 + 19 + Hint: See https://tour.gleam.run/advanced-features/externals/
+11
compiler-core/src/parse/tests.rs
··· 748 748 } 749 749 750 750 #[test] 751 + fn external_with_no_arguments() { 752 + assert_module_error!( 753 + r#" 754 + @external 755 + pub fn one(x: Int) -> Int { 756 + todo 757 + }"# 758 + ); 759 + } 760 + 761 + #[test] 751 762 fn unknown_target() { 752 763 assert_module_error!( 753 764 r#"