FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
https://docs.fuel.network/docs/sway/
Apache License 2.0
62.58k stars 5.37k forks source link

Emit unreachable arm warning for OR match arms #6505

Closed ironcev closed 2 months ago

ironcev commented 2 months ago

Description

This PR fixes #6388. If a whole OR match arm is unreachable a warning will be emitted like in this case:

match v {
    1 => (),
    2 => (),
    1 | 2 => (), <<<--- Warning emitted here.
    _ => (),
};

The PR strictly fixes the issue reported in #6388. It does not fix a previously known, more general issue, described in #5097 where we expect warnings to be emitted also on individual elements of an OR arm, even if the whole arm is reachable. E.g.:

match v {
    1 => (),
    2 => (),
    1 | 3 => (), <<<--- Warning should be emitted here that `1` is not reachable.
    2 | 4 => (), <<<--- Warning should be emitted here that `2` is not reachable.
    _ => (),
};

Fixing this issue requires more invasive restructuring of the propagation of the collected witness information and will be done in a separate PR.

Closes #6388.

Checklist

codspeed-hq[bot] commented 2 months ago

CodSpeed Performance Report

Merging #6505 will not alter performance

Comparing ironcev/6388-no-warning-for-overlaps-in-pattern-matching (7ed5f86) with master (eaac649)

Summary

✅ 21 untouched benchmarks