Skip to content

Commit

Permalink
Merge pull request #7926 from ethereum/revertSemver
Browse files Browse the repository at this point in the history
Revert changes to semver matcher.
  • Loading branch information
chriseth authored Dec 9, 2019
2 parents 69e4500 + 9c35038 commit 5404343
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Bugfixes:
* SMTChecker: Fix internal error when using ``abi.decode``.
* SMTChecker: Fix internal error when using arrays or mappings of functions.
* SMTChecker: Fix internal error in array of structs type.
* Version Checker: 0.5.x-prerelease will match `pragma solidity ^0.5`.
* Version Checker: ``^0`` should match ``0.5.0``, but no prerelease.
* Yul: Consider infinite loops and recursion to be not removable.


Expand Down
12 changes: 1 addition & 11 deletions liblangutil/SemVerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool SemVerMatchExpression::MatchComponent::matches(SemVerVersion const& _versio
if (!comp.matches(_version))
return false;

if (comp.version.numbers[0] == 0)
if (comp.version.numbers[0] == 0 && comp.levelsPresent != 1)
comp.levelsPresent = 2;
else
comp.levelsPresent = 1;
Expand All @@ -107,17 +107,7 @@ bool SemVerMatchExpression::MatchComponent::matches(SemVerVersion const& _versio
}

if (cmp == 0 && !_version.prerelease.empty() && didCompare)
{
cmp = -1;
for (unsigned i = levelsPresent; i < 3; i++)
{
if (_version.numbers[i] > 0)
{
cmp = 0;
break;
}
}
}

switch (prefix)
{
Expand Down
19 changes: 14 additions & 5 deletions test/libsolidity/SemVerMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ BOOST_AUTO_TEST_CASE(positive_range)
{"^0.1.2", "0.1.2"},
{"^0.1", "0.1.2"},
{"^1.2", "1.4.2"},
{"^1.2", "1.2.1-pre"},
{"^1.2", "1.2.0"},
{"^1", "1.2.0-pre"},
{"^1", "1.2.0"},
{"<=1.2.3", "1.2.3-beta"},
{">1.2", "1.3.0-beta"},
{"<1.2.3", "1.2.3-beta"},
{"^1.2 ^1", "1.4.2"}
{"^1.2 ^1", "1.4.2"},
{"^0", "0.5.1"},
{"^0", "0.1.1"},
};
for (auto const& t: tests)
{
Expand All @@ -163,13 +163,14 @@ BOOST_AUTO_TEST_CASE(positive_range)

BOOST_AUTO_TEST_CASE(negative_range)
{
// Positive range tests
// Negative range tests
vector<pair<string, string>> tests = {
{"1.0.0 - 2.0.0", "2.2.3"},
{"1.0", "1.0.0-pre"},
{"1", "1.0.0-pre"},
{"^1.2.3", "1.2.3-pre"},
{"^1.2", "1.2.0-pre"},
{"^1.2", "1.2.1-pre"},
{"^1.2.3", "1.2.3-beta"},
{"=0.7.x", "0.7.0-asdf"},
{">=0.7.x", "0.7.0-asdf"},
Expand Down Expand Up @@ -212,8 +213,16 @@ BOOST_AUTO_TEST_CASE(negative_range)
{"=1.2.3", "1.2.3-beta"},
{">1.2", "1.2.8"},
{"^1.2.3", "2.0.0-alpha"},
{"^0.6", "0.6.2-alpha"},
{"^0.6", "0.6.0-alpha"},
{"^1.2", "1.2.1-pre"},
{"^1.2.3", "1.2.2"},
{"^1.2", "1.1.9"}
{"^1", "1.2.0-pre"},
{"^1", "1.2.0-pre"},
{"^1.2", "1.1.9"},
{"^0", "0.5.1-pre"},
{"^0", "0.0.0-pre"},
{"^0", "1.0.0"},
};
for (auto const& t: tests)
{
Expand Down

0 comments on commit 5404343

Please sign in to comment.