mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #9959 from a3d4/fix-ice-struct-with-mapping-assignment
Fix ICE caused by const structs with mappings
This commit is contained in:
		
						commit
						6eea2f5c08
					
				| @ -18,6 +18,7 @@ Bugfixes: | ||||
|  * SMTChecker: Fix false negatives when analyzing external function calls. | ||||
|  * SMTChecker: Fix missing type constraints for block variables. | ||||
|  * SMTChecker: Fix internal error on ``block.chainid``. | ||||
|  * Type Checker: Fix internal error caused by constant structs containing mappings. | ||||
|  * Type System: Disallow implicit conversion from ``uintN`` to ``intM`` when ``M > N``, and by extension, explicit conversion between the same types is also disallowed. | ||||
| 
 | ||||
| ### 0.8.0 (2020-12-16) | ||||
|  | ||||
| @ -412,6 +412,15 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) | ||||
| 		type = TypeProvider::withLocation(ref, typeLoc, isPointer); | ||||
| 	} | ||||
| 
 | ||||
| 	if (_variable.isConstant() && !type->isValueType()) | ||||
| 	{ | ||||
| 		bool allowed = false; | ||||
| 		if (auto arrayType = dynamic_cast<ArrayType const*>(type)) | ||||
| 			allowed = arrayType->isByteArray(); | ||||
| 		if (!allowed) | ||||
| 			m_errorReporter.fatalDeclarationError(9259_error, _variable.location(), "Constants of non-value type not yet implemented."); | ||||
| 	} | ||||
| 
 | ||||
| 	_variable.annotation().type = type; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -521,15 +521,6 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) | ||||
| 	} | ||||
| 	if (_variable.isConstant()) | ||||
| 	{ | ||||
| 		if (!_variable.type()->isValueType()) | ||||
| 		{ | ||||
| 			bool allowed = false; | ||||
| 			if (auto arrayType = dynamic_cast<ArrayType const*>(_variable.type())) | ||||
| 				allowed = arrayType->isByteArray(); | ||||
| 			if (!allowed) | ||||
| 				m_errorReporter.typeError(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) | ||||
|  | ||||
| @ -1,3 +1,4 @@ | ||||
| int[L] constant L = 6; | ||||
| // ---- | ||||
| // TypeError 5462: (4-5): Invalid array length, expected integer literal or constant expression. | ||||
| // DeclarationError 9259: (0-21): Constants of non-value type not yet implemented. | ||||
|  | ||||
| @ -3,3 +3,4 @@ contract C { | ||||
| } | ||||
| // ---- | ||||
| // TypeError 5462: (21-22): Invalid array length, expected integer literal or constant expression. | ||||
| // DeclarationError 9259: (17-38): Constants of non-value type not yet implemented. | ||||
|  | ||||
| @ -1,3 +1,3 @@ | ||||
| mapping(uint => uint) constant b = b; | ||||
| // ---- | ||||
| // TypeError 9259: (0-36): Constants of non-value type not yet implemented. | ||||
| // DeclarationError 9259: (0-36): Constants of non-value type not yet implemented. | ||||
|  | ||||
| @ -1,5 +1,4 @@ | ||||
| struct S { uint x; } | ||||
| S constant s; | ||||
| // ---- | ||||
| // TypeError 9259: (21-33): Constants of non-value type not yet implemented. | ||||
| // TypeError 4266: (21-33): Uninitialized "constant" variable. | ||||
| // DeclarationError 9259: (21-33): Constants of non-value type not yet implemented. | ||||
|  | ||||
| @ -0,0 +1,8 @@ | ||||
| contract C { | ||||
|     struct S { | ||||
|         mapping(uint => uint) c; | ||||
|     } | ||||
|     S public constant e = 0x1212121212121212121212121212121212121212; | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 9259: (71-135): Constants of non-value type not yet 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. | ||||
| // DeclarationError 9259: (31-55): Constants of non-value type not yet 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. | ||||
| // DeclarationError 9259: (17-53): Constants of non-value type not yet 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. | ||||
| // DeclarationError 9259: (52-86): Constants of non-value type not yet implemented. | ||||
|  | ||||
| @ -4,5 +4,4 @@ contract C { | ||||
|     mapping(uint => uint) constant x; | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9259: (148-180): Constants of non-value type not yet implemented. | ||||
| // TypeError 4266: (148-180): Uninitialized "constant" variable. | ||||
| // DeclarationError 9259: (148-180): Constants of non-value type not yet implemented. | ||||
|  | ||||
| @ -0,0 +1,8 @@ | ||||
| contract C { | ||||
|     struct S { | ||||
|         mapping(uint => uint) x; | ||||
|     } | ||||
|     S public constant c; | ||||
| } | ||||
| // ---- | ||||
| // DeclarationError 9259: (71-90): Constants of non-value type not yet 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. | ||||
| // DeclarationError 9259: (30-55): Constants of non-value type not yet implemented. | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user