Skip to content

Commit

Permalink
Error when a user tries to redefine a field used in a superclass.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltratt committed Jun 9, 2020
1 parent e4a2659 commit 5e00d91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lang_tests/instance_fields_overlap/test.som
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"
VM:
status: error
stderr:
...test.som', line 10, column 23:
test = test_super ( | a |
Field 'a' is already defined in a superclass.
"

test = test_super ( | a |
run = (
)
)
3 changes: 3 additions & 0 deletions lang_tests/instance_fields_overlap/test_super.som
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_super = (
| a |
)
9 changes: 9 additions & 0 deletions src/lib/compiler/ast_to_instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ impl<'a, 'input> Compiler<'a, 'input> {
.iter()
.map(|(k, v)| (k.to_owned(), *v)),
);
for var in ast_inst_vars {
let n = lexer.span_str(*var);
if inst_vars.contains_key(n) {
return Err(vec![(
*var,
format!("Field '{}' is already defined in a superclass.", n),
)]);
}
}
inst_vars
} else {
HashMap::with_capacity(ast_inst_vars.len())
Expand Down

0 comments on commit 5e00d91

Please sign in to comment.