Skip to content

Commit

Permalink
Fix ICE by avoiding copyForLocation() on ArraySliceType
Browse files Browse the repository at this point in the history
  • Loading branch information
Marenz committed May 26, 2020
1 parent 5fedb4e commit 8f12b6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libsolidity/analysis/TypeChecker.cpp
Expand Up @@ -2555,7 +2555,7 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)

if (possibleMembers.empty())
{
if (initialMemberCount == 0)
if (initialMemberCount == 0 && !dynamic_cast<ArraySliceType const*>(exprType))
{
// Try to see if the member was removed because it is only available for storage types.
auto storageType = TypeProvider::withLocationIfReference(
Expand Down
9 changes: 6 additions & 3 deletions libsolidity/ast/Types.cpp
Expand Up @@ -349,14 +349,17 @@ TypePointer Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool) c
MemberList::MemberMap Type::boundFunctions(Type const& _type, ContractDefinition const& _scope)
{
// Normalise data location of type.
TypePointer type = TypeProvider::withLocationIfReference(DataLocation::Storage, &_type);
DataLocation typeLocation = DataLocation::Storage;
if (auto refType = dynamic_cast<ReferenceType const*>(&_type))
typeLocation = refType->location();

set<Declaration const*> seenFunctions;
MemberList::MemberMap members;
for (ContractDefinition const* contract: _scope.annotation().linearizedBaseContracts)
for (UsingForDirective const* ufd: contract->usingForDirectives())
{
if (ufd->typeName() && *type != *TypeProvider::withLocationIfReference(
DataLocation::Storage,
if (ufd->typeName() && _type != *TypeProvider::withLocationIfReference(
typeLocation,
ufd->typeName()->annotation().type
))
continue;
Expand Down
8 changes: 8 additions & 0 deletions test/libsolidity/syntaxTests/array/slice/member_access.sol
@@ -0,0 +1,8 @@
// Used to cause ICE
contract C {
function f(uint[] calldata x) external pure {
x[1:2].a;
}
}
// ----
// TypeError: (92-100): Member "a" not found or not visible after argument-dependent lookup in uint256[] calldata slice.

0 comments on commit 8f12b6e

Please sign in to comment.