aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormestorlx <github@martindiz.com.ar>2018-10-12 05:21:49 +0800
committermestorlx <github@martindiz.com.ar>2018-10-13 20:54:07 +0800
commit1ce9566e504f3ce14978a9df5e8b37b74e6f621e (patch)
tree872c5f9562d88aaba4b2dd419af838a72f7e2bc0
parent26dc876c28718613ad64961e65374ace1139010b (diff)
downloaddexon-solidity-1ce9566e504f3ce14978a9df5e8b37b74e6f621e.tar.gz
dexon-solidity-1ce9566e504f3ce14978a9df5e8b37b74e6f621e.tar.zst
dexon-solidity-1ce9566e504f3ce14978a9df5e8b37b74e6f621e.zip
Updated MAXIMUM_STRING_DISTANCE to non static maximumStringDistance taking into account length of the identifier
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/DeclarationContainer.cpp8
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/580_improve_name_suggestion_one_and_two_letters.sol14
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/581_improve_name_suggestion_three_letters.sol12
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/582_improve_name_suggestion_four_letters.sol17
5 files changed, 48 insertions, 4 deletions
diff --git a/Changelog.md b/Changelog.md
index b817dc22..05636a30 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -101,6 +101,7 @@ Compiler Features:
* Code Generator: Allocate and free local variables according to their scope.
* Removed ``pragma experimental "v0.5.0";``.
* Syntax Checker: Improved error message for lookup in function types.
+ * Name Resolver: Updated name suggestion look up function to take into account length of the identifier: 1: no search, 2-3: at most one change, 4-: at most two changes
Bugfixes:
* Build System: Support versions of CVC4 linked against CLN instead of GMP. In case of compilation issues due to the experimental SMT solver support, the solvers can be disabled when configuring the project with CMake using ``-DUSE_CVC4=OFF`` or ``-DUSE_Z3=OFF``.
diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp
index 5f980788..cf12a49d 100644
--- a/libsolidity/analysis/DeclarationContainer.cpp
+++ b/libsolidity/analysis/DeclarationContainer.cpp
@@ -137,23 +137,23 @@ vector<Declaration const*> DeclarationContainer::resolveName(ASTString const& _n
vector<ASTString> DeclarationContainer::similarNames(ASTString const& _name) const
{
- static size_t const MAXIMUM_EDIT_DISTANCE = 2;
+
// because the function below has quadratic runtime - it will not magically improve once a better algorithm is discovered ;)
// since 80 is the suggested line length limit, we use 80^2 as length threshold
static size_t const MAXIMUM_LENGTH_THRESHOLD = 80 * 80;
vector<ASTString> similar;
-
+ size_t maximumEditDistance = _name.size() > 3 ? 2 : _name.size() / 2;
for (auto const& declaration: m_declarations)
{
string const& declarationName = declaration.first;
- if (stringWithinDistance(_name, declarationName, MAXIMUM_EDIT_DISTANCE, MAXIMUM_LENGTH_THRESHOLD))
+ if (stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
similar.push_back(declarationName);
}
for (auto const& declaration: m_invisibleDeclarations)
{
string const& declarationName = declaration.first;
- if (stringWithinDistance(_name, declarationName, MAXIMUM_EDIT_DISTANCE, MAXIMUM_LENGTH_THRESHOLD))
+ if (stringWithinDistance(_name, declarationName, maximumEditDistance, MAXIMUM_LENGTH_THRESHOLD))
similar.push_back(declarationName);
}
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/580_improve_name_suggestion_one_and_two_letters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/580_improve_name_suggestion_one_and_two_letters.sol
new file mode 100644
index 00000000..8d2d071b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/580_improve_name_suggestion_one_and_two_letters.sol
@@ -0,0 +1,14 @@
+contract c {
+ function f () public
+ {
+ a = ac;
+ a = cd;
+ a = b;
+ }
+ uint256 a;
+ uint256 ab;
+}
+// ----
+// DeclarationError: (56-58): Undeclared identifier. Did you mean "ab"?
+// DeclarationError: (72-74): Undeclared identifier.
+// DeclarationError: (88-89): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/581_improve_name_suggestion_three_letters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/581_improve_name_suggestion_three_letters.sol
new file mode 100644
index 00000000..69f5a7e2
--- /dev/null
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/581_improve_name_suggestion_three_letters.sol
@@ -0,0 +1,12 @@
+contract c {
+ function f () public
+ {
+ a = abd;
+ a = ade;
+ }
+ uint256 a;
+ uint256 abc;
+}
+// ----
+// DeclarationError: (56-59): Undeclared identifier. Did you mean "abc" or "abi"?
+// DeclarationError: (73-76): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/582_improve_name_suggestion_four_letters.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/582_improve_name_suggestion_four_letters.sol
new file mode 100644
index 00000000..547ea308
--- /dev/null
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/582_improve_name_suggestion_four_letters.sol
@@ -0,0 +1,17 @@
+contract c {
+ function f () public
+ {
+ a = land;
+ a = lost;
+ a = lang;
+ }
+ uint256 long;
+ uint256 abc;
+}
+// ----
+// DeclarationError: (52-53): Undeclared identifier.
+// DeclarationError: (56-60): Undeclared identifier. Did you mean "long"?
+// DeclarationError: (70-71): Undeclared identifier.
+// DeclarationError: (74-78): Undeclared identifier. Did you mean "long", "log0", "log1", "log2", "log3" or "log4"?
+// DeclarationError: (88-89): Undeclared identifier.
+// DeclarationError: (92-96): Undeclared identifier. Did you mean "long"?