mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
TypeChecker: Check if type exists before dereferencing it
This commit is contained in:
parent
7599fd7c4e
commit
50b4193705
@ -629,6 +629,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
|
||||
bool requiresStorage = ref->second.isSlot || ref->second.isOffset;
|
||||
if (auto var = dynamic_cast<VariableDeclaration const*>(declaration))
|
||||
{
|
||||
solAssert(var->type(), "Expected variable type!");
|
||||
if (var->isConstant())
|
||||
{
|
||||
m_errorReporter.typeError(_identifier.location, "Constant variables not supported by inline assembly.");
|
||||
@ -1009,6 +1010,14 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
|
||||
}
|
||||
}
|
||||
|
||||
if (valueTypes.size() != variables.size())
|
||||
{
|
||||
solAssert(m_errorReporter.hasErrors(), "Should have errors!");
|
||||
for (auto const& var: variables)
|
||||
if (var && !var->annotation().type)
|
||||
BOOST_THROW_EXCEPTION(FatalError());
|
||||
}
|
||||
|
||||
if (autoTypeDeductionNeeded)
|
||||
{
|
||||
if (!typeCanBeExpressed(variables))
|
||||
|
17
test/libsolidity/syntaxTests/types/var_decl_val_mismatch.sol
Normal file
17
test/libsolidity/syntaxTests/types/var_decl_val_mismatch.sol
Normal file
@ -0,0 +1,17 @@
|
||||
contract n
|
||||
{
|
||||
function()
|
||||
{
|
||||
// Used to cause a segfault
|
||||
var (x,y) = (1);
|
||||
var (z) = ();
|
||||
|
||||
assembly {
|
||||
mstore(y, z)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// SyntaxError: (14-129): No visibility specified. Did you intend to add "external"?
|
||||
// TypeError: (14-129): Fallback function must be defined as "external".
|
||||
// TypeError: (60-75): Different number of components on the left hand side (2) than on the right hand side (1).
|
@ -28,10 +28,3 @@ contract C {
|
||||
// SyntaxError: (360-384): Use of the "var" keyword is disallowed. Use explicit declaration `(uint8 a, string memory b) = ...´ instead.
|
||||
// SyntaxError: (394-411): Use of the "var" keyword is disallowed. Use explicit declaration `(uint256 x, , uint256 z) = ...´ instead.
|
||||
// TypeError: (421-438): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (421-438): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// TypeError: (448-464): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (448-464): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// TypeError: (474-488): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (474-488): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// TypeError: (498-513): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (498-513): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
|
Loading…
Reference in New Issue
Block a user