mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow non-pure functions as suffixes
This commit is contained in:
parent
ccb913b244
commit
84c42d4ae2
@ -3732,18 +3732,20 @@ void TypeChecker::endVisit(Literal const& _literal)
|
||||
|
||||
// TODO at this point 'type' needs to be stored for code generation.
|
||||
|
||||
bool isPure = true;
|
||||
bool isCompileTimeConstant = true;
|
||||
if (auto const* identifierPath = get_if<ASTPointer<IdentifierPath>>(&_literal.suffix()))
|
||||
{
|
||||
Declaration const* declaration = (*identifierPath)->annotation().referencedDeclaration;
|
||||
FunctionDefinition const* definition = dynamic_cast<FunctionDefinition const*>(declaration);
|
||||
if (
|
||||
!dynamic_cast<FunctionDefinition const*>(declaration) ||
|
||||
!dynamic_cast<FunctionDefinition const*>(declaration)->isFree()
|
||||
!definition ||
|
||||
!definition->isFree() ||
|
||||
definition->stateMutability() != StateMutability::Pure
|
||||
)
|
||||
m_errorReporter.typeError(
|
||||
4438_error,
|
||||
_literal.location(),
|
||||
"The literal suffix needs to be a pre-defined suffix or a file-level function."
|
||||
"The literal suffix needs to be a pre-defined suffix or a file-level pure function."
|
||||
);
|
||||
else
|
||||
{
|
||||
@ -3785,7 +3787,7 @@ void TypeChecker::endVisit(Literal const& _literal)
|
||||
if (parameterTypeMessage.has_value())
|
||||
m_errorReporter.typeError(8838_error, _literal.location(), parameterTypeMessage.value());
|
||||
|
||||
isPure = functionType.isPure();
|
||||
isCompileTimeConstant = functionType.isPure();
|
||||
if (functionType.returnParameterTypes().size() == 1)
|
||||
type = functionType.returnParameterTypes().front();
|
||||
else
|
||||
@ -3793,8 +3795,8 @@ void TypeChecker::endVisit(Literal const& _literal)
|
||||
}
|
||||
}
|
||||
|
||||
_literal.annotation().isPure = isPure;
|
||||
_literal.annotation().type = type;
|
||||
_literal.annotation().isPure = isCompileTimeConstant;
|
||||
_literal.annotation().isLValue = false;
|
||||
_literal.annotation().isConstant = false;
|
||||
}
|
||||
|
@ -19,6 +19,6 @@ contract C {
|
||||
// Warning 2519: (277-283): This declaration shadows an existing declaration.
|
||||
// Warning 2519: (201-210): This declaration shadows an existing declaration.
|
||||
// Warning 2519: (217-241): This declaration shadows an existing declaration.
|
||||
// TypeError 4438: (294-297): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (307-310): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (320-323): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (294-297): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (307-310): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (320-323): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -8,8 +8,8 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (52-71): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (81-92): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (102-113): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (123-178): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (188-197): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (52-71): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (81-92): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (102-113): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (123-178): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (188-197): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -5,4 +5,4 @@ contract C {
|
||||
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (44-50): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (44-50): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -5,4 +5,4 @@ contract C {
|
||||
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (48-54): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (48-54): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -0,0 +1,7 @@
|
||||
function suffix(uint x) returns (uint) {}
|
||||
|
||||
contract C {
|
||||
uint a = 1000 suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (69-80): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
@ -5,3 +5,4 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// TypeError 9559: (0-49): Free functions cannot be payable.
|
||||
// TypeError 4438: (77-88): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -0,0 +1,7 @@
|
||||
function suffix(uint x) view returns (uint) {}
|
||||
|
||||
contract C {
|
||||
uint a = 1000 suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (74-85): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
@ -10,5 +10,5 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (236-249): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (259-274): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (236-249): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (259-274): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -10,6 +10,6 @@ contract C is B {
|
||||
function suffix(uint x) internal pure returns (uint) { return x; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (127-138): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (153-175): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (190-203): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (127-138): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (153-175): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
// TypeError 4438: (190-203): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -6,4 +6,4 @@ contract C {
|
||||
uint x = 1000 L.suffix;
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (112-125): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (112-125): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -4,4 +4,4 @@ contract C {
|
||||
modifier suffix(uint x) { _; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (26-37): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (26-37): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
@ -4,4 +4,4 @@ contract C {
|
||||
function suffix(uint x) public pure returns (uint) { return x; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 4438: (26-37): The literal suffix needs to be a pre-defined suffix or a file-level function.
|
||||
// TypeError 4438: (26-37): The literal suffix needs to be a pre-defined suffix or a file-level pure function.
|
||||
|
Loading…
Reference in New Issue
Block a user