Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent panic for issues #4474 and #4317 #4538

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
"###);
}
Loading