Skip to content

Commit

Permalink
Breaking changes in v0.8.0 (#459)
Browse files Browse the repository at this point in the history
* Fixing silent errors since v0.8.0

* missing snapshot
  • Loading branch information
Janther authored Mar 31, 2021
1 parent 6c56faa commit 2e9149b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 97 deletions.
15 changes: 12 additions & 3 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ function parse(text, parsers, options) {
: `hex"${ctx.value.slice(4, -1)}"`;
},
ElementaryTypeName(ctx) {
// We avoid making changes for bytes1 since the type 'byte' was removed
// in v0.8.0
// See the breaking changes in https://docs.soliditylang.org/en/v0.8.0/080-breaking-changes.html#silent-changes-of-the-semantics
// The type byte has been removed. It was an alias of bytes1.
// TODO once we decide to keep track of the pragma, we can implement this again.

if (options.explicitTypes === 'always') {
if (ctx.name === 'uint') ctx.name = 'uint256';
if (ctx.name === 'int') ctx.name = 'int256';
if (ctx.name === 'byte') ctx.name = 'bytes1';
} else if (options.explicitTypes === 'never') {
if (ctx.name === 'uint256') ctx.name = 'uint';
if (ctx.name === 'int256') ctx.name = 'int';
if (ctx.name === 'bytes1') ctx.name = 'byte';
}
},
BinaryOperation(ctx) {
Expand All @@ -56,7 +60,12 @@ function parse(text, parsers, options) {
ctx.left = tryHug(ctx.left, ['*', '/', '%']);
break;
case '**':
ctx.left = tryHug(ctx.left, ['**']);
// We avoid making changes here since the order of precedence of the
// operators for ** changed in v0.8.0
// See the breaking changes in https://docs.soliditylang.org/en/v0.8.0/080-breaking-changes.html#silent-changes-of-the-semantics
// Exponentiation is right associative, i.e., the expression a**b**c
// is parsed as a**(b**c). Before 0.8.0, it was parsed as (a**b)**c.
// TODO once we decide to keep track of the pragma, we can implement this again.
break;
case '<<':
case '>>':
Expand Down
2 changes: 1 addition & 1 deletion tests/BinaryOperators/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ contract Parentheses {
a**b * c;
a**b / c;
a**b % c;
(a**b)**c;
a**b**c;
(a**b) << c;
(a**b) >> c;
(a**b) & c;
Expand Down
28 changes: 17 additions & 11 deletions tests/ExplicitVariableTypes/ExplicitVariableTypes.sol
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
pragma solidity 0.5.8;

// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;

contract VariableTypesMixed {
uint256 public a;
int256 public b;
bytes1 public c;
uint public e;
int public f;
byte public g;

struct S {
uint a;
int b;
byte c;
uint256 e;
int256 f;
bytes1 g;
}

event Event(uint _a, int256 _b, bytes1 _c, uint256 _e, int _f, byte _g);
event Event(uint _a, int256 _b, uint256 _e, int _f);

function func(uint256 _a, int256 _b, byte _c, uint _e, int _f, bytes1 _g)
function func(
uint256 _a,
int256 _b,
uint _e,
int _f
)
public
returns (uint, int256, byte, uint256, int, bytes1)
returns (
uint,
int256,
uint256,
int
)
{
emit Event(_a, _b, _c, _e, _f, _g);
return (_a, _b, _c, _e, _f, _g);
emit Event(_a, _b, _e, _f);
return (_a, _b, _e, _f);
}
}
Loading

0 comments on commit 2e9149b

Please sign in to comment.