Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Check type of struct init expression. #2340

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/passes/src/type_checking/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,11 @@ impl<'a> TypeChecker<'a> {

/// Returns the `struct` type and emits an error if the `expected` type does not match.
pub(crate) fn check_expected_struct(&mut self, struct_: Identifier, expected: &Option<Type>, span: Span) -> Type {
if let Some(Type::Identifier(expected)) = expected {
if !struct_.matches(expected) {
self.emit_err(TypeCheckerError::type_should_be(struct_.name, expected.name, span));
if let Some(expected) = expected {
if !Type::Identifier(struct_).eq_flat(expected) {
self.emit_err(TypeCheckerError::type_should_be(struct_.name, expected, span));
}
}

Type::Identifier(struct_)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372003]: Expected type `()` but type `test_credits` was found\n --> compiler-test:11:16\n |\n 11 | return test_credits {\n | ^^^^^^^^^^^^\n"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
namespace: Compile
expectation: Fail
*/

program test.aleo {
record test_credits {
owner: address,
gates: u64,
amount: u64
}

transition mint_credits(to: address, amount: u64) {
return test_credits {
owner: self.caller,
gates: 0u64,
amount
};
}
}