Skip to content

Commit

Permalink
feat(hydroflow_lang): improve singleton error messages/handling (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Apr 2, 2024
1 parent c468d45 commit c9b2fb8
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 4 deletions.
10 changes: 10 additions & 0 deletions hydroflow/tests/compile-fail/surface_singleton_nostate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub fn main() {
let mut df = hydroflow::hydroflow_syntax! {
my_ref = source_iter(15..=25) -> null();
source_iter(10..=30)
-> filter(|value| value <= #my_ref.as_reveal_ref())
-> null();

};
df.run_available();
}
20 changes: 20 additions & 0 deletions hydroflow/tests/compile-fail/surface_singleton_nostate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0425]: cannot find value `singleton_op_2v1` in this scope
--> tests/compile-fail/surface_singleton_nostate.rs:5:16
|
5 | -> filter(|value| value <= #my_ref.as_reveal_ref())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0282]: type annotations needed
--> tests/compile-fail/surface_singleton_nostate.rs:2:18
|
2 | let mut df = hydroflow::hydroflow_syntax! {
| __________________^
3 | | my_ref = source_iter(15..=25) -> null();
4 | | source_iter(10..=30)
5 | | -> filter(|value| value <= #my_ref.as_reveal_ref())
6 | | -> null();
7 | |
8 | | };
| |_____^ cannot infer type
|
= note: this error originates in the macro `hydroflow::hydroflow_syntax` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn main() {
let mut df = hydroflow::hydroflow_syntax! {
my_ref = source_iter(15..=25) -> null();
source_iter(10..=30)
-> filter(|value| value <= #my_ref.as_reveal_ref() && value <= #unknown.as_reveal_ref())
-> null();
};
df.run_available();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Cannot find referenced name `unknown`; name was never assigned.
--> tests/compile-fail/surface_singleton_nostate_undefined.rs:5:77
|
5 | -> filter(|value| value <= #my_ref.as_reveal_ref() && value <= #unknown.as_reveal_ref())
| ^^^^^^^
9 changes: 9 additions & 0 deletions hydroflow/tests/compile-fail/surface_singleton_undefined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn main() {
let mut df = hydroflow::hydroflow_syntax! {
source_iter(10..=30)
-> filter(|value| value <= #unknown.as_reveal_ref())
-> null();

};
df.run_available();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Cannot find referenced name `unknown`; name was never assigned.
--> tests/compile-fail/surface_singleton_undefined.rs:4:41
|
4 | -> filter(|value| value <= #unknown.as_reveal_ref())
| ^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn main() {
let mut df = hydroflow::hydroflow_syntax! {
my_ref = source_iter(15..=25) -> null();
source_iter(10..=30)
-> filter(|value| value <= #unknown.as_reveal_ref() && value <= #my_ref.as_reveal_ref())
-> null();
};
df.run_available();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Cannot find referenced name `unknown`; name was never assigned.
--> tests/compile-fail/surface_singleton_undefined_nostate.rs:5:41
|
5 | -> filter(|value| value <= #unknown.as_reveal_ref() && value <= #my_ref.as_reveal_ref())
| ^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: Cannot find name `hydro_lab`; name was never assigned.
--> tests/compile-fail/surface_undefined_variable.rs:5:9
--> tests/compile-fail/surface_varname_undefined.rs:5:9
|
5 | hydro_lab -> for_each(std::mem::drop);
| ^^^^^^^^^

error: `for_each` must have exactly 1 input(s), actually has 0.
--> tests/compile-fail/surface_undefined_variable.rs:5:22
--> tests/compile-fail/surface_varname_undefined.rs:5:22
|
5 | hydro_lab -> for_each(std::mem::drop);
| ^^^^^^^^^^^^^^^^^^^^^^^^
15 changes: 13 additions & 2 deletions hydroflow_lang/src/graph/flat_graph_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,19 @@ impl FlatGraphBuilder {
.and_then(|result| result.as_ref().ok())
.and_then(|ends| ends.out.as_ref())
.cloned();
let (_port, node_id) = self.helper_resolve_name(port_det, false)?;
Some(node_id)
if let Some((_port, node_id)) = self.helper_resolve_name(port_det, false) {
Some(node_id)
} else {
self.diagnostics.push(Diagnostic::spanned(
singleton_ref.span(),
Level::Error,
format!(
"Cannot find referenced name `{}`; name was never assigned.",
singleton_ref
),
));
None
}
})
.collect();

Expand Down

0 comments on commit c9b2fb8

Please sign in to comment.