Fix qualified modifier lookup.

This commit is contained in:
chriseth 2020-11-16 16:42:17 +01:00
parent 3957fb8191
commit e64fd99fb5
3 changed files with 56 additions and 4 deletions

View File

@ -1301,11 +1301,16 @@ void ContractCompiler::appendModifierOrFunctionCode()
appendModifierOrFunctionCode(); appendModifierOrFunctionCode();
else else
{ {
solAssert(*modifierInvocation->name().annotation().requiredLookup == VirtualLookup::Virtual, ""); ModifierDefinition const& referencedModifier = dynamic_cast<ModifierDefinition const&>(
ModifierDefinition const& modifier = dynamic_cast<ModifierDefinition const&>(
*modifierInvocation->name().annotation().referencedDeclaration *modifierInvocation->name().annotation().referencedDeclaration
).resolveVirtual(m_context.mostDerivedContract()); );
VirtualLookup lookup = *modifierInvocation->name().annotation().requiredLookup;
solAssert(lookup == VirtualLookup::Virtual || lookup == VirtualLookup::Static, "");
ModifierDefinition const& modifier =
lookup == VirtualLookup::Virtual ?
referencedModifier.resolveVirtual(m_context.mostDerivedContract()) :
referencedModifier;
CompilerContext::LocationSetter locationSetter(m_context, modifier); CompilerContext::LocationSetter locationSetter(m_context, modifier);
std::vector<ASTPointer<Expression>> const& modifierArguments = std::vector<ASTPointer<Expression>> const& modifierArguments =
modifierInvocation->arguments() ? *modifierInvocation->arguments() : std::vector<ASTPointer<Expression>>(); modifierInvocation->arguments() ? *modifierInvocation->arguments() : std::vector<ASTPointer<Expression>>();

View File

@ -0,0 +1,22 @@
contract A {
uint public x = 7;
modifier m virtual { x = 2; _; }
}
contract C is A {
modifier m override { x = 1; _; }
function f() public A.m returns (uint) {
return 9;
}
function g() public m returns (uint) {
return 10;
}
}
// ----
// x() -> 7
// f() -> 9
// x() -> 2
// g() -> 0x0a
// x() -> 1
// f() -> 9
// x() -> 2

View File

@ -0,0 +1,25 @@
==== Source: a ====
import "a" as M;
contract C {
uint public x;
modifier m { x = 1; _; }
function f() public M.M.C.m returns (uint t, uint r) {
t = x;
x = 3;
r = 9;
}
function g() public m returns (uint t, uint r) {
t = x;
x = 4;
r = 10;
}
}
// ----
// x() -> 0x00
// f() -> 1, 9
// x() -> 3
// g() -> 1, 0x0a
// x() -> 4
// f() -> 1, 9
// x() -> 3