mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Merge pull request #28193 from ProvableHQ/fix/empty-struct
[Fix] Informative error on empty struct.
This commit is contained in:
commit
475f6d37cc
@ -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() {
|
||||
|
@ -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,
|
||||
}
|
||||
);
|
||||
|
@ -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"
|
12
tests/tests/compiler/structs/empty_struct_fail.leo
Normal file
12
tests/tests/compiler/structs/empty_struct_fail.leo
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
struct Bar {}
|
||||
|
||||
function main() -> bool {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user