Skip to content

Commit

Permalink
Show unimplemented function if trying to instantiate an abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Aug 4, 2017
1 parent c835bce commit 494dea2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.4.15 (unreleased)

Features:
* Type Checker: Show unimplemented function if trying to instantiate an abstract class.

Bugfixes:
* Code Generator: ``.delegatecall()`` should always return execution outcome.
Expand Down
9 changes: 8 additions & 1 deletion libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,14 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
if (!contract)
m_errorReporter.fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
if (!contract->annotation().unimplementedFunctions.empty())
m_errorReporter.typeError(_newExpression.location(), "Trying to create an instance of an abstract contract.");
m_errorReporter.typeError(
_newExpression.location(),
SecondarySourceLocation().append(
"Missing implementation:",
contract->annotation().unimplementedFunctions.front()->location()
),
"Trying to create an instance of an abstract contract."
);
if (!contract->constructorIsPublic())
m_errorReporter.typeError(_newExpression.location(), "Contract with internal constructor cannot be created directly.");

Expand Down
10 changes: 10 additions & 0 deletions libsolidity/interface/ErrorReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ void ErrorReporter::syntaxError(SourceLocation const& _location, string const& _
);
}

void ErrorReporter::typeError(SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{
error(
Error::Type::TypeError,
_location,
_secondaryLocation,
_description
);
}

void ErrorReporter::typeError(SourceLocation const& _location, string const& _description)
{
error(
Expand Down
6 changes: 6 additions & 0 deletions libsolidity/interface/ErrorReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class ErrorReporter

void syntaxError(SourceLocation const& _location, std::string const& _description);

void typeError(
SourceLocation const& _location,
SecondarySourceLocation const& _secondaryLocation,
std::string const& _description
);

void typeError(SourceLocation const& _location, std::string const& _description);

void fatalTypeError(SourceLocation const& _location, std::string const& _description);
Expand Down

0 comments on commit 494dea2

Please sign in to comment.