diff --git a/prql-compiler/src/semantic/transforms.rs b/prql-compiler/src/semantic/transforms.rs index b3009692c4dd..0be029456546 100644 --- a/prql-compiler/src/semantic/transforms.rs +++ b/prql-compiler/src/semantic/transforms.rs @@ -76,7 +76,14 @@ pub fn cast_transform(resolver: &mut Resolver, closure: Closure) -> Result Range::from_ints(None, Some(n)), ExprKind::Range(range) => range, - _ => unimplemented!("`take` range: {expr}"), + _ => bail!(Error::new(Reason::Expected { + who: Some("`take`".to_string()), + expected: "int or range".to_string(), + found: expr.to_string(), + }) + // Possibly this should refer to the item after the `take` where + // one exists? + .with_span(expr.span)), }; (TransformKind::Take { range }, tbl) diff --git a/prql-compiler/src/test.rs b/prql-compiler/src/test.rs index 994cbb80a4ab..8f2fe51ee037 100644 --- a/prql-compiler/src/test.rs +++ b/prql-compiler/src/test.rs @@ -1797,25 +1797,6 @@ fn test_casting() { ); } -#[test] -/// Start testing some error messages. This can hopefully be expanded significantly. -fn test_errors() { - assert_display_snapshot!(compile(r###" - from x - select a - select b - "###).unwrap_err(), - @r###" - Error: - ╭─[:4:12] - │ - 4 │ select b - · ┬ - · ╰── Unknown name b - ───╯ - "###); -} - #[test] fn test_toposort() { // #1183 @@ -2351,3 +2332,37 @@ fn test_closures_and_pipelines() { "### ); } + +#[test] +/// Start testing some error messages. This can hopefully be expanded significantly. +// It's also fine to put errors by the things that they're testing. +fn test_errors() { + assert_display_snapshot!(compile(r###" + from x + select a + select b + "###).unwrap_err(), + @r###" + Error: + ╭─[:4:12] + │ + 4 │ select b + · ┬ + · ╰── Unknown name b + ───╯ + "###); + + assert_display_snapshot!(compile(r###" + from employees + take 1.8 + "###).unwrap_err(), + @r###" + Error: + ╭─[:3:10] + │ + 3 │ take 1.8 + · ─┬─ + · ╰─── `take` expected int or range, but found 1.8 + ───╯ + "###); +}