Skip to content

Commit d25928b

Browse files
authored
fix: correct target error message to say identifier, not string literal (#6081)
1 parent 0d6fc7a commit d25928b

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

  • prqlc/prqlc-parser/src/parser

prqlc/prqlc-parser/src/parser/stmt.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ where
141141
if let ExprKind::Ident(name) = v.kind {
142142
Some(name.to_string())
143143
} else {
144-
emit.emit(Rich::custom(span, "target must be a string literal"));
144+
emit.emit(Rich::custom(span, "target must be an identifier"));
145145
None
146146
}
147147
})
@@ -273,6 +273,34 @@ mod tests {
273273
crate::parse_test!(source, module_contents().then_ignore(end()))
274274
}
275275

276+
fn parse_query_def(source: &str) -> Result<Stmt, Vec<Error>> {
277+
crate::parse_test!(source, query_def().then_ignore(end()))
278+
}
279+
280+
#[test]
281+
fn query_def_target_string_literal() {
282+
// A `target` given as a string literal rather than an identifier
283+
// should report that it must be an identifier (the valid form is
284+
// `target:sql.duckdb`, not `target:"sql.duckdb"`).
285+
assert_debug_snapshot!(parse_query_def(r#"
286+
prql target:"sql.duckdb"
287+
"#).unwrap_err(), @r#"
288+
[
289+
Error {
290+
kind: Error,
291+
span: Some(
292+
0:0-34,
293+
),
294+
reason: Simple(
295+
"target must be an identifier",
296+
),
297+
hints: [],
298+
code: None,
299+
},
300+
]
301+
"#);
302+
}
303+
276304
#[test]
277305
fn test_module_contents() {
278306
assert_yaml_snapshot!(parse_module_contents(r#"

0 commit comments

Comments
 (0)