这是混音、编译器还是 openzeplin 错误?

Is this a remix,compiler or an openzeplin bug?

我刚刚写了一个简单的代码来测试 openzeplin Safemath 库。我正在使用最新版本的 remix ide 并针对 ^0.5.0 进行编译。 Remix 使用 0.5.0_commit.1d4f565a 编译器 环境是 JavaScript VM EVM 版本是编译器默认值

添加函数在下面给出的代码中似乎不起作用

我试过x.sub(1) 它按预期抛出异常,我也试过将 x 初始化为不同的值但仍然不起作用。

pragma solidity ^0.5.0;
import "./SafeMath.sol";

contract SimpleStorage {
    using SafeMath for uint;
    uint x;

    event incremented(uint x);

    constructor() public{
        x=0;
    }

    function increment() public {
        x.add(1);
        emit incremented(x);
    }

    function get() external view returns (uint) {
        return x;
    }
}

预期输出在每次调用函数时递增 1,但每次都获得相同的值。 Emit 也显示相同的值。

好吧,这是你的错误:)

尝试 x = x.add(1) 而不是 x.add(1)。添加函数不在位,返回新值,需要将新值赋值给x.