Merge pull request #28193 from ProvableHQ/fix/empty-struct

[Fix] Informative error on empty struct.
This commit is contained in:
evan-schott 2024-07-08 09:54:37 -07:00 committed by GitHub
commit 475f6d37cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 0 deletions

View File

@ -153,6 +153,10 @@ impl<'a, N: Network> ProgramVisitor<'a> for TypeChecker<'a, N> {
};
check_has_field(sym::owner, Type::Address);
}
// For structs, check that there is at least one member.
else if input.members.is_empty() {
self.emit_err(TypeCheckerError::empty_struct(input.span()));
}
if !(input.is_record && self.scope_state.is_stub) {
for Member { mode, identifier, type_, span, .. } in input.members.iter() {

View File

@ -879,4 +879,11 @@ create_messages!(
msg: format!("The async function `{name}` does not exist."),
help: Some(format!("Ensure that `{name}` is defined as an async function in the current program.")),
}
@formatted
empty_struct {
args: (),
msg: "A struct must have at least one member.".to_string(),
help: None,
}
);

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372112]: A struct must have at least one member.\n --> compiler-test:4:5\n |\n 4 | struct Bar {}\n | ^^^^^^^^^^^^^\nError [ETYC0372083]: A program must have at least one transition function.\n --> compiler-test:1:1\n |\n 1 | \n 2 | \n 3 | program test.aleo {\n | ^^^^^^^^^^^^\n"

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
struct Bar {}
function main() -> bool {
return true;
}
}