Forbid private library functions to be attached outside their declaration scope

This commit is contained in:
Matheus Aguiar
2023-01-17 16:27:35 -03:00
parent 229fcc9fce
commit 7779b6f352
5 changed files with 53 additions and 0 deletions
+25
View File
@@ -3809,6 +3809,10 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
m_errorReporter.fatalTypeError(
4731_error,
path->location(),
SecondarySourceLocation().append(
"Function defined here:",
functionDefinition.location()
),
fmt::format(
"The function \"{}\" does not have any parameters, and therefore cannot be attached to the type \"{}\".",
joinHumanReadable(path->path(), "."),
@@ -3816,6 +3820,27 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
)
);
if (
functionDefinition.visibility() == Visibility::Private &&
functionDefinition.scope() != m_currentContract
)
{
solAssert(functionDefinition.libraryFunction());
m_errorReporter.typeError(
6772_error,
path->location(),
SecondarySourceLocation().append(
"Function defined here:",
functionDefinition.location()
),
fmt::format(
"Function \"{}\" is private and therefore cannot be attached"
" to a type outside of the library where it is defined.",
joinHumanReadable(path->path(), ".")
)
);
}
FunctionType const* functionType = dynamic_cast<FunctionType const&>(*functionDefinition.type()).withBoundFirstArgument();
solAssert(functionType && functionType->selfType(), "");
BoolResult result = normalizedType->isImplicitlyConvertibleTo(