I have an interface with a public function foo
that consumes a single address
parameter and returns a Point
struct:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IFoo {
struct Point {
uint x;
uint y;
}
function foo (address) external view returns (Point memory);
}
In my implementation I want to override foo
with a mapping:
contract Foo is IFoo {
mapping (address => Point) public override foo;
}
But I get the compiler error
TypeError: Overriding public state variable return types differ.
I want to understand how exactly these two types differ. Both consume an address
and return a Point
, so what's the problem here? I know this problem is unique to structs because when I try it with a map that returns a value type the compiler doesn't complain:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IFoo {
function foo (address) external view returns (uint);
}
contract Foo is IFoo {
mapping (address => uint) public override foo;
}