prohibit external record creation

This commit is contained in:
evan-schott 2024-01-12 20:17:19 -08:00
parent b7bd4060ec
commit d4aed52344
2 changed files with 14 additions and 2 deletions

View File

@ -437,12 +437,17 @@ impl ParserContext<'_> {
// Parse function name.
let name = self.expect_identifier()?;
// Parsing a '{' means that user is trying to illegally define an external record.
if self.token.token == Token::LeftCurly {
return Err(ParserError::cannot_define_external_record(expr.span() + name.span()).into());
}
// Parse the function call.
let (arguments, _, span) = self.parse_paren_comma_list(|p| p.parse_expression().map(Some))?;
// Parse the parent program identifier.
let program: Option<ProgramId> = match expr {
Expression::Identifier(identifier) => Some(ProgramId::from(identifier)),
let program: Option<Symbol> = match expr {
Expression::Identifier(identifier) => Some(identifier.name),
_ => unreachable!("Function called must be preceded by a program identifier."),
};

View File

@ -335,4 +335,11 @@ create_messages!(
msg: format!("Only external calls to `.aleo` programs are supported."),
help: None,
}
@formatted
cannot_define_external_record {
args: (),
msg: format!("Cannot create an external record. Records can only be created from scratch in the program that they are defined in."),
help: None,
}
);