User-defined operator
Attach the plus operator to a user-defined value type.
Why use this example
Use this pattern to test contract composition, external calls, events, and return values inside one reproducible run. The entry isolates user-defined operator so its input, result, and state changes stay easy to compare.
Solidity to run
import "./Price.sol"
Price subtotal = Price.wrap(20)
Price fee = Price.wrap(2)
Price total = subtotal + fee
Price.unwrap(total)Official Solidity reference
Compare this focused investigation with the complete language definition in the Solidity documentation.
User-defined operatorsIncluded local files
Solidity REPL creates these files before compiling the main entry, so its imports resolve without additional setup.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
type Price is uint256;
function addPrice(Price left, Price right) pure returns (Price) {
return Price.wrap(Price.unwrap(left) + Price.unwrap(right));
}
using { addPrice as + } for Price global;
What to expect
The globally attached plus operator combines the wrapped Price values and unwraps to 22.
Continue the investigation
Change a value, add another expression, or open Inspect after the run. Accepted entries remain available to the next entry, and the clean replay keeps the complete result reproducible.
Read about calls and logs Reproducible investigation