mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-17 14:47:21 +03:00
Return error if there is a String data type definition
This commit is contained in:
parent
89b73cdb02
commit
ab9e71786e
@ -39,7 +39,7 @@ pub fn compile_book(book: &mut Book, opt_level: OptimizationLevel) -> Result<Com
|
||||
pub fn desugar_book(book: &mut Book, opt_level: OptimizationLevel) -> Result<DefId, String> {
|
||||
let main = book.check_has_main()?;
|
||||
book.check_shared_names()?;
|
||||
book.encode_strs();
|
||||
book.encode_strs()?;
|
||||
book.generate_scott_adts();
|
||||
book.resolve_refs();
|
||||
encode_pattern_matching(book)?;
|
||||
|
@ -10,7 +10,11 @@ const HEAD: &str = "head";
|
||||
const TAIL: &str = "tail";
|
||||
|
||||
impl Book {
|
||||
pub fn encode_strs(&mut self) {
|
||||
pub fn encode_strs(&mut self) -> Result<(), String> {
|
||||
if self.adts.contains_key(&Name::new(STRING)) {
|
||||
return Err(format!("String is a built-in data type and should not be overridden."));
|
||||
}
|
||||
|
||||
self.ctrs.insert(Name::new(SNIL), Name::new(STRING));
|
||||
self.ctrs.insert(Name::new(SCONS), Name::new(STRING));
|
||||
|
||||
@ -33,6 +37,8 @@ impl Book {
|
||||
self.ctrs.remove(&Name::new(SCONS));
|
||||
self.adts.remove(&Name::new(STRING));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +70,7 @@ impl Term {
|
||||
let fst_uses = fst.encode_str();
|
||||
let snd_uses = snd.encode_str();
|
||||
fst_uses || snd_uses
|
||||
},
|
||||
}
|
||||
Term::Match { arms, .. } => {
|
||||
let mut used = false;
|
||||
for arm in arms {
|
||||
|
@ -160,7 +160,7 @@ fn encode_pattern_match() {
|
||||
run_golden_test_dir(function_name!(), &|code| {
|
||||
let mut book = do_parse_book(code)?;
|
||||
book.check_shared_names()?;
|
||||
book.encode_strs();
|
||||
book.encode_strs()?;
|
||||
book.generate_scott_adts();
|
||||
book.resolve_refs();
|
||||
encode_pattern_matching(&mut book)?;
|
||||
|
3
tests/golden_tests/compile_file/adt_string.hvm
Normal file
3
tests/golden_tests/compile_file/adt_string.hvm
Normal file
@ -0,0 +1,3 @@
|
||||
data String = S
|
||||
|
||||
main = S
|
5
tests/snapshots/compile_file__adt_string.hvm.snap
Normal file
5
tests/snapshots/compile_file__adt_string.hvm.snap
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/compile_file/adt_string.hvm
|
||||
---
|
||||
String is a built-in data type and should not be overridden.
|
Loading…
Reference in New Issue
Block a user