Disallow variables of library types

This commit is contained in:
Mathias Baumann 2019-11-14 12:48:15 +01:00
parent f6191a7183
commit 0891b9451b
5 changed files with 28 additions and 4 deletions

View File

@ -12,6 +12,7 @@ Compiler Features:
* SMTChecker: Support inheritance and function overriding. * SMTChecker: Support inheritance and function overriding.
* Standard JSON Interface: Output the storage layout of a contract when artifact ``storageLayout`` is requested. * Standard JSON Interface: Output the storage layout of a contract when artifact ``storageLayout`` is requested.
* TypeChecker: List possible candidates when overload resolution fails. * TypeChecker: List possible candidates when overload resolution fails.
* TypeChecker: Disallow variables of library types.
Bugfixes: Bugfixes:

View File

@ -450,6 +450,9 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
TypePointer varType = _variable.annotation().type; TypePointer varType = _variable.annotation().type;
solAssert(!!varType, "Variable type not provided."); solAssert(!!varType, "Variable type not provided.");
if (auto contractType = dynamic_cast<ContractType const*>(varType))
if (contractType->contractDefinition().isLibrary())
m_errorReporter.typeError(_variable.location(), "The type of a variable cannot be a library.");
if (_variable.value()) if (_variable.value())
expectType(*_variable.value(), *varType); expectType(*_variable.value(), *varType);
if (_variable.isConstant()) if (_variable.isConstant())

View File

@ -1,9 +1,14 @@
contract X {}
library test { library test {
struct StructType { uint a; } struct StructType { uint a; }
function f(StructType storage b, uint[] storage c, test d) public returns (uint[] memory e, StructType storage f) { f = f; } function f(StructType storage b, uint[] storage c, X d) public returns (uint[] memory e, StructType storage f) { f = f; }
function f1(uint[] memory c, test d) public pure returns (uint[] memory e) { } function f1(uint[] memory c, X d) public pure returns (uint[] memory e) { }
} }
// ---- // ----
// :X
// []
//
//
// :test // :test
// [ // [
// { // {
@ -16,9 +21,9 @@ library test {
// "type": "uint256[]" // "type": "uint256[]"
// }, // },
// { // {
// "internalType": "library test", // "internalType": "contract X",
// "name": "d", // "name": "d",
// "type": "test" // "type": "X"
// } // }
// ], // ],
// "name": "f1", // "name": "f1",

View File

@ -6,4 +6,5 @@ contract test {
} }
} }
// ---- // ----
// TypeError: (87-90): The type of a variable cannot be a library.
// TypeError: (100-103): Member "l" not found or not visible after argument-dependent lookup in library L. // TypeError: (100-103): Member "l" not found or not visible after argument-dependent lookup in library L.

View File

@ -0,0 +1,14 @@
library X { }
contract Y {
X abc;
function foo(X param) private view
{
X ofg;
ofg = abc;
}
}
// ----
// TypeError: (29-34): The type of a variable cannot be a library.
// TypeError: (50-57): The type of a variable cannot be a library.
// TypeError: (77-82): The type of a variable cannot be a library.