mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use EVM version in type checker.
This commit is contained in:
parent
f2f61f1c2f
commit
a53d6b499d
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <libsolidity/interface/EVMVersion.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/Types.h>
|
#include <libsolidity/ast/Types.h>
|
||||||
#include <libsolidity/ast/ASTAnnotations.h>
|
#include <libsolidity/ast/ASTAnnotations.h>
|
||||||
#include <libsolidity/ast/ASTForward.h>
|
#include <libsolidity/ast/ASTForward.h>
|
||||||
@ -43,7 +45,10 @@ class TypeChecker: private ASTConstVisitor
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// @param _errorReporter provides the error logging functionality.
|
/// @param _errorReporter provides the error logging functionality.
|
||||||
TypeChecker(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {}
|
TypeChecker(EVMVersion _evmVersion, ErrorReporter& _errorReporter):
|
||||||
|
m_evmVersion(_evmVersion),
|
||||||
|
m_errorReporter(_errorReporter)
|
||||||
|
{}
|
||||||
|
|
||||||
/// Performs type checking on the given contract and all of its sub-nodes.
|
/// Performs type checking on the given contract and all of its sub-nodes.
|
||||||
/// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings
|
/// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings
|
||||||
@ -132,6 +137,8 @@ private:
|
|||||||
|
|
||||||
ContractDefinition const* m_scope = nullptr;
|
ContractDefinition const* m_scope = nullptr;
|
||||||
|
|
||||||
|
EVMVersion m_evmVersion;
|
||||||
|
|
||||||
/// Flag indicating whether we are currently inside an EmitStatement.
|
/// Flag indicating whether we are currently inside an EmitStatement.
|
||||||
bool m_insideEmitStatement = false;
|
bool m_insideEmitStatement = false;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ bool CompilerStack::analyze()
|
|||||||
m_contracts[contract->fullyQualifiedName()].contract = contract;
|
m_contracts[contract->fullyQualifiedName()].contract = contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeChecker typeChecker(m_errorReporter);
|
TypeChecker typeChecker(m_evmVersion, m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
|
@ -20,11 +20,9 @@
|
|||||||
* Unit tests for Assembly Items from evmasm/Assembly.h
|
* Unit tests for Assembly Items from evmasm/Assembly.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
#include <libevmasm/SourceLocation.h>
|
#include <libevmasm/SourceLocation.h>
|
||||||
#include <libevmasm/Assembly.h>
|
#include <libevmasm/Assembly.h>
|
||||||
|
|
||||||
#include <libsolidity/parsing/Scanner.h>
|
#include <libsolidity/parsing/Scanner.h>
|
||||||
#include <libsolidity/parsing/Parser.h>
|
#include <libsolidity/parsing/Parser.h>
|
||||||
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
||||||
@ -33,6 +31,11 @@
|
|||||||
#include <libsolidity/analysis/TypeChecker.h>
|
#include <libsolidity/analysis/TypeChecker.h>
|
||||||
#include <libsolidity/interface/ErrorReporter.h>
|
#include <libsolidity/interface/ErrorReporter.h>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dev::eth;
|
using namespace dev::eth;
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ namespace test
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
eth::AssemblyItems compileContract(const string& _sourceCode)
|
eth::AssemblyItems compileContract(string const& _sourceCode)
|
||||||
{
|
{
|
||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
ErrorReporter errorReporter(errors);
|
ErrorReporter errorReporter(errors);
|
||||||
@ -69,7 +72,7 @@ eth::AssemblyItems compileContract(const string& _sourceCode)
|
|||||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
{
|
{
|
||||||
TypeChecker checker(errorReporter);
|
TypeChecker checker(EVMVersion{}, errorReporter);
|
||||||
BOOST_REQUIRE_NO_THROW(checker.checkTypeRequirements(*contract));
|
BOOST_REQUIRE_NO_THROW(checker.checkTypeRequirements(*contract));
|
||||||
if (!Error::containsOnlyWarnings(errorReporter.errors()))
|
if (!Error::containsOnlyWarnings(errorReporter.errors()))
|
||||||
return AssemblyItems();
|
return AssemblyItems();
|
||||||
|
@ -132,7 +132,7 @@ bytes compileFirstExpression(
|
|||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
{
|
{
|
||||||
ErrorReporter errorReporter(errors);
|
ErrorReporter errorReporter(errors);
|
||||||
TypeChecker typeChecker(errorReporter);
|
TypeChecker typeChecker(EVMVersion{}, errorReporter);
|
||||||
BOOST_REQUIRE(typeChecker.checkTypeRequirements(*contract));
|
BOOST_REQUIRE(typeChecker.checkTypeRequirements(*contract));
|
||||||
}
|
}
|
||||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||||
|
@ -3350,6 +3350,11 @@ BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
m_compiler.setEVMVersion(EVMVersion{});
|
||||||
|
CHECK_WARNING(sourceCode, "Use of the \"var\" keyword is deprecated");
|
||||||
|
m_compiler.setEVMVersion(*EVMVersion::fromString("byzantium"));
|
||||||
|
CHECK_WARNING(sourceCode, "Use of the \"var\" keyword is deprecated");
|
||||||
|
m_compiler.setEVMVersion(*EVMVersion::fromString("homestead"));
|
||||||
CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed from \"inaccessible dynamic type\" to \"bytes storage pointer\".");
|
CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed from \"inaccessible dynamic type\" to \"bytes storage pointer\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user