mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 07:07:07 +03:00
Error for trying to modify external mappings
This commit is contained in:
parent
75f3647879
commit
2a152c2517
@ -974,6 +974,13 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
// Check that the first argument is a mapping.
|
||||
if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) {
|
||||
// Cannot modify external mappings.
|
||||
if mapping_type.program != self.program_name.unwrap() {
|
||||
self.handler.emit_err(TypeCheckerError::cannot_modify_external_mapping(
|
||||
"set",
|
||||
function_span,
|
||||
));
|
||||
}
|
||||
// Check that the second argument matches the key type of the mapping.
|
||||
self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1);
|
||||
// Check that the third argument matches the value type of the mapping.
|
||||
@ -994,6 +1001,13 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
// Check that the first argument is a mapping.
|
||||
if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) {
|
||||
// Cannot modify external mappings.
|
||||
if mapping_type.program != self.program_name.unwrap() {
|
||||
self.handler.emit_err(TypeCheckerError::cannot_modify_external_mapping(
|
||||
"remove",
|
||||
function_span,
|
||||
));
|
||||
}
|
||||
// Check that the second argument matches the key type of the mapping.
|
||||
self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1);
|
||||
// Return nothing.
|
||||
|
@ -768,4 +768,11 @@ create_messages!(
|
||||
msg: format!("The definition for `{struct_}` in program `{program_1}.aleo` does not match the definition in program `{program_2}.aleo`"),
|
||||
help: Some("Check that the struct definition in the current program matches the definition in the imported program.".to_string()),
|
||||
}
|
||||
|
||||
@formatted
|
||||
cannot_modify_external_mapping {
|
||||
args: (operation: impl Display),
|
||||
msg: format!("Cannot use operation `{operation}` to modify external mapping."),
|
||||
help: Some("The only valid operations on external mappings are get, get_or_use, and contains.".to_string()),
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user