So I'm having two problems with returning arrays from external functions:
Case One: arrays in getters
contract A {
mapping(address => uint8[10]) public gameBoards;
}
// test.sol
function testGetGameBoard() {
address myAddress;
uint8[10] memory gameBoard = a.boards(address);
Assert.equal(gameBoard[0], 0, 'uint8 arrays are initialized with 0');
// TypeError: Member "equal" not unique after argument-dependent lookup in type(library Assert)
From this answer it looks like the compiler can't infer gameBoard[0]
is a uint8
? I'm not sure what's going on.
Case Two: arrays in structs
contract A {
mapping(address => Game) public games;
struct Game {
address player;
uint8[10] board;
}
}
// test.sol
function testGetGame() {
address myAddress;
var(player, board) = a.games(myAddress);
// TypeError: Not enough components (1) in value to assign all variables (2).
From what I understand, return values need to be known in size, which prevents you from returning dynamic arrays and strings. But a fixed array uint8[10]
should be known in size, right? It's not clear to me why I'm getting both of these errors. Any explanation as to what's going on would be much appreciated.
struct Game { address playerOne; address playerTwo }
allows me to destructure it asvar(addrOne, addr2) = myContract.games(myAddress);