sway icon indicating copy to clipboard operation
sway copied to clipboard

Sway hex literals have their suffix counted as digits

Open camden-smallwood opened this issue 1 year ago • 3 comments

Related Component

compiler

Problem

As the title states, hex literals have their optional suffix counted as part of their digits. This causes the following error, and related errors for types aside from b256:

  --> /Users/camden/Source/charcoal/out/ds_auth/src/main.sw:69:75
   |
67 |     } else if src == storage.owner.read() {
68 |         return true;
69 |     } else if storage.authority.read() == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000000b256)) {
   |                                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ hex literals must have 1..16 or 64 digits
70 |         return false;
71 |     } else {

If we count the zeroes, logically we can deduce that there is in fact exactly 64 digits in the following:

0x0000000000000000000000000000000000000000000000000000000000000000b256

But there is no attempt made to strip the b256 before counting.

Steps

  1. Create a sway project.
  2. Create a b256 variable using the 0x0000000000000000000000000000000000000000000000000000000000000000b256 constant.
  3. Run forc build

Possible Solution(s)

Maybe strip the suffix before this point: https://github.com/FuelLabs/sway/blob/73e1a7a80301d341864ea75de4124bf98d52a3ce/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs#L3388-L3402

Notes

Should be an easy fix, but it should be done ASAP.

Installed components

camden@Camdens-MacBook-Air sway % fuelup check
latest - Up to date
fuelup - Up to date
camden@Camdens-MacBook-Air sway % fuelup show
Default host: aarch64-apple-darwin
fuelup home: /Users/camden/.fuelup

Installed toolchains
--------------------
latest-aarch64-apple-darwin (default)

active toolchain
----------------
latest-aarch64-apple-darwin (default)
  forc : 0.66.4
    - forc-client
      - forc-deploy : 0.66.4
      - forc-run : 0.66.4
    - forc-crypto : 0.66.4
    - forc-debug : 0.66.4
    - forc-doc : 0.66.4
    - forc-fmt : 0.66.4
    - forc-lsp : 0.66.4
    - forc-tx : 0.66.4
    - forc-wallet : 0.11.1
  fuel-core : 0.40.0
  fuel-core-keygen : 0.40.0

fuels versions
--------------
forc : 0.66.9
forc-wallet : 0.66.9

camden-smallwood avatar Nov 16 '24 19:11 camden-smallwood

Can I handle this task?

krishnabandewar avatar Mar 03 '25 06:03 krishnabandewar

Can I contribute to this one?

Samibhr09 avatar Mar 08 '25 10:03 Samibhr09

Hey I'd like to handle this task, I will carefully study the possible solution hinted at and see how to best implement the fix.

saimeunt avatar Mar 20 '25 21:03 saimeunt