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

Configure Feed

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

Add specific parser error for angle-bracket generics in function definitions

+51
+9
compiler-core/src/parse.rs
··· 2081 2081 n, 2082 2082 )); 2083 2083 } 2084 + if let Some((less_start, less_end)) = self.maybe_one(&Token::Less) { 2085 + return Err(ParseError { 2086 + error: ParseErrorType::FunctionDefinitionAngleGenerics, 2087 + location: SrcSpan { 2088 + start: less_start, 2089 + end: less_end, 2090 + }, 2091 + }); 2092 + } 2084 2093 let _ = self 2085 2094 .expect_one(&Token::LeftParen) 2086 2095 .map_err(|e| self.add_anon_function_hint(e))?;
+16
compiler-core/src/parse/error.rs
··· 117 117 EmptyGuardBlock, 118 118 // When the use tries to define a constant inside a function 119 119 ConstantInsideFunction, 120 + FunctionDefinitionAngleGenerics, // fn something<T>() { ... } 120 121 } 121 122 122 123 pub(crate) struct ParseErrorDetails { ··· 649 650 "Either move this into the global scope or use `let` binding instead.".into(), 650 651 ), 651 652 label_text: "Constants are not allowed inside functions".into(), 653 + extra_labels: vec![], 654 + }, 655 + 656 + ParseErrorType::FunctionDefinitionAngleGenerics => ParseErrorDetails { 657 + text: "\ 658 + Generic function type variables do not need to be predeclared like they 659 + would be in some other languages, instead they are written with lowercase 660 + names. 661 + 662 + fn example(argument: generic) -> generic 663 + 664 + See: https://tour.gleam.run/functions/generic-functions/" 665 + .into(), 666 + hint: None, 667 + label_text: "I was expecting `(` here.".into(), 652 668 extra_labels: vec![], 653 669 }, 654 670 }
+21
compiler-core/src/parse/snapshots/gleam_core__parse__tests__function_definition_angle_generics_error.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "fn id<T>(x: T) { x }" 4 + --- 5 + ----- SOURCE CODE 6 + fn id<T>(x: T) { x } 7 + 8 + ----- ERROR 9 + error: Syntax error 10 + ┌─ /src/parse/error.gleam:1:6 11 + 12 + 1 │ fn id<T>(x: T) { x } 13 + │ ^ I was expecting `(` here. 14 + 15 + Generic function type variables do not need to be predeclared like they 16 + would be in some other languages, instead they are written with lowercase 17 + names. 18 + 19 + fn example(argument: generic) -> generic 20 + 21 + See: https://tour.gleam.run/functions/generic-functions/
+5
compiler-core/src/parse/tests.rs
··· 1942 1942 " 1943 1943 ); 1944 1944 } 1945 + 1946 + #[test] 1947 + fn function_definition_angle_generics_error() { 1948 + assert_module_error!("fn id<T>(x: T) { x }"); 1949 + }