Better error for missing member on circuit init

This commit is contained in:
Pranav Gaddamadugu 2022-07-08 10:27:53 -07:00
parent 014959aa24
commit e7f4a41410
3 changed files with 7 additions and 8 deletions

View File

@ -162,9 +162,6 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
}
// Check circuit member types.
// TODO: Leo errors for:
// - missing members on initialization.
// - members that don't exist in the circuit
circ.members
.iter()
.for_each(|CircuitMember::CircuitVariable(name, ty)| {
@ -174,9 +171,11 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
self.visit_expression(expr, &Some(*ty));
}
} else {
self.handler.emit_err(
TypeCheckerError::unknown_sym("circuit member variable", name, name.span()).into(),
);
self.handler.emit_err(TypeCheckerError::missing_circuit_member(
circ.identifier,
name,
input.span(),
));
};
});

View File

@ -216,7 +216,7 @@ create_messages!(
missing_circuit_member {
args: (circuit: impl Display, member: impl Display),
msg: format!(
"Circuit `{circuit}` missing member `{member}`.",
"Circuit initialization expression for `{circuit}` is missing member `{member}`.",
),
help: None,
}

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372006]: Unknown circuit member variable `owner`\n --> compiler-test:5:5\n |\n 5 | owner: address,\n | ^^^^^\n"
- "Error [ETYC0372019]: Circuit initialization expression for `Token` is missing member `owner`.\n --> compiler-test:13:12\n |\n 13 | return Token {\n 14 | sender: r0, // This variable should be named `owner`.\n 15 | balance: 0u64,\n 16 | amount: r1,\n 17 | };\n | ^^^^^^\n"