You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When it comes to typing the elements of an array, the type system is not able to stick to proper types.
This leads to the following snippets all successfully compiling:
leta= [8, 8, 8u64];
letb:u32=a[2];
// compiles even though we have given a hintleta= [1u32, 1u64];
letb:u32=a[1];
## Description
This PR fixes: #6376
The issue is that we use the first element of the array as its element
type. This can be problematic as the first element is not "concrete".
For example, when it is `Numeric`.
Now we iterate the array elements, search for the first "good" element,
and use its type as the array type. This means:
1 - if the type is concrete, we use it;
2 - if the type is `Numeric`, we keep searching for something better;
This allows consistent arrays, but where the concrete types are at the
end.
```sway
let a = [1, 2u8]; <- we will choose u8
let a = [None, Some(1), Some(2u8)]; <- we will choose Option<u8>, instead of Option<T>
```
## snapshot tests
This PR also brings an experiment. Now when an "e2e" test has a file
`snapshot.toml` it will run as `cargo insta` snapshot tests. These tests
can be run as normal: `cargo r -p test`, and in two new ways:
```
> cargo t -p test
> cargo insta test
```
Snapshots can be reviewed using normal "cargo insta" workflow.
The secret lies in https://github.com/LukasKalbertodt/libtest-mimic. **I
also want to suggest that all our tests migrate to this model**, where
we could just use "cargo test" normally. Apart from that, I opted to use
the `forc` executable, which means tests will run in parallel. In the
future, if we want to poke compiler internals, we can expose them using
flags, or create a special binary to fit our needs.
`snapshot.toml` is still empty because I have no idea to what put there
at the moment. My initial idea was to configure what ends up into
snapshots (multiple runs, compiler flags, script/contract calls) etc...
But for the moment, empty is enough.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: IGI-111 <igi-111@protonmail.com>
CS-FSSA-010
When it comes to typing the elements of an array, the type system is not able to stick to proper types.
This leads to the following snippets all successfully compiling:
Note, this issue relates to two other issue reported regarding typing of arrays and typing of literals
The text was updated successfully, but these errors were encountered: