Skip to content

Commit f6402a7

Browse files
committed
detect bug
1 parent d841289 commit f6402a7

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

interpreter/src/backend/evaluate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ mod tests {
12541254
#[test]
12551255
fn test_loop_3_times() {
12561256
let (result, print_output) = interpret_io(
1257-
"0 =i;{}|loop {i +1 =>i |core/inspect(x) {x |to_str |print} =? 3 |branch {i}{}} :i64",
1257+
"0 =i;{}|loop {i +1 =>i |`core/inspect (x) {|to_str |print} =? 3 |branch {i}{}} :i64",
12581258
"",
12591259
);
12601260
assert_eq!(result, 3);
@@ -1424,7 +1424,7 @@ mod tests {
14241424
// const INSPECT: &str =
14251425
// ";macro(input t: types c :chain) {|function t c ;input} =m_inspect";
14261426
// const INSPECT: &str = ";macro(input t: pnode c :pnode) {|function t c ;input} =m_inspect";
1427-
const INSPECT: &str = ";public function(input t c) {|function[t c] ;input} =m_inspect";
1427+
const INSPECT: &str = ";public macro(input t c) {|function[t c] ;input} =m_inspect";
14281428
#[test]
14291429
fn test_inspect() {
14301430
assert_eq!(

interpreter/src/common.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ pub fn err_span<T, S: AsRef<str>>(
5959
.into())
6060
}
6161
#[track_caller]
62+
pub fn bug_span<T, S: AsRef<str>>(
63+
error_message: S,
64+
code: &SourceCode,
65+
span: Span,
66+
) -> Result<T, AnyError> {
67+
// place your breakpoints here
68+
let caller_location = std::panic::Location::caller();
69+
Err(format!(
70+
"\n{}:\nBug: {}{}",
71+
caller_location,
72+
error_message.as_ref(),
73+
code.format_span(span)
74+
)
75+
.into())
76+
}
77+
#[track_caller]
6278
pub fn err_since<T, S: AsRef<str>>(
6379
error_message: S,
6480
code: &SourceCode,

interpreter/src/middleend/typing.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use strum::IntoEnumIterator;
33

4-
use crate::common::{context, err, err_span, maybe_format_span, AnyError};
4+
use crate::common::{bug, bug_span, context, err, err_span, maybe_format_span, AnyError};
55
use crate::frontend::expression::display::typed_identifiers_to_str;
66
use crate::frontend::expression::{
77
is_macro, Branch, Browse, BrowseOr, Chain, Composed, Comptime, Expression, ExpressionSpan,
@@ -556,7 +556,11 @@ impl<'a> Typer<'a> {
556556
Ok(Operation::single(operator, typed_operand, type_))
557557
}
558558
Operator::Call => self.get_call_type(input, operands, operator.span),
559-
Operator::MacroCall => unimplemented!(),
559+
Operator::MacroCall => bug_span(
560+
"macro calls should not reach the typing stage. Macro call",
561+
self.sources.get_main(),
562+
operator.span,
563+
),
560564
Operator::Get => {
561565
let array = list_any();
562566
let unified_input = self.is_castable_to(input, &array, operator)?;

pipes_programs/corelib/core.pipes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@
3939
}
4040
=inspect
4141

42+
;{
43+
;10 =var
44+
;3 |`inspect (_) {+1 =>var} |assert/eq 3
45+
;var |assert/eq 4
46+
}
47+
4248
;

0 commit comments

Comments
 (0)