argotorg / argotorg/solidity

Comparison of a fixed type and a rational literal is not commutative

Open
#14,175 2 comments 0 reactions 0 assignees View on GitHub
bug :bug: low effort low impact nice to have
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description

```solidity
function fixed_number_test(fixed num) {
// Compiles
if (num > 2.5) {}
// Does not compile
if (2.5 < num) {}
}
```

When comparing a fixed/ufixed number and a rational literal, the Solidity compiler compiles the code when the fixed number is on the LHS side, but it doesn't when LHS and RHS are swapped.

## Environment

- Compiler version: `0.8.18+commit.87f61d96.Linux.g++`
- Target EVM version (as per compiler settings): default
- Framework/IDE (e.g. Truffle or Remix): Direct invocation from CLI (`solc test.sol`)
- EVM execution environment / backend / blockchain client: N/A
- Operating system: Ubuntu 22.04.2 LTS server

## Steps to Reproduce

Save the above code as `test.sol` and run `solc test.sol`. Line 3 compiles, but line 5 fails to compile with message "Built-in binary operator < cannot be applied to types rational_const 5 / 2 and fixed128x18. Fractional literals not supported."

I expect Solidity to treat both lines equally.

Contributor guide

Open the contributing guide

Research direction

Reproduce the fixed_number_test example in test.sol by running solc test.sol, then compare the diagnostics for the two operand orders. Trace the Solidity compiler's type-checking path for binary comparisons; done means both comparisons are handled consistently and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.