mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #12520 from ethereum/failed-assert-12505
Fix ICE when a variable declaration before a referenced struct
This commit is contained in:
		
						commit
						e8c628e6cc
					
				| @ -12,6 +12,7 @@ Compiler Features: | ||||
| Bugfixes: | ||||
|  * Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis. | ||||
|  * Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables. | ||||
|  * TypeChecker: Fix ICE when a constant variable declaration forward references a struct. | ||||
| 
 | ||||
| 
 | ||||
| Solc-Js: | ||||
|  | ||||
| @ -437,16 +437,14 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) | ||||
| 		type = TypeProvider::withLocation(ref, typeLoc, isPointer); | ||||
| 	} | ||||
| 
 | ||||
| 	if ( | ||||
| 		_variable.isConstant() && | ||||
| 		!dynamic_cast<UserDefinedValueType const*>(type) && | ||||
| 		type->containsNestedMapping() | ||||
| 	) | ||||
| 		m_errorReporter.fatalDeclarationError( | ||||
| 			3530_error, | ||||
| 			_variable.location(), | ||||
| 			"The type contains a (nested) mapping and therefore cannot be a constant." | ||||
| 		); | ||||
| 	if (_variable.isConstant() && !type->isValueType()) | ||||
| 	{ | ||||
| 		bool allowed = false; | ||||
| 		if (auto arrayType = dynamic_cast<ArrayType const*>(type)) | ||||
| 			allowed = arrayType->isByteArray(); | ||||
| 		if (!allowed) | ||||
| 			m_errorReporter.fatalTypeError(9259_error, _variable.location(), "Only constants of value type and byte array type are implemented."); | ||||
| 	} | ||||
| 
 | ||||
| 	_variable.annotation().type = type; | ||||
| } | ||||
|  | ||||
| @ -530,15 +530,6 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) | ||||
| 	} | ||||
| 	if (_variable.isConstant()) | ||||
| 	{ | ||||
| 		if (!varType->isValueType()) | ||||
| 		{ | ||||
| 			bool allowed = false; | ||||
| 			if (auto arrayType = dynamic_cast<ArrayType const*>(varType)) | ||||
| 				allowed = arrayType->isByteArray(); | ||||
| 			if (!allowed) | ||||
| 				m_errorReporter.fatalTypeError(9259_error, _variable.location(), "Constants of non-value type not yet implemented."); | ||||
| 		} | ||||
| 
 | ||||
| 		if (!_variable.value()) | ||||
| 			m_errorReporter.typeError(4266_error, _variable.location(), "Uninitialized \"constant\" variable."); | ||||
| 		else if (!*_variable.value()->annotation().isPure) | ||||
|  | ||||
| @ -1110,11 +1110,7 @@ public: | ||||
| 	u256 storageSize() const override { return underlyingType().storageSize(); } | ||||
| 	unsigned storageBytes() const override { return underlyingType().storageBytes(); } | ||||
| 
 | ||||
| 	bool isValueType() const override | ||||
| 	{ | ||||
| 		solAssert(underlyingType().isValueType(), ""); | ||||
| 		return true; | ||||
| 	} | ||||
| 	bool isValueType() const override { return true; } | ||||
| 	bool nameable() const override | ||||
| 	{ | ||||
| 		solAssert(underlyingType().nameable(), ""); | ||||
|  | ||||
| @ -1,3 +1,4 @@ | ||||
| int[L] constant L = 6; | ||||
| // ---- | ||||
| // TypeError 5462: (4-5): Invalid array length, expected integer literal or constant expression. | ||||
| // TypeError 9259: (0-21): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -3,3 +3,4 @@ contract C { | ||||
| } | ||||
| // ---- | ||||
| // TypeError 5462: (21-22): Invalid array length, expected integer literal or constant expression. | ||||
| // TypeError 9259: (17-38): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -1,3 +1,3 @@ | ||||
| mapping(uint => uint) constant b = b; | ||||
| // ---- | ||||
| // DeclarationError 3530: (0-36): The type contains a (nested) mapping and therefore cannot be a constant. | ||||
| // TypeError 9259: (0-36): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| struct S { uint x; } | ||||
| S constant s; | ||||
| // ---- | ||||
| // TypeError 9259: (21-33): Constants of non-value type not yet implemented. | ||||
| // TypeError 9259: (21-33): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -5,4 +5,4 @@ contract C { | ||||
|     S public constant e = 0x1212121212121212121212121212121212121212; | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 3530: (71-135): The type contains a (nested) mapping and therefore cannot be a constant. | ||||
| // TypeError 9259: (71-135): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -3,3 +3,4 @@ contract test { | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 1788: (31-55): The "constant" keyword can only be used for state variables or variables at file level. | ||||
| // TypeError 9259: (31-55): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -2,4 +2,4 @@ contract C { | ||||
|     uint[3] constant x = [uint(1), 2, 3]; | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9259: (17-53): Constants of non-value type not yet implemented. | ||||
| // TypeError 9259: (17-53): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -3,4 +3,4 @@ contract C { | ||||
|     S constant x = S(5, new uint[](4)); | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9259: (52-86): Constants of non-value type not yet implemented. | ||||
| // TypeError 9259: (52-86): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -0,0 +1,4 @@ | ||||
| S constant x; | ||||
| struct S { int y; } | ||||
| // ---- | ||||
| // TypeError 9259: (0-12): Only constants of value type and byte array type are implemented. | ||||
| @ -2,4 +2,4 @@ contract C { | ||||
|     mapping(uint => uint) constant x; | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 3530: (17-49): The type contains a (nested) mapping and therefore cannot be a constant. | ||||
| // TypeError 9259: (17-49): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -5,4 +5,4 @@ contract C { | ||||
|     S public constant c; | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 3530: (71-90): The type contains a (nested) mapping and therefore cannot be a constant. | ||||
| // TypeError 9259: (71-90): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -3,3 +3,4 @@ contract Foo { | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 1788: (30-55): The "constant" keyword can only be used for state variables or variables at file level. | ||||
| // TypeError 9259: (30-55): Only constants of value type and byte array type are implemented. | ||||
|  | ||||
| @ -217,6 +217,9 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_select_individuals_with_probability_ | ||||
| { | ||||
| 	constexpr double relativeTolerance = 0.1; | ||||
| 	constexpr size_t populationSize = 1000; | ||||
| 
 | ||||
| 	SimulationRNG::reset(1); | ||||
| 
 | ||||
| 	assert(populationSize % 4 == 0 && "Choose a number divisible by 4 for this test"); | ||||
| 
 | ||||
| 	auto population = | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user