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

Configure Feed

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

Revert warning for todo inside pipeline

+14 -82
+2 -43
compiler-core/src/type_/pipe.rs
··· 53 53 assignments: Vec::with_capacity(size), 54 54 }; 55 55 56 - let first_location = first.location(); 57 - 58 56 // No need to update self.argument_* as we set it above 59 57 typer.push_assignment_no_update(first); 60 58 61 59 // Perform the type checking 62 - typer.infer_expressions(expressions, first_location) 60 + typer.infer_expressions(expressions) 63 61 } 64 62 65 63 fn infer_expressions( 66 64 &mut self, 67 65 expressions: impl IntoIterator<Item = UntypedExpr>, 68 - first_location: SrcSpan, 69 66 ) -> Result<TypedExpr, Error> { 70 - let finally = self.infer_each_expression(expressions, first_location); 67 + let finally = self.infer_each_expression(expressions); 71 68 72 69 // Return any errors after clean-up 73 70 let finally = finally?; ··· 83 80 fn infer_each_expression( 84 81 &mut self, 85 82 expressions: impl IntoIterator<Item = UntypedExpr>, 86 - first_location: SrcSpan, 87 83 ) -> Result<TypedExpr, Error> { 88 84 let mut finally = None; 89 85 let expressions = expressions.into_iter().collect_vec(); 90 - let mut previous_expression_location: Option<SrcSpan> = None; 91 86 92 87 for (i, call) in expressions.into_iter().enumerate() { 93 - self.warn_if_is_todo_or_panic(&call, first_location, previous_expression_location); 94 88 if self.expr_typer.previous_panics { 95 89 self.expr_typer 96 90 .warn_for_unreachable_code(call.location(), PanicPosition::PreviousExpression); ··· 119 113 // right(left) 120 114 call => self.infer_apply_pipe(call)?, 121 115 }; 122 - 123 - previous_expression_location = Some(call.location()); 124 116 125 117 if i + 2 == self.size { 126 118 finally = Some(call); ··· 322 314 } 323 315 } 324 316 _ => false, 325 - } 326 - } 327 - 328 - fn warn_if_is_todo_or_panic( 329 - &self, 330 - call: &UntypedExpr, 331 - first_location: SrcSpan, 332 - previous_expression_location: Option<SrcSpan>, 333 - ) { 334 - let call_todo_or_panic = match call { 335 - UntypedExpr::Todo { .. } => Some(TodoOrPanic::Todo), 336 - UntypedExpr::Call { fun, .. } if fun.is_todo() => Some(TodoOrPanic::Todo), 337 - UntypedExpr::Panic { .. } => Some(TodoOrPanic::Panic), 338 - UntypedExpr::Call { fun, .. } if fun.is_panic() => Some(TodoOrPanic::Todo), 339 - _ => None, 340 - }; 341 - 342 - if let Some(kind) = call_todo_or_panic { 343 - let args_location = if let Some(previous) = previous_expression_location { 344 - Some(SrcSpan::new(first_location.start, previous.end)) 345 - } else { 346 - Some(first_location) 347 - }; 348 - 349 - self.expr_typer 350 - .environment 351 - .warnings 352 - .emit(Warning::TodoOrPanicUsedAsFunction { 353 - kind, 354 - location: call.location(), 355 - args_location, 356 - args: 1, 357 - }) 358 317 } 359 318 } 360 319 }
+11
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__panic_used_as_function_inside_pipeline.snap
··· 1 + --- 2 + source: compiler-core/src/type_/tests/warnings.rs 3 + expression: "\n pub fn wibble(_) { 1 }\n pub fn main() {\n 1 |> panic |> wibble\n }\n " 4 + --- 5 + warning: Unreachable code 6 + ┌─ /src/warning/wrn.gleam:4:27 7 + 8 + 4 │ 1 |> panic |> wibble 9 + │ ^^^^^^ 10 + 11 + This code is unreachable because it comes after a `panic`.
-13
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__panic_used_as_function_inside_pipeline_2.snap
··· 2 2 source: compiler-core/src/type_/tests/warnings.rs 3 3 expression: "\n pub fn wibble(_) { 1 }\n pub fn main() {\n 1 |> panic |> wibble\n }\n " 4 4 --- 5 - warning: Panic used as a function 6 - ┌─ /src/warning/wrn.gleam:4:13 7 - 8 - 4 │ 1 |> panic |> wibble 9 - │ ^ 10 - 11 - `panic` is not a function and will crash before it can do anything with 12 - this argument. 13 - 14 - Hint: if you want to display an error message you should write 15 - `panic as "my error message"` 16 - See: https://tour.gleam.run/advanced-features/panic/ 17 - 18 5 warning: Unreachable code 19 6 ┌─ /src/warning/wrn.gleam:4:27 20 7
-13
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__warnings__unreachable_warning_for_panic_as_last_item_of_pipe_on_next_expression.snap
··· 2 2 source: compiler-core/src/type_/tests/warnings.rs 3 3 expression: "\n pub fn wibble(_) { 1 }\n pub fn main() {\n 1 |> wibble |> panic\n \"unreachable\"\n }\n " 4 4 --- 5 - warning: Panic used as a function 6 - ┌─ /src/warning/wrn.gleam:4:13 7 - 8 - 4 │ 1 |> wibble |> panic 9 - │ ^^^^^^^^^^^ 10 - 11 - `panic` is not a function and will crash before it can do anything with 12 - this argument. 13 - 14 - Hint: if you want to display an error message you should write 15 - `panic as "my error message"` 16 - See: https://tour.gleam.run/advanced-features/panic/ 17 - 18 5 warning: Unreachable code 19 6 ┌─ /src/warning/wrn.gleam:5:13 20 7
+1 -13
compiler-core/src/type_/tests/warnings.rs
··· 1817 1817 } 1818 1818 1819 1819 #[test] 1820 - fn panic_used_as_function_inside_pipeline_1() { 1821 - assert_warning!( 1822 - " 1823 - pub fn wibble(_) { 1 } 1824 - pub fn main() { 1825 - 1 |> wibble |> panic 1826 - } 1827 - " 1828 - ); 1829 - } 1830 - 1831 - #[test] 1832 - fn panic_used_as_function_inside_pipeline_2() { 1820 + fn panic_used_as_function_inside_pipeline() { 1833 1821 assert_warning!( 1834 1822 " 1835 1823 pub fn wibble(_) { 1 }