Skip to content

Never Type For Arrays #6387

@IGI-111

Description

@IGI-111

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].

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions