mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Changed error message and added tests
This commit is contained in:
		
							parent
							
								
									4522c804f3
								
							
						
					
					
						commit
						17176871ab
					
				| @ -142,7 +142,7 @@ void SyntaxChecker::checkSingleStatementVariableDeclaration(ASTNode const* _stat | ||||
| { | ||||
| 	auto varDecl = dynamic_cast<VariableDeclarationStatement const*>(_statement); | ||||
| 	if (varDecl) | ||||
| 		m_errorReporter.syntaxError(_statement->location(), "Invalid variable declaration. Please declare it inside a block."); | ||||
| 		m_errorReporter.syntaxError(_statement->location(), "Variable declarations can only be used inside blocks."); | ||||
| } | ||||
| 
 | ||||
| bool SyntaxChecker::visit(IfStatement const& _ifStatement) | ||||
|  | ||||
| @ -0,0 +1,12 @@ | ||||
| pragma solidity >0.4.24; | ||||
| 
 | ||||
| contract C | ||||
| { | ||||
| 	function f(uint x) public pure { | ||||
| 		do | ||||
| 			uint y; | ||||
| 		while (x > 0); | ||||
| 	} | ||||
| } | ||||
| // ---- | ||||
| // SyntaxError: (81-87): Variable declarations can only be used inside blocks. | ||||
							
								
								
									
										13
									
								
								test/libsolidity/syntaxTests/variableDeclaration/else.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								test/libsolidity/syntaxTests/variableDeclaration/else.sol
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| pragma solidity >0.4.24; | ||||
| 
 | ||||
| contract C | ||||
| { | ||||
| 	function f(uint x) public pure { | ||||
| 		if (x > 0) | ||||
| 			{uint y;} | ||||
| 		else | ||||
| 			uint z; | ||||
| 	} | ||||
| } | ||||
| // ---- | ||||
| // SyntaxError: (109-115): Variable declarations can only be used inside blocks. | ||||
							
								
								
									
										11
									
								
								test/libsolidity/syntaxTests/variableDeclaration/for.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								test/libsolidity/syntaxTests/variableDeclaration/for.sol
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| pragma solidity >0.4.24; | ||||
| 
 | ||||
| contract C | ||||
| { | ||||
| 	function f(uint x) public pure { | ||||
| 		for (uint i = 0; i < x; ++i) | ||||
| 			uint y; | ||||
| 	} | ||||
| } | ||||
| // ---- | ||||
| // SyntaxError: (107-113): Variable declarations can only be used inside blocks. | ||||
							
								
								
									
										11
									
								
								test/libsolidity/syntaxTests/variableDeclaration/if.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								test/libsolidity/syntaxTests/variableDeclaration/if.sol
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| pragma solidity >0.4.24; | ||||
| 
 | ||||
| contract C | ||||
| { | ||||
| 	function f(uint x) public pure { | ||||
| 		if (x > 0) | ||||
| 			uint y; | ||||
| 	} | ||||
| } | ||||
| // ---- | ||||
| // SyntaxError: (89-95): Variable declarations can only be used inside blocks. | ||||
							
								
								
									
										11
									
								
								test/libsolidity/syntaxTests/variableDeclaration/while.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								test/libsolidity/syntaxTests/variableDeclaration/while.sol
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| pragma solidity >0.4.24; | ||||
| 
 | ||||
| contract C | ||||
| { | ||||
| 	function f(uint x) public pure { | ||||
| 		while (x > 0) | ||||
| 			uint y; | ||||
| 	} | ||||
| } | ||||
| // ---- | ||||
| // SyntaxError: (92-98): Variable declarations can only be used inside blocks. | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user