Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,20 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
FunctionDefinition const& functionDefinition =
dynamic_cast<FunctionDefinition const&>(*path->annotation().referencedDeclaration);

// Free functions with an explicit visibility were already flagged by the
// SyntaxChecker (error 4126). That error is not fatal, so resolution
// continues into this directive and calls `functionDefinition.type()`,
// which asserts non-external. Skip the entry to avoid the ICE; the user
// will still see the visibility error from the function definition.
if (
!functionDefinition.libraryFunction() &&
functionDefinition.visibility() == Visibility::External
)
{
solAssert(m_errorReporter.hasErrors());
continue;
}

FunctionType const* functionType = dynamic_cast<FunctionType const*>(
functionDefinition.libraryFunction() ?
functionDefinition.typeViaContractName() :
Expand Down
7 changes: 7 additions & 0 deletions test/libsolidity/syntaxTests/using/external_free_function.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Used to cause ICE in FunctionDefinition::type() when an external free
// function (already a syntax error) was bound via `using for`.
function f(int) external;
using {f} for int global;
// ----
// SyntaxError 4126: (0-26): Free functions cannot have visibility.
// TypeError 4668: (0-26): Free functions must be implemented.