Skip to content

Commit b07d0ca

Browse files
authored
Add test of never type in arrays (#6943)
## 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.
1 parent 69ac39e commit b07d0ca

File tree

6 files changed

+72
-2
lines changed

6 files changed

+72
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[package]]
2+
name = "core"
3+
source = "path+from-root-DFCFC85C94C0C9BD"
4+
5+
[[package]]
6+
name = "std"
7+
source = "path+from-root-DFCFC85C94C0C9BD"
8+
dependencies = ["core"]
9+
10+
[[package]]
11+
name = "unify_never"
12+
source = "member"
13+
dependencies = ["std"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[project]
2+
authors = ["Fuel Labs <contact@fuel.sh>"]
3+
license = "Apache-2.0"
4+
name = "unify_never"
5+
entry = "main.sw"
6+
7+
[dependencies]
8+
std = { path = "../../../reduced_std_libs/sway-lib-std-assert" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
script;
2+
3+
// Test of unification of the Never type
4+
5+
impl [u32;0] {
6+
fn foo(self){
7+
log("32");
8+
}
9+
}
10+
11+
impl [!;0] {
12+
fn foo(self){
13+
log("never");
14+
}
15+
}
16+
17+
fn main() {
18+
let z:[u32;0] = [];
19+
20+
// Should fail because z gets the type of its type ascription
21+
let y: [!;0] = z;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
category = "fail"
2+
3+
#check: $()error
4+
#check: $()Mismatched types
5+
#nextln: $()expected: [!; 0]
6+
#nextln: $()found: [u32; 0].
7+
#nextln: $()help: Variable declaration's type annotation does not match up with the assigned expression's type
8+
9+
#check: $()Aborting due to 1 error

test/src/e2e_vm_tests/test_programs/should_pass/language/unify_never/src/main.sw

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@ fn test_2(){
1313
}
1414

1515

16-
fn main() {
16+
impl [u32;0] {
17+
fn foo(self) -> u64 {
18+
32
19+
}
20+
}
21+
22+
impl [!;0] {
23+
fn foo(self) -> u64{
24+
64
25+
}
26+
}
27+
28+
fn main() -> u64 {
1729
test_1();
1830
test_2();
31+
32+
let x:[u32;0] = [];
33+
x.foo() // should return 32
1934
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
category = "compile"
1+
category = "run"
22
expected_warnings = 1
3+
expected_result = { action = "return", value = 32 }
4+
expected_result_new_encoding = { action = "return_data", value = "0000000000000020" }
5+
validate_abi = false

0 commit comments

Comments
 (0)