[TypeChecker] Remove function input and return parameter names from mobileType

This commit is contained in:
Djordje Mijovic 2020-07-15 16:27:38 +02:00
parent ba4e05c62c
commit e7d5a7da10
6 changed files with 51 additions and 3 deletions

View File

@ -32,6 +32,7 @@ Bugfixes:
* NatSpec: Constructors and functions have consistent userdoc output.
* Inheritance: Disallow public state variables overwriting ``pure`` functions.
* State Mutability: Constant public state variables are considered ``pure`` functions.
* Type Checker: Fixing deduction issues on function types when function call has named arguments.
### 0.6.12 (2020-07-22)

View File

@ -1293,9 +1293,9 @@ bool TypeChecker::visit(Conditional const& _conditional)
if (_conditional.annotation().willBeWrittenTo)
m_errorReporter.typeError(
2212_error,
_conditional.location(),
"Conditional expression as left value is not supported yet."
2212_error,
_conditional.location(),
"Conditional expression as left value is not supported yet."
);
return false;

View File

@ -3425,6 +3425,28 @@ TypeResult FunctionType::interfaceType(bool /*_inLibrary*/) const
return TypeResult::err("Internal type is not allowed for public or external functions.");
}
TypePointer FunctionType::mobileType() const
{
if (m_valueSet || m_gasSet || m_saltSet || m_bound)
return nullptr;
// return function without parameter names
return TypeProvider::function(
m_parameterTypes,
m_returnParameterTypes,
strings(m_parameterTypes.size()),
strings(m_returnParameterNames.size()),
m_kind,
m_arbitraryParameters,
m_stateMutability,
m_declaration,
m_gasSet,
m_valueSet,
m_bound,
m_saltSet
);
}
bool FunctionType::canTakeArguments(
FuncCallArguments const& _arguments,
Type const* _selfType

View File

@ -1234,6 +1234,7 @@ public:
MemberList::MemberMap nativeMembers(ASTNode const* _currentScope) const override;
TypePointer encodingType() const override;
TypeResult interfaceType(bool _inLibrary) const override;
TypePointer mobileType() const override;
/// @returns TypePointer of a new FunctionType object. All input/return parameters are an
/// appropriate external types (i.e. the interfaceType()s) of input/return parameters of

View File

@ -0,0 +1,10 @@
contract C {
function g(int x, int y) public pure returns (int) { return x - y; }
function h(int y, int x) public pure returns (int) { return y - x; }
function f() public pure returns (int) {
return (false ? g : h)(2, 1);
}
}
// ----
// f() -> 1

View File

@ -0,0 +1,14 @@
contract C {
function g(int x, int y) public pure returns (int) { return x - y; }
function h(int y, int x) public pure returns (int) { return y - x; }
function f() public pure {
(true ? g : h)({x : 1, y : 2});
[g, h][1]({x : 1, y : 2});
}
}
// ----
// TypeError 4974: (199-229): Named argument "x" does not match function declaration.
// TypeError 4974: (199-229): Named argument "y" does not match function declaration.
// TypeError 4974: (239-264): Named argument "x" does not match function declaration.
// TypeError 4974: (239-264): Named argument "y" does not match function declaration.