Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never Type For Arrays #6387

Closed
IGI-111 opened this issue Aug 7, 2024 · 1 comment
Closed

Never Type For Arrays #6387

IGI-111 opened this issue Aug 7, 2024 · 1 comment
Assignees
Labels
audit-report Related to the audit report bug Something isn't working P: low team:compiler Compiler Team

Comments

@IGI-111
Copy link
Contributor

IGI-111 commented Aug 7, 2024

CS-FSSA-021

Empty arrays are assigned the never type. Never type is treated as a subtype of all types. This means
that a never array should be assignable to an empty array of any other type. Moroever, if we assign an
empty array to a type-ascribed variable, the type of this variable should be its ascription. This is not true
in the following example.

script;
impl [u32;0] {
 fn foo(self){
 log("32");
 }
}
impl [!;0] {
 fn foo(self){
 log("never");
 }
}
fn main() {
 let x:[u32;0] = [];
 x.foo(); // logs "never"
}

The never type in arrays is more problematic considering the following case which also compiles:

let x:[u32;0] = [];
let y: [!;0] = x;

As one would expect x to preserve its ascription assigning x to y should fail since the never type is a
subtype of the [u32;0].

@IGI-111 IGI-111 added bug Something isn't working P: low audit-report Related to the audit report labels Aug 7, 2024
@jjcnn jjcnn added the team:compiler Compiler Team label Feb 10, 2025
tritao pushed a commit that referenced this issue Feb 20, 2025
## Description

Shows that #6387 has been fixed.

This PR adds a few tests of variable initializers that involve type
Never. In this case the variable's type ascription should be used
instead of the initializer's type.

No changes have been made to the compiler, since the problem that was
originally reported was fixed by #6911.


## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] 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.
@jjcnn
Copy link
Contributor

jjcnn commented Feb 24, 2025

Fixed by #6911 .

@jjcnn jjcnn closed this as completed Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-report Related to the audit report bug Something isn't working P: low team:compiler Compiler Team
Projects
None yet
Development

No branches or pull requests

2 participants