Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/sema/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@ impl Type {
.max()
.unwrap_or(1), // All fields had infinite size, so we just pretend the alignment is one
Type::InternalFunction { .. } => ns.target.ptr_size().into(),
Type::UserType(no) => ns.user_types[*no].ty.align_of(ns),
_ => 1,
}
}
Expand Down Expand Up @@ -1835,6 +1836,7 @@ impl Type {
Type::Mapping(..) => BigInt::from(4),
Type::Ref(ty) | Type::StorageRef(_, ty) => ty.storage_align(ns),
Type::Unresolved => BigInt::one(),
Type::UserType(no) => ns.user_types[*no].ty.storage_align(ns),
_ => unimplemented!(),
};

Expand Down
37 changes: 37 additions & 0 deletions tests/solana_tests/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,40 @@ fn struct_as_reference() {
])
);
}

#[test]
fn user_defined_type_in_struct() {
let mut vm = build_solidity(
r#"
type C is address;
struct S { C c; }
contract T {
S s;
function set_c(C c) public {
s.c = c;
}
function get_c() public view returns (C) {
return s.c;
}
}
"#,
);

let data_account = vm.initialize_data_account();
vm.function("new")
.accounts(vec![("dataAccount", data_account)])
.call();

let address = [0x42; 32];
vm.function("set_c")
.arguments(&[BorshToken::Address(address)])
.accounts(vec![("dataAccount", data_account)])
.call();

let res = vm
.function("get_c")
.accounts(vec![("dataAccount", data_account)])
.call()
.unwrap();
assert_eq!(res, BorshToken::Address(address));
}