Extract typing.

This commit is contained in:
Daniel Kirchner
2020-04-14 10:59:28 +02:00
parent accd8d7667
commit 3af43fd350
25 changed files with 461 additions and 340 deletions
+8
View File
@@ -27,6 +27,7 @@
#include <liblangutil/Scanner.h>
#include <libsolidity/parsing/Parser.h>
#include <libsolidity/analysis/DeclarationTypeChecker.h>
#include <libsolidity/analysis/NameAndTypeResolver.h>
#include <libsolidity/codegen/Compiler.h>
#include <libsolidity/ast/AST.h>
@@ -60,6 +61,7 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
GlobalContext globalContext;
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), scopes, errorReporter);
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
@@ -69,6 +71,12 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
if (!Error::containsOnlyWarnings(errorReporter.errors()))
return AssemblyItems();
}
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
{
BOOST_REQUIRE_NO_THROW(declarationTypeChecker.check(*node));
if (!Error::containsOnlyWarnings(errorReporter.errors()))
return AssemblyItems();
}
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
@@ -25,6 +25,7 @@
#include <liblangutil/Scanner.h>
#include <libsolidity/parsing/Parser.h>
#include <libsolidity/analysis/NameAndTypeResolver.h>
#include <libsolidity/analysis/DeclarationTypeChecker.h>
#include <libsolidity/codegen/CompilerContext.h>
#include <libsolidity/codegen/ExpressionCompiler.h>
#include <libsolidity/ast/AST.h>
@@ -118,10 +119,12 @@ bytes compileFirstExpression(
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), scopes, errorReporter);
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
BOOST_REQUIRE_MESSAGE(resolver.resolveNamesAndTypes(*contract), "Resolving names failed");
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
BOOST_REQUIRE(declarationTypeChecker.check(*node));
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
@@ -6,3 +6,4 @@ contract C {
// ----
// DeclarationError: (28-45): The "constant" keyword can only be used for state variables.
// TypeError: (69-72): Invalid array length, expected integer literal or constant expression.
// TypeError: (64-75): Data location must be "storage" or "memory" for variable, but none was given.
@@ -8,4 +8,3 @@ library L
}
// ----
// DeclarationError: (32-35): Identifier not found or not unique.
// TypeError: (63-76): Internal type cannot be used for external function type.
@@ -3,3 +3,4 @@ contract c {
}
// ----
// TypeError: (51-52): Invalid array length, expected integer literal or constant expression.
// TypeError: (45-55): Data location must be "storage" or "memory" for variable, but none was given.
@@ -3,3 +3,4 @@ contract c {
}
// ----
// TypeError: (51-53): Array with negative length specified.
// TypeError: (45-56): Data location must be "storage" or "memory" for variable, but none was given.
@@ -5,3 +5,4 @@ contract test {
}
// ----
// TypeError: (55-58): Array with fractional length specified.
// TypeError: (50-61): Data location must be "storage" or "memory" for variable, but none was given.
@@ -5,3 +5,4 @@ contract test {
}
// ----
// TypeError: (55-65): Invalid array length, expected integer literal or constant expression.
// TypeError: (50-68): Data location must be "storage" or "memory" for variable, but none was given.
@@ -5,3 +5,4 @@ contract test {
}
// ----
// TypeError: (55-66): Invalid array length, expected integer literal or constant expression.
// TypeError: (50-69): Data location must be "storage" or "memory" for variable, but none was given.
@@ -18,9 +18,9 @@ contract C {
// TypeError: (33-45): Address types can only be payable or non-payable.
// TypeError: (52-64): Address types can only be payable or non-payable.
// TypeError: (89-101): Address types can only be payable or non-payable.
// TypeError: (138-150): Address types can only be payable or non-payable.
// TypeError: (156-168): Address types can only be payable or non-payable.
// TypeError: (195-207): Address types can only be payable or non-payable.
// TypeError: (236-248): Address types can only be payable or non-payable.
// TypeError: (300-312): Address types can only be payable or non-payable.
// TypeError: (352-364): Address types can only be payable or non-payable.
// TypeError: (138-150): Address types can only be payable or non-payable.
// TypeError: (156-168): Address types can only be payable or non-payable.
@@ -4,4 +4,3 @@ contract C {
}
// ----
// TypeError: (25-26): Name has to refer to a struct, enum or contract.
// TypeError: (53-61): Internal type cannot be used for external function type.
@@ -5,4 +5,3 @@ contract C {
}
// ----
// TypeError: (50-51): Name has to refer to a struct, enum or contract.
// TypeError: (78-86): Internal type cannot be used for external function type.
@@ -1,12 +1,11 @@
contract C {
function f() {
function f() public {
(((((((((((,2),)),)),),))=4)));
}
}
// ----
// SyntaxError: (15-69): No visibility specified. Did you intend to add "public"?
// TypeError: (46-47): Expression has to be an lvalue.
// TypeError: (60-61): Type int_const 4 is not implicitly convertible to expected type tuple(tuple(tuple(tuple(tuple(,int_const 2),),),),).
// TypeError: (37-61): Tuple component cannot be empty.
// TypeError: (36-62): Tuple component cannot be empty.
// TypeError: (35-63): Tuple component cannot be empty.
// TypeError: (53-54): Expression has to be an lvalue.
// TypeError: (67-68): Type int_const 4 is not implicitly convertible to expected type tuple(tuple(tuple(tuple(tuple(,int_const 2),),),),).
// TypeError: (44-68): Tuple component cannot be empty.
// TypeError: (43-69): Tuple component cannot be empty.
// TypeError: (42-70): Tuple component cannot be empty.
@@ -1,6 +1,6 @@
contract n
{
fallback()
fallback() external
{
// Used to cause a segfault
var (x,y) = (1);
@@ -12,5 +12,4 @@ contract n
}
}
// ----
// SyntaxError: (14-129): No visibility specified. Did you intend to add "external"?
// TypeError: (60-75): Different number of components on the left hand side (2) than on the right hand side (1).
// TypeError: (69-84): Different number of components on the left hand side (2) than on the right hand side (1).