Fix using for with explicit reference types.

This commit is contained in:
chriseth 2020-06-11 12:55:30 +02:00
parent baabe65a84
commit 549c90612c
3 changed files with 38 additions and 4 deletions

View File

@ -13,6 +13,7 @@ Bugfixes:
* SMTChecker: Fix internal error when encoding tuples of tuples.
* SMTChecker: Fix aliasing soundness after pushing to an array pointer.
* Type system: Fix internal compiler error on calling externally a function that returns variables with calldata location.
* Type system: Fix bug where a bound function was not found if ``using for`` is applied to explicit reference types.
### 0.6.9 (2020-06-04)

View File

@ -356,10 +356,18 @@ MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition
for (ContractDefinition const* contract: _scope.annotation().linearizedBaseContracts)
for (UsingForDirective const* ufd: contract->usingForDirectives())
{
if (ufd->typeName() && _type != *TypeProvider::withLocationIfReference(
typeLocation,
ufd->typeName()->annotation().type
))
// Convert both types to pointers for comparison to see if the `using for`
// directive applies.
// Further down, we check more detailed for each function if `_type` is
// convertible to the function parameter type.
if (ufd->typeName() &&
*TypeProvider::withLocationIfReference(typeLocation, &_type, true) !=
*TypeProvider::withLocationIfReference(
typeLocation,
ufd->typeName()->annotation().type,
true
)
)
continue;
auto const& library = dynamic_cast<ContractDefinition const&>(
*ufd->libraryName().annotation().referencedDeclaration

View File

@ -0,0 +1,25 @@
struct Struct { uint x; }
library L {
function f(Struct storage _x) internal view returns (uint256) {
return _x.x;
}
}
contract C {
using L for Struct;
Struct s;
function h(Struct storage _s) internal view returns (uint) {
// _s is pointer
return _s.f();
}
function g() public returns (uint, uint) {
s.x = 7;
// s is reference
return (s.f(), h(s));
}
}
// ----
// g() -> 7, 7