mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 11:56:54 +03:00
Improve function redefinition error message
This commit is contained in:
parent
8b31fad7a3
commit
0d2d2bb01e
@ -133,12 +133,12 @@ impl<'a> TermParser<'a> {
|
|||||||
def.rules.push(rule);
|
def.rules.push(rule);
|
||||||
} else {
|
} else {
|
||||||
// Trying to add a new rule to a previous definition, coming from a different rule.
|
// Trying to add a new rule to a previous definition, coming from a different rule.
|
||||||
let msg = format!("Redefinition of function '{name}'");
|
let msg = self.redefinition_of_function_msg(builtin, &name);
|
||||||
return self.with_ctx(Err(msg), ini_idx, end_idx);
|
return self.with_ctx(Err(msg), ini_idx, end_idx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Trying to add a new rule to a previous definition, coming from another kind of top-level.
|
// Trying to add a new rule to a previous definition, coming from another kind of top-level.
|
||||||
let msg = format!("Redefinition of function '{name}'");
|
let msg = self.redefinition_of_function_msg(builtin, &name);
|
||||||
return self.with_ctx(Err(msg), ini_idx, end_idx);
|
return self.with_ctx(Err(msg), ini_idx, end_idx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1234,4 +1234,12 @@ pub trait ParserCommons<'a>: Parser<'a> {
|
|||||||
self.consume_exactly("`")?;
|
self.consume_exactly("`")?;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn redefinition_of_function_msg(&self, builtin: bool, function_name: &str) -> String {
|
||||||
|
if builtin {
|
||||||
|
format!("Redefinition of builtin (function) '{function_name}'.")
|
||||||
|
} else {
|
||||||
|
format!("Redefinition of function '{function_name}'.")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1069,8 +1069,8 @@ impl<'a> PyParser<'a> {
|
|||||||
end_idx: usize,
|
end_idx: usize,
|
||||||
builtin: bool,
|
builtin: bool,
|
||||||
) -> ParseResult<()> {
|
) -> ParseResult<()> {
|
||||||
if book.defs.contains_key(&def.name) {
|
if let Some(def) = book.defs.get(&def.name) {
|
||||||
let msg = format!("Redefinition of function '{}'.", def.name);
|
let msg = self.redefinition_of_function_msg(def.builtin, &def.name);
|
||||||
return self.with_ctx(Err(msg), ini_idx, end_idx);
|
return self.with_ctx(Err(msg), ini_idx, end_idx);
|
||||||
}
|
}
|
||||||
if book.ctrs.contains_key(&def.name) {
|
if book.ctrs.contains_key(&def.name) {
|
||||||
|
5
tests/golden_tests/parse_file/redefinition_builtin.bend
Normal file
5
tests/golden_tests/parse_file/redefinition_builtin.bend
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
def Map/get(m):
|
||||||
|
return m
|
||||||
|
|
||||||
|
def main:
|
||||||
|
return *(*(*(*(*(*)))))
|
11
tests/snapshots/parse_file__redefinition_builtin.bend.snap
Normal file
11
tests/snapshots/parse_file__redefinition_builtin.bend.snap
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
source: tests/golden_tests.rs
|
||||||
|
input_file: tests/golden_tests/parse_file/redefinition_builtin.bend
|
||||||
|
---
|
||||||
|
[4m[1m[31mErrors:[0m
|
||||||
|
In tests/golden_tests/parse_file/redefinition_builtin.bend :
|
||||||
|
Redefinition of builtin (function) 'Map/get'.
|
||||||
|
[0m 1 | [4m[31mdef Map/get(m):
|
||||||
|
[0m 2 | [4m[31m return m
|
||||||
|
[0m 3 | [4m[31m
|
||||||
|
[0m 4 | [4m[31m[0mdef main:[0m
|
@ -4,5 +4,5 @@ input_file: tests/golden_tests/parse_file/redefinition_imp_fun.bend
|
|||||||
---
|
---
|
||||||
[4m[1m[31mErrors:[0m
|
[4m[1m[31mErrors:[0m
|
||||||
In tests/golden_tests/parse_file/redefinition_imp_fun.bend :
|
In tests/golden_tests/parse_file/redefinition_imp_fun.bend :
|
||||||
Redefinition of function 'A'
|
Redefinition of function 'A'.
|
||||||
[0m 5 | [4m[31m(A) = 1[0m
|
[0m 5 | [4m[31m(A) = 1[0m
|
||||||
|
@ -4,5 +4,5 @@ input_file: tests/golden_tests/parse_file/redefinition_with_def_between.bend
|
|||||||
---
|
---
|
||||||
[4m[1m[31mErrors:[0m
|
[4m[1m[31mErrors:[0m
|
||||||
In tests/golden_tests/parse_file/redefinition_with_def_between.bend :
|
In tests/golden_tests/parse_file/redefinition_with_def_between.bend :
|
||||||
Redefinition of function 'A'
|
Redefinition of function 'A'.
|
||||||
[0m 4 | [4m[31m(A) = @x x[0m
|
[0m 4 | [4m[31m(A) = @x x[0m
|
||||||
|
@ -4,5 +4,5 @@ input_file: tests/golden_tests/parse_file/redefinition_with_object_between.bend
|
|||||||
---
|
---
|
||||||
[4m[1m[31mErrors:[0m
|
[4m[1m[31mErrors:[0m
|
||||||
In tests/golden_tests/parse_file/redefinition_with_object_between.bend :
|
In tests/golden_tests/parse_file/redefinition_with_object_between.bend :
|
||||||
Redefinition of function 'A'
|
Redefinition of function 'A'.
|
||||||
[0m 3 | [4m[31mA = 1[0m
|
[0m 3 | [4m[31mA = 1[0m
|
||||||
|
@ -4,5 +4,5 @@ input_file: tests/golden_tests/parse_file/redefinition_with_type_between.bend
|
|||||||
---
|
---
|
||||||
[4m[1m[31mErrors:[0m
|
[4m[1m[31mErrors:[0m
|
||||||
In tests/golden_tests/parse_file/redefinition_with_type_between.bend :
|
In tests/golden_tests/parse_file/redefinition_with_type_between.bend :
|
||||||
Redefinition of function 'A'
|
Redefinition of function 'A'.
|
||||||
[0m 3 | [4m[31mA = 1[0m
|
[0m 3 | [4m[31mA = 1[0m
|
||||||
|
Loading…
Reference in New Issue
Block a user