Skip to content

Commit

Permalink
Merge branch 'master' into kayagokalp/remove-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Jul 8, 2024
2 parents f1ea14a + 5db41b5 commit 0caa09a
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 11 deletions.
3 changes: 2 additions & 1 deletion sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,11 +1261,12 @@ impl TypeInfo {
engines: &Engines,
span: &Span,
) -> Result<(), ErrorEmitted> {
const CURRENTLY_SUPPORTED_TYPES_MESSAGE: [&str; 8] = [
const CURRENTLY_SUPPORTED_TYPES_MESSAGE: [&str; 9] = [
"Sway currently supports pattern matching on these types:",
" - b256",
" - boolean",
" - enums",
" - string slices",
" - structs",
" - tuples",
" - unsigned integers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,146 @@
{
"configurableType": {
"name": "",
"type": 1,
"type": 5,
"typeArguments": null
},
"name": "BOOL",
"offset": 360
"offset": 6944
},
{
"configurableType": {
"name": "",
"type": 13,
"typeArguments": null
},
"name": "U8",
"offset": 7088
},
{
"configurableType": {
"name": "",
"type": 13,
"typeArguments": null
},
"name": "ANOTHER_U8",
"offset": 6872
},
{
"configurableType": {
"name": "",
"type": 9,
"typeArguments": null
},
"name": "U16",
"offset": 7032
},
{
"configurableType": {
"name": "",
"type": 11,
"typeArguments": null
},
"name": "U32",
"offset": 7072
},
{
"configurableType": {
"name": "",
"type": 11,
"typeArguments": null
},
"name": "U64",
"offset": 7080
},
{
"configurableType": {
"name": "",
"type": 10,
"typeArguments": null
},
"name": "U256",
"offset": 7040
},
{
"configurableType": {
"name": "",
"type": 4,
"typeArguments": null
},
"name": "B256",
"offset": 6912
},
{
"configurableType": {
"name": "",
"type": 8,
"typeArguments": []
},
"name": "CONFIGURABLE_STRUCT",
"offset": 6984
},
{
"configurableType": {
"name": "",
"type": 6,
"typeArguments": []
},
"name": "CONFIGURABLE_ENUM_A",
"offset": 6952
},
{
"configurableType": {
"name": "",
"type": 6,
"typeArguments": []
},
"name": "CONFIGURABLE_ENUM_B",
"offset": 6968
},
{
"configurableType": {
"name": "",
"type": 2,
"typeArguments": null
},
"name": "ARRAY_BOOL",
"offset": 6880
},
{
"configurableType": {
"name": "",
"type": 3,
"typeArguments": null
},
"name": "ARRAY_U64",
"offset": 6888
},
{
"configurableType": {
"name": "",
"type": 1,
"typeArguments": null
},
"name": "TUPLE_BOOL_U64",
"offset": 7016
},
{
"configurableType": {
"name": "",
"type": 7,
"typeArguments": null
},
"name": "STR_4",
"offset": 7008
},
{
"configurableType": {
"name": "",
"type": 13,
"typeArguments": null
},
"name": "NOT_USED",
"offset": 7000
}
],
"encoding": "1",
Expand All @@ -32,10 +167,127 @@
"typeId": 0,
"typeParameters": null
},
{
"components": [
{
"name": "__tuple_element",
"type": 5,
"typeArguments": null
},
{
"name": "__tuple_element",
"type": 12,
"typeArguments": null
}
],
"type": "(_, _)",
"typeId": 1,
"typeParameters": null
},
{
"components": [
{
"name": "__array_element",
"type": 5,
"typeArguments": null
}
],
"type": "[_; 3]",
"typeId": 2,
"typeParameters": null
},
{
"components": [
{
"name": "__array_element",
"type": 12,
"typeArguments": null
}
],
"type": "[_; 3]",
"typeId": 3,
"typeParameters": null
},
{
"components": null,
"type": "b256",
"typeId": 4,
"typeParameters": null
},
{
"components": null,
"type": "bool",
"typeId": 1,
"typeId": 5,
"typeParameters": null
},
{
"components": [
{
"name": "A",
"type": 5,
"typeArguments": null
},
{
"name": "B",
"type": 12,
"typeArguments": null
}
],
"type": "enum ConfigurableEnum",
"typeId": 6,
"typeParameters": null
},
{
"components": null,
"type": "str[4]",
"typeId": 7,
"typeParameters": null
},
{
"components": [
{
"name": "a",
"type": 5,
"typeArguments": null
},
{
"name": "b",
"type": 12,
"typeArguments": null
}
],
"type": "struct ConfigurableStruct",
"typeId": 8,
"typeParameters": null
},
{
"components": null,
"type": "u16",
"typeId": 9,
"typeParameters": null
},
{
"components": null,
"type": "u256",
"typeId": 10,
"typeParameters": null
},
{
"components": null,
"type": "u32",
"typeId": 11,
"typeParameters": null
},
{
"components": null,
"type": "u64",
"typeId": 12,
"typeParameters": null
},
{
"components": null,
"type": "u8",
"typeId": 13,
"typeParameters": null
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,78 @@
script;

use std::hash::*;

struct ConfigurableStruct {
a: bool,
b: u64,
}

enum ConfigurableEnum {
A: bool,
B: u64,
}

impl core::ops::Eq for ConfigurableEnum {
fn eq(self, other: ConfigurableEnum) -> bool {
match (self, other) {
(ConfigurableEnum::A(inner1), ConfigurableEnum::A(inner2)) => inner1 == inner2,
(ConfigurableEnum::B(inner1), ConfigurableEnum::B(inner2)) => inner1 == inner2,
_ => false,
}
}
}

type AnotherU8 = u8;

configurable {
BOOL: bool = true,
U8: u8 = 1,
ANOTHER_U8: AnotherU8 = 3,
U16: u16 = 2,
U32: u32 = 3,
U64: u32 = 4,
U256: u256 = 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAu256,
B256: b256 = 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
CONFIGURABLE_STRUCT: ConfigurableStruct = ConfigurableStruct { a: true, b: 5 },
CONFIGURABLE_ENUM_A: ConfigurableEnum = ConfigurableEnum::A(true),
CONFIGURABLE_ENUM_B: ConfigurableEnum = ConfigurableEnum::B(12),
ARRAY_BOOL: [bool; 3] = [true, false, true],
ARRAY_U64: [u64; 3] = [9, 8, 7],
TUPLE_BOOL_U64: (bool, u64) = (true, 11),
STR_4: str[4] = __to_str_array("abcd"),

NOT_USED: u8 = 1
}

fn main() {
assert(BOOL == true);
}
assert(U8 == 1);
assert(ANOTHER_U8 == 3);
assert(U16 == 2);
assert(U32 == 3);
assert(U64 == 4);
assert(U256 == 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAu256);
assert(B256 == 0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB);
assert(CONFIGURABLE_STRUCT.a == true);
assert(CONFIGURABLE_STRUCT.b == 5);
assert(CONFIGURABLE_ENUM_A == ConfigurableEnum::A(true));
assert(CONFIGURABLE_ENUM_B == ConfigurableEnum::B(12));
assert(ARRAY_BOOL[0] == true);
assert(ARRAY_BOOL[1] == false);
assert(ARRAY_BOOL[2] == true);
assert(ARRAY_U64[0] == 9);
assert(ARRAY_U64[1] == 8);
assert(ARRAY_U64[2] == 7);
assert(TUPLE_BOOL_U64.0 == true);
assert(TUPLE_BOOL_U64.1 == 11);
assert(sha256_str_array(STR_4) == sha256("abcd"));

// Assert address do not change
let addr_1 = asm(addr: __addr_of(&BOOL)) {
addr: u64
};
let addr_2 = asm(addr: __addr_of(&BOOL)) {
addr: u64
};
assert(addr_1 == addr_2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ category = "run"
expected_result = { action = "return", value = 0 }
expected_result_new_encoding = { action = "return_data", value = "" }
validate_abi = true
expected_warnings = 6
expected_warnings = 1
unsupported_profiles = ["debug"]

# check: $()NOT_USED: u8 = 1
# nextln: $()This declaration is never used
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ abigen!(Contract(
));

#[tokio::test]
#[ignore]
async fn run_external_can_proxy_call() {
let wallet = launch_provider_and_get_wallet().await.unwrap();

Expand Down

0 comments on commit 0caa09a

Please sign in to comment.