Skip to content

Fix panic when getting value from FunctorSet #2367

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

Merged
merged 1 commit into from
May 8, 2025
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
21 changes: 21 additions & 0 deletions compiler/qsc/src/interpret/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,27 @@ mod given_interpreter {
is_unit_with_output_eval_entry(&result, &output, "hello there...");
}

#[test]
fn invalid_partial_application_should_fail_not_panic() {
// Found via fuzzing, see #2363
let source = "operation e(oracle:(w=>)){oracle=i(_)";
let sources = SourceMap::new([("test".into(), source.into())], None);
let (std_id, store) =
crate::compile::package_store_with_stdlib(TargetCapabilityFlags::all());
assert!(
Interpreter::new(
sources,
PackageType::Exe,
TargetCapabilityFlags::all(),
LanguageFeatures::default(),
store,
&[(std_id, None)],
)
.is_err(),
"interpreter should fail with error"
);
}

#[test]
fn errors_returned_if_sources_do_not_match_profile() {
let source = indoc! { r#"
Expand Down
6 changes: 3 additions & 3 deletions compiler/qsc_hir/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,12 @@ impl FunctorSet {
///
/// # Panics
///
/// Panics if this set is not a value.
/// Panics if this set does not have a value.
#[must_use]
pub fn expect_value(self, msg: &str) -> FunctorSetValue {
match self {
Self::Value(value) => value,
Self::Param(_, _) | Self::Infer(_) => panic!("{msg}"),
Self::Value(value) | Self::Param(_, value) => value,
Self::Infer(_) => panic!("{msg}"),
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions compiler/qsc_passes/src/spec_gen/adj_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use qsc_data_structures::span::Span;
use qsc_hir::{
hir::{CallableKind, Expr, ExprKind, Functor, NodeId, UnOp},
mut_visit::{walk_expr, MutVisitor},
ty::{FunctorSet, Ty},
ty::Ty,
};
use thiserror::Error;

Expand All @@ -33,12 +33,10 @@ impl MutVisitor for AdjDistrib {
ExprKind::Call(op, _) => {
match &op.ty {
Ty::Arrow(arrow) if arrow.kind == CallableKind::Operation => {
let functors = match *arrow.functors.borrow() {
FunctorSet::Value(functors) | FunctorSet::Param(_, functors) => {
functors
}
FunctorSet::Infer(_) => panic!("arrow type should have known functors"),
};
let functors = arrow
.functors
.borrow()
.expect_value("arrow type should have known functors");

if functors.contains(&Functor::Adj) {
*op = Box::new(Expr {
Expand Down
Loading