Force fallback to be external (experimental 0.5.0 change)

This commit is contained in:
Alex Beregszaszi 2017-09-16 16:10:23 +01:00
parent c289fd3d9e
commit a3380ea8d0
3 changed files with 39 additions and 1 deletions

View File

@ -1,7 +1,7 @@
### 0.4.17 (unreleased)
Features:
* Support ``pragma experimental v0.5.0;`` to turn on upcoming breaking changes.
* Support ``pragma experimental "v0.5.0";`` to turn on upcoming breaking changes.
* Code Generator: Added ``.selector`` member on external function types to retrieve their signature.
* Code Generator: Keep a single copy of encoding functions when using the experimental "ABIEncoderV2".
* Optimizer: Add new optimization step to remove unused ``JUMPDEST``s.
@ -12,6 +12,7 @@ Features:
* Type Checker: Warn on using literals as tight packing parameters in ``keccak256``, ``sha3``, ``sha256`` and ``ripemd160``.
* Type Checker: Enforce ``view`` and ``pure``.
* Type Checker: Enforce ``view`` / ``constant`` with error as experimental 0.5.0 feature.
* Type Checker: Enforce fallback functions to be ``external`` as experimental 0.5.0 feature.
Bugfixes:
* ABI JSON: Include all overloaded events.

View File

@ -120,6 +120,11 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
m_errorReporter.typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
if (!fallbackFunction->returnParameters().empty())
m_errorReporter.typeError(fallbackFunction->returnParameterList()->location(), "Fallback function cannot return values.");
if (
_contract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050) &&
fallbackFunction->visibility() != FunctionDefinition::Visibility::External
)
m_errorReporter.typeError(fallbackFunction->location(), "Fallback function must be defined as \"external\".");
}
}
}

View File

@ -6691,6 +6691,38 @@ BOOST_AUTO_TEST_CASE(tight_packing_literals)
CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
}
BOOST_AUTO_TEST_CASE(non_external_fallback)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract C {
function () external { }
}
)";
CHECK_WARNING(text, "Experimental features are turned on.");
text = R"(
pragma experimental "v0.5.0";
contract C {
function () internal { }
}
)";
CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
text = R"(
pragma experimental "v0.5.0";
contract C {
function () private { }
}
)";
CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
text = R"(
pragma experimental "v0.5.0";
contract C {
function () public { }
}
)";
CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
}
BOOST_AUTO_TEST_SUITE_END()
}