hyperledger-solang / solang

Solidity Compiler for Solana and Polkadot
https://solang.readthedocs.io/
Apache License 2.0
1.27k stars 215 forks source link

Bugfix: Propagate RHS type of resolved assignments #1569

Closed xermicus closed 1 year ago

xermicus commented 1 year ago

When resolving an assignment, the resolved variable should inherit the RHS type to avoid various issues in later compilation stages (for example with assignment chains).

codecov[bot] commented 1 year ago

Codecov Report

Merging #1569 (b6ba9df) into main (242ebfd) will decrease coverage by 0.08%. The diff coverage is 100.00%.

:exclamation: Current head b6ba9df differs from pull request most recent head 65b71bd. Consider uploading reports for the commit 65b71bd to get more accurate results

@@            Coverage Diff             @@
##             main    #1569      +/-   ##
==========================================
- Coverage   87.41%   87.34%   -0.08%     
==========================================
  Files         133      133              
  Lines       64133    64148      +15     
==========================================
- Hits        56063    56029      -34     
- Misses       8070     8119      +49     
Files Coverage Δ
src/codegen/expression.rs 95.28% <100.00%> (ø)
src/sema/types.rs 95.20% <100.00%> (+0.01%) :arrow_up:

... and 9 files with indirect coverage changes

xermicus commented 1 year ago

I changed the fix to use the RHS type of the assignment. Which seems to fix a bunch of cases (see codegen tests).

The FIXME added to the constant folding codegen test should go away after #1450. Unless there is easy fix for this, I think it deserves a dedicated fix (in the sense of a unused variable pass after codegen / until it converges). Otherwise the problem might only be partially fixed.