Skip to content

Commit c703f8c

Browse files
author
Dejan Jovanovic
committed
[0.7] fix for #166
1 parent 8688567 commit c703f8c

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

libsolidity/boogie/ASTBoogieExpressionConverter.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,31 +1354,14 @@ bool ASTBoogieExpressionConverter::visit(MemberAccess const& _node)
13541354
return false;
13551355
}
13561356

1357-
// Enums
1358-
if (_node.annotation().type->category() == Type::Category::Enum)
1357+
// Reaching for enum, e.g. Enum.A
1358+
if (type->category() == Type::Category::TypeType && _node.annotation().type->category() == Type::Category::Enum)
13591359
{
1360-
// Try to get the enum definition
1361-
EnumDefinition const* enumDef = nullptr;
1362-
if (auto exprId = dynamic_cast<Identifier const*>(&_node.expression()))
1363-
enumDef = dynamic_cast<EnumDefinition const*>(exprId->annotation().referencedDeclaration);
1364-
if (auto exprMemAcc = dynamic_cast<MemberAccess const*>(&_node.expression()))
1365-
enumDef = dynamic_cast<EnumDefinition const*>(exprMemAcc->annotation().referencedDeclaration);
1366-
1367-
if (enumDef)
1368-
{
1369-
// TODO: better way to get index?
1370-
for (size_t i = 0; i < enumDef->members().size(); ++i)
1371-
{
1372-
if (enumDef->members()[i]->name() == _node.memberName())
1373-
{
1374-
m_currentExpr = m_context.intLit(i, 256);
1375-
return false;
1376-
}
1377-
}
1378-
solAssert(false, "Enum member not found");
1379-
}
1380-
else
1381-
solAssert(false, "Enum definition not found");
1360+
// If it's a member of the enum, just return the value
1361+
EnumType const* enumType = dynamic_cast<EnumType const*>(_node.annotation().type);
1362+
unsigned i = enumType->memberValue(_node.memberName());
1363+
m_currentExpr = m_context.intLit(i, 256);
1364+
return false;
13821365
}
13831366

13841367
// Non-special member access: 'referencedDeclaration' should point to the
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
pragma solidity >=0.5.0;
3+
4+
contract Test {
5+
enum B { A }
6+
struct AA {
7+
B s;
8+
}
9+
10+
AA private _aa;
11+
12+
function test() public view {
13+
B b = _aa.s;
14+
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test/solc-verify/issues/Issue166.sol:13:5: Warning: Unused local variable.
2+
Test::test: OK
3+
Test::[implicit_constructor]: OK
4+
No errors found.

0 commit comments

Comments
 (0)