Skip to content

Commit

Permalink
fix: prevent panic for issues #4474 and #4317 (#4538)
Browse files Browse the repository at this point in the history
Co-authored-by: Maximilian Roos <[email protected]>
  • Loading branch information
m-span and max-sixty committed Jun 5, 2024
1 parent 1a3fc6f commit 6f711de
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
**Fixes**:

- Support expressions on left hand side of `std.in` operator. (@kgutwin, #4498)
- Prevent panic for `from {}` and `std` (@m-span, #4538)

**Documentation**:

Expand Down
5 changes: 4 additions & 1 deletion prqlc/prqlc/src/semantic/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ impl Lowerer {
pl::ExprKind::Ident(fq_table_name) => {
// ident that refer to table: create an instance of the table
let id = expr.id.unwrap();
let tid = *self.table_mapping.get(&fq_table_name).unwrap();
let tid = *self
.table_mapping
.get(&fq_table_name)
.ok_or_else(|| Error::new_bug(4474))?;

log::debug!("lowering an instance of table {fq_table_name} (id={id})...");

Expand Down
5 changes: 4 additions & 1 deletion prqlc/prqlc/src/semantic/resolver/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ impl Resolver<'_> {

// add relation frame into scope
if partial_application_position.is_none() {
let frame = arg.lineage.as_ref().unwrap();
let frame = arg
.lineage
.as_ref()
.ok_or_else(|| Error::new_bug(4317).with_span(closure.body.span))?;
if is_last {
self.root_mod.module.insert_frame(frame, NS_THIS);
} else {
Expand Down
37 changes: 37 additions & 0 deletions prqlc/prqlc/tests/integration/bad_error_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,40 @@ fn a_arrow_b() {
Error: internal compiler error; tracked at https://github.com/PRQL/prql/issues/4280
"###);
}

#[test]
fn just_std() {
assert_snapshot!(compile(r###"
std
"###).unwrap_err(), @r###"
Error:
╭─[:2:5]
2 │ std
│ ──┬─
│ ╰─── internal compiler error; tracked at https://github.com/PRQL/prql/issues/4474
───╯
"###);
}

#[test]
fn empty_tuple_from() {
assert_snapshot!(compile(r###"
from {}
"###).unwrap_err(), @r###"
Error: internal compiler error; tracked at https://github.com/PRQL/prql/issues/4317
"###);

assert_snapshot!(compile(r###"
from []
"###).unwrap_err(), @r###"
Error: internal compiler error; tracked at https://github.com/PRQL/prql/issues/4317
"###);

assert_snapshot!(compile(r###"
from {}
select a
"###).unwrap_err(), @r###"
Error: internal compiler error; tracked at https://github.com/PRQL/prql/issues/4317
"###);
}

0 comments on commit 6f711de

Please sign in to comment.