From d00704ffdf5dcca3290e1634f7923ce722cbb949 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Sat, 12 Jun 2021 18:34:18 +0200 Subject: [PATCH 01/14] optimize flag changed to option with default true --- src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 33723cd4f2..c63872d27d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -152,14 +152,18 @@ pub fn main() { .arg( Arg::with_name("optimize") .long("optimize") - .help("Enables the Yul optimizer`"), + .help("Enables the Yul optimizer`") + .possible_values(&["true", "false"]) + .default_value("true") + .use_delimiter(false) + .takes_value(true), ) .get_matches(); let input_file = matches.value_of("input").unwrap(); let output_dir = matches.value_of("output-dir").unwrap(); let overwrite = matches.is_present("overwrite"); - let optimize = matches.is_present("optimize"); + let optimize = matches.value_of("optimize")==Some("true"); let targets = values_t!(matches.values_of("emit"), CompilationTarget).unwrap_or_else(|e| e.exit()); let with_bytecode = targets.contains(&CompilationTarget::Bytecode); From 302f9c1e26b93127e4810c8ba82aed09656b2897 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 15 Jun 2021 05:20:13 +0200 Subject: [PATCH 02/14] formatting --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c63872d27d..05108050d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,7 +163,7 @@ pub fn main() { let input_file = matches.value_of("input").unwrap(); let output_dir = matches.value_of("output-dir").unwrap(); let overwrite = matches.is_present("overwrite"); - let optimize = matches.value_of("optimize")==Some("true"); + let optimize = matches.value_of("optimize") == Some("true"); let targets = values_t!(matches.values_of("emit"), CompilationTarget).unwrap_or_else(|e| e.exit()); let with_bytecode = targets.contains(&CompilationTarget::Bytecode); From a24267098f568cee5317f52bb289377f580fbb8a Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 15 Jun 2021 06:15:47 +0200 Subject: [PATCH 03/14] formatting --- docs/src/quickstart/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/quickstart/installation.md b/docs/src/quickstart/installation.md index 4f96292021..a3a43a3b41 100644 --- a/docs/src/quickstart/installation.md +++ b/docs/src/quickstart/installation.md @@ -28,13 +28,13 @@ USAGE: FLAGS: -h, --help Prints help information - --optimize Enables the Yul optimizer` --overwrite Overwrite contents of output directory` -V, --version Prints version information OPTIONS: -e, --emit Comma separated compile targets e.g. -e=bytecode,yul [default: abi,bytecode] [possible values: abi, bytecode, ast, tokens, yul, loweredAst] + --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] -o, --output-dir The directory to store the compiler output e.g /tmp/output [default: output] ARGS: From 814bfcfbaa6cffc908bbe7f825b4a9fc3e01766f Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 15 Jun 2021 06:19:26 +0200 Subject: [PATCH 04/14] formatting --- docs/src/quickstart/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/quickstart/installation.md b/docs/src/quickstart/installation.md index a3a43a3b41..c663a66132 100644 --- a/docs/src/quickstart/installation.md +++ b/docs/src/quickstart/installation.md @@ -34,7 +34,7 @@ FLAGS: OPTIONS: -e, --emit Comma separated compile targets e.g. -e=bytecode,yul [default: abi,bytecode] [possible values: abi, bytecode, ast, tokens, yul, loweredAst] - --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] + --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] -o, --output-dir The directory to store the compiler output e.g /tmp/output [default: output] ARGS: From 5df55c400534f9e292787d2f0b67d26e57a4e828 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 15 Jun 2021 06:22:26 +0200 Subject: [PATCH 05/14] formatting --- docs/src/quickstart/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/quickstart/installation.md b/docs/src/quickstart/installation.md index c663a66132..ea211418a1 100644 --- a/docs/src/quickstart/installation.md +++ b/docs/src/quickstart/installation.md @@ -34,7 +34,7 @@ FLAGS: OPTIONS: -e, --emit Comma separated compile targets e.g. -e=bytecode,yul [default: abi,bytecode] [possible values: abi, bytecode, ast, tokens, yul, loweredAst] - --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] + --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] -o, --output-dir The directory to store the compiler output e.g /tmp/output [default: output] ARGS: From 76116b8bb9c5d5b0f3c4e3e55b068b3b07d24f64 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 15 Jun 2021 06:23:35 +0200 Subject: [PATCH 06/14] formatting --- docs/src/quickstart/installation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/quickstart/installation.md b/docs/src/quickstart/installation.md index ea211418a1..01a1f7031b 100644 --- a/docs/src/quickstart/installation.md +++ b/docs/src/quickstart/installation.md @@ -34,7 +34,8 @@ FLAGS: OPTIONS: -e, --emit Comma separated compile targets e.g. -e=bytecode,yul [default: abi,bytecode] [possible values: abi, bytecode, ast, tokens, yul, loweredAst] - --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] + --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false + [default: true] -o, --output-dir The directory to store the compiler output e.g /tmp/output [default: output] ARGS: From 70b8d595fa33627b59cb1536447cf0e71be901e8 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 15 Jun 2021 06:24:08 +0200 Subject: [PATCH 07/14] formatting --- docs/src/quickstart/installation.md | 3 +-- newsfragments/439.feature.md | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 newsfragments/439.feature.md diff --git a/docs/src/quickstart/installation.md b/docs/src/quickstart/installation.md index 01a1f7031b..149843d5b1 100644 --- a/docs/src/quickstart/installation.md +++ b/docs/src/quickstart/installation.md @@ -34,8 +34,7 @@ FLAGS: OPTIONS: -e, --emit Comma separated compile targets e.g. -e=bytecode,yul [default: abi,bytecode] [possible values: abi, bytecode, ast, tokens, yul, loweredAst] - --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false - [default: true] + --optimize Whether the Yul optimizer should be used or not e.g. --optimize=false [default: true] -o, --output-dir The directory to store the compiler output e.g /tmp/output [default: output] ARGS: diff --git a/newsfragments/439.feature.md b/newsfragments/439.feature.md new file mode 100644 index 0000000000..593e850293 --- /dev/null +++ b/newsfragments/439.feature.md @@ -0,0 +1,2 @@ +Enable the optimizer by default. The optimizer can still be disabled +by supplying `--optimize=false` as an argument. From 104a908ba286dc8ec3bd9b120e06c6768fc98412 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 22 Jun 2021 19:43:10 +0200 Subject: [PATCH 08/14] add support for string type items in structs and test it as part of issue #343 --- analyzer/src/traversal/structs.rs | 94 +++++++++++++------ compiler/src/yul/runtime/functions/structs.rs | 6 +- test.fe | 17 +++- tests/fixtures/features/struct_with_string.fe | 17 ++++ tests/src/features.rs | 14 +++ 5 files changed, 115 insertions(+), 33 deletions(-) create mode 100644 tests/fixtures/features/struct_with_string.fe diff --git a/analyzer/src/traversal/structs.rs b/analyzer/src/traversal/structs.rs index 28301dbc70..c350e1843f 100644 --- a/analyzer/src/traversal/structs.rs +++ b/analyzer/src/traversal/structs.rs @@ -19,38 +19,72 @@ pub fn struct_def( for field in fields { let fe::Field { name, typ, .. } = &field.kind; let field_type = type_desc(&Scope::Module(Rc::clone(&module_scope)), context, typ)?; - if let Type::Base(base_typ) = field_type { - if let Err(AlreadyDefined) = val.add_field(&name.kind, &FixedSize::Base(base_typ)) { - let first_definition = fields - .iter() - .find(|val| { - let fe::Field { - name: inner_name, .. - } = &val.kind; - inner_name.kind == name.kind && val.span != field.span - }) - .expect("Missing field"); + match field_type { + Type::Base(base_typ) => { + if let Err(AlreadyDefined) = val.add_field(&name.kind, &FixedSize::Base(base_typ)) { + let first_definition = fields + .iter() + .find(|val| { + let fe::Field { + name: inner_name, .. + } = &val.kind; + inner_name.kind == name.kind && val.span != field.span + }) + .expect("Missing field"); - context.fancy_error( - "a struct field with the same name already exists", - vec![ - Label::primary( - first_definition.span, - format!("First definition of field `{}`", name.kind), - ), - Label::primary( - field.span, - format!("Conflicting definition of field `{}`", name.kind), - ), - ], - vec![format!( - "Note: Give one of the `{}` fields a different name", - name.kind - )], - ) + context.fancy_error( + "a struct field with the same name already exists", + vec![ + Label::primary( + first_definition.span, + format!("First definition of field `{}`", name.kind), + ), + Label::primary( + field.span, + format!("Conflicting definition of field `{}`", name.kind), + ), + ], + vec![format!( + "Note: Give one of the `{}` fields a different name", + name.kind + )], + ) + } } - } else { - context.not_yet_implemented("non-base type struct fields", field.span) + Type::String(string_typ) => { + if let Err(AlreadyDefined) = + val.add_field(&name.kind, &FixedSize::String(string_typ)) + { + let first_definition = fields + .iter() + .find(|val| { + let fe::Field { + name: inner_name, .. + } = &val.kind; + inner_name.kind == name.kind && val.span != field.span + }) + .expect("Missing field"); + + context.fancy_error( + "a struct field with the same name already exists", + vec![ + Label::primary( + first_definition.span, + format!("First definition of field `{}`", name.kind), + ), + Label::primary( + field.span, + format!("Conflicting definition of field `{}`", name.kind), + ), + ], + vec![format!( + "Note: Give one of the `{}` fields a different name", + name.kind + )], + ) + } + } + _ => context.not_yet_implemented("non-base type struct fields", field.span), } } if let Err(AlreadyDefined) = module_scope diff --git a/compiler/src/yul/runtime/functions/structs.rs b/compiler/src/yul/runtime/functions/structs.rs index 9da919026a..0b62aad42c 100644 --- a/compiler/src/yul/runtime/functions/structs.rs +++ b/compiler/src/yul/runtime/functions/structs.rs @@ -72,7 +72,11 @@ pub fn generate_get_fn(struct_type: &Struct, field_name: &str) -> yul::Statement // field, we must take into consideration the left-padding. The left-padding is // equal to the difference between the value's size and 32 bytes, so we end up // adding the word offset and the byte offset. - let field_offset = field_index * 32 + (32 - field_type.size()); + let field_offset = if field_type.size() < 32 { + field_index * 32 + (32 - field_type.size()) + } else { + field_index * field_type.size() + }; let offset = literal_expression! { (field_offset) }; function_definition! { diff --git a/test.fe b/test.fe index 86ff165a8e..d0517a32a8 100644 --- a/test.fe +++ b/test.fe @@ -1,3 +1,16 @@ +struct TodoItem: + amount: u256 + content: String<100> contract Foo: - pub def bar(): - (42,).abi_encode() + ti1: TodoItem + ti2: TodoItem + + pub def set_item(): + self.ti1.content = String<100>("Fooooo") + self.ti2.content = String<100>("Fooooo2") + + pub def get_number() -> u256: + return self.ti1.amount + + pub def get_some_string() -> String<100>: + return self.ti1.content.to_mem() \ No newline at end of file diff --git a/tests/fixtures/features/struct_with_string.fe b/tests/fixtures/features/struct_with_string.fe new file mode 100644 index 0000000000..ea4d839ab6 --- /dev/null +++ b/tests/fixtures/features/struct_with_string.fe @@ -0,0 +1,17 @@ +struct TodoItem: + amount: u256 + content: String<100> +contract Foo: + ti1: TodoItem + ti2: TodoItem + + pub def set_item(): + self.ti1.content = String<100>("Fooooo") + self.ti2.content = String<100>("Fooooo2") + + pub def get_number() -> u256: + return self.ti1.amount + + pub def get_some_string() -> String<100>: + self.set_item() + return self.ti1.content.to_mem() \ No newline at end of file diff --git a/tests/src/features.rs b/tests/src/features.rs index 1e64706dc7..b7688d8ed9 100644 --- a/tests/src/features.rs +++ b/tests/src/features.rs @@ -1193,6 +1193,20 @@ fn create_contract_from_init() { }) } +#[test] +fn struct_with_string() { + with_executor(&|mut executor| { + let string_harness = deploy_contract(&mut executor, "struct_with_string.fe", "Foo", &[]); + + string_harness.test_function( + &mut executor, + "get_some_string", + &[], + Some(&string_token("Fooooo")), + ); + }) +} + #[rstest( fixture_file, contract_name, From f3c6f2c77be71891d91ec39ee77eb3657d32c2ce Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Tue, 22 Jun 2021 19:54:40 +0200 Subject: [PATCH 09/14] . --- test.fe | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/test.fe b/test.fe index d0517a32a8..e5b7ee7ba7 100644 --- a/test.fe +++ b/test.fe @@ -1,16 +1,3 @@ -struct TodoItem: - amount: u256 - content: String<100> contract Foo: - ti1: TodoItem - ti2: TodoItem - - pub def set_item(): - self.ti1.content = String<100>("Fooooo") - self.ti2.content = String<100>("Fooooo2") - - pub def get_number() -> u256: - return self.ti1.amount - - pub def get_some_string() -> String<100>: - return self.ti1.content.to_mem() \ No newline at end of file + pub def bar(): + (42,).abi_encode() \ No newline at end of file From 1554a6403bbd0fecfd9a521f5ccfa39eea501bd0 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Thu, 24 Jun 2021 08:05:02 +0200 Subject: [PATCH 10/14] updated spec to include strings --- docs/src/spec/index.md | 8 +++++++- test.fe | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/src/spec/index.md b/docs/src/spec/index.md index 52ca61daa5..3ef268b8f8 100644 --- a/docs/src/spec/index.md +++ b/docs/src/spec/index.md @@ -642,7 +642,13 @@ MISSING ### 5.1.1.13. String types -MISSING +A String type. + +Example: + +``` +content: String<100> +``` ### 5.1.1.14. Event types diff --git a/test.fe b/test.fe index e5b7ee7ba7..79cb8ba481 100644 --- a/test.fe +++ b/test.fe @@ -1,3 +1,2 @@ contract Foo: - pub def bar(): - (42,).abi_encode() \ No newline at end of file + content: String<100> \ No newline at end of file From aef99bb9ec45d44eb0c2ae69c014efd6fa021ac4 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Thu, 24 Jun 2021 09:26:19 +0200 Subject: [PATCH 11/14] addded support for nested structs --- .vscode/launch.json | 16 ++++++ analyzer/src/traversal/structs.rs | 66 ++++++++++++++++++++++++ output/Foo/Foo.bin | 1 + output/Foo/Foo_abi.json | 19 +++++++ output/Foo2/Foo2.bin | 1 + output/Foo2/Foo2_abi.json | 19 +++++++ test.fe | 10 +++- tests/fixtures/features/nested_struct.fe | 13 +++++ tests/src/features.rs | 14 +++++ 9 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 output/Foo/Foo.bin create mode 100644 output/Foo/Foo_abi.json create mode 100644 output/Foo2/Foo2.bin create mode 100644 output/Foo2/Foo2_abi.json create mode 100644 tests/fixtures/features/nested_struct.fe diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..b5f1d1f8cc --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/target/debug/fe", + "args": ["--overwrite","test.fe"], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/analyzer/src/traversal/structs.rs b/analyzer/src/traversal/structs.rs index c350e1843f..5ca599ead7 100644 --- a/analyzer/src/traversal/structs.rs +++ b/analyzer/src/traversal/structs.rs @@ -84,6 +84,72 @@ pub fn struct_def( ) } } + Type::Struct(struct_typ) => { + if let Err(AlreadyDefined) = + val.add_field(&name.kind, &FixedSize::Struct(struct_typ)) + { + let first_definition = fields + .iter() + .find(|val| { + let fe::Field { + name: inner_name, .. + } = &val.kind; + inner_name.kind == name.kind && val.span != field.span + }) + .expect("Missing field"); + + context.fancy_error( + "a struct field with the same name already exists", + vec![ + Label::primary( + first_definition.span, + format!("First definition of field `{}`", name.kind), + ), + Label::primary( + field.span, + format!("Conflicting definition of field `{}`", name.kind), + ), + ], + vec![format!( + "Note: Give one of the `{}` fields a different name", + name.kind + )], + ) + } + } + Type::Tuple(tuple_typ) => { + if let Err(AlreadyDefined) = + val.add_field(&name.kind, &FixedSize::Tuple(tuple_typ)) + { + let first_definition = fields + .iter() + .find(|val| { + let fe::Field { + name: inner_name, .. + } = &val.kind; + inner_name.kind == name.kind && val.span != field.span + }) + .expect("Missing field"); + + context.fancy_error( + "a struct field with the same name already exists", + vec![ + Label::primary( + first_definition.span, + format!("First definition of field `{}`", name.kind), + ), + Label::primary( + field.span, + format!("Conflicting definition of field `{}`", name.kind), + ), + ], + vec![format!( + "Note: Give one of the `{}` fields a different name", + name.kind + )], + ) + } + } _ => context.not_yet_implemented("non-base type struct fields", field.span), } } diff --git a/output/Foo/Foo.bin b/output/Foo/Foo.bin new file mode 100644 index 0000000000..4a4a12f4da --- /dev/null +++ b/output/Foo/Foo.bin @@ -0,0 +1 @@ +61032a80610010600039806000f350fe60003560e01c63d794d55881146100205763e2a9de7481146100ee576100f8565b610028610103565b506100316101da565b6000805b60011561008757602082016084811015156100505750610087565b817e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc5088015483850152809250506001810190505b610035565b816084038260841415156100ce576100cd827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc508801548260031b610100031c8285870161024f565b5b5050506100db8151610235565b6040016100e78261026a565bf3506100f8565b6100f6610103565b505b5060006000f3610322565b6000600660008051905080151561011957602090505b60208082016000528282528261032461013185610216565b3960009250825b600115610189578184016084811015156101525750610189565b84840151827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155809450506001810190505b610138565b8360841415156101ce578383015191508360840360031b6101000382811c811b827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155505b50505050600090505b90565b600060005190508015156101ed57602090505b608481016000525b90565b6000600051905080151561020b57602090505b602081016000525b90565b6000600051905080151561022957602090505b8181016000525b919050565b6000601f19601f83011690505b919050565b60208152505b565b8160031b82820151811c8482610100031b178252505050505b565b600060008051905080151561027e57602090505b8091505061029261028d6101f8565b610247565b815161029c6101f8565b5281516102a881610216565b60005b6001156102dc57602080820184811015156102c75750506102dc565b8183880101518385015280925050505b6102ab565b808303818414151561030557610304602083880101518260031b610100031c8284860161024f565b5b50505061031a81601f19601f84011603610216565b50505b919050565bfe466f6f6f6f6f \ No newline at end of file diff --git a/output/Foo/Foo_abi.json b/output/Foo/Foo_abi.json new file mode 100644 index 0000000000..e551ea7dfe --- /dev/null +++ b/output/Foo/Foo_abi.json @@ -0,0 +1,19 @@ +[ + { + "name": "set_item", + "type": "function", + "inputs": [], + "outputs": [] + }, + { + "name": "get_some_string", + "type": "function", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string" + } + ] + } +] \ No newline at end of file diff --git a/output/Foo2/Foo2.bin b/output/Foo2/Foo2.bin new file mode 100644 index 0000000000..4a4a12f4da --- /dev/null +++ b/output/Foo2/Foo2.bin @@ -0,0 +1 @@ +61032a80610010600039806000f350fe60003560e01c63d794d55881146100205763e2a9de7481146100ee576100f8565b610028610103565b506100316101da565b6000805b60011561008757602082016084811015156100505750610087565b817e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc5088015483850152809250506001810190505b610035565b816084038260841415156100ce576100cd827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc508801548260031b610100031c8285870161024f565b5b5050506100db8151610235565b6040016100e78261026a565bf3506100f8565b6100f6610103565b505b5060006000f3610322565b6000600660008051905080151561011957602090505b60208082016000528282528261032461013185610216565b3960009250825b600115610189578184016084811015156101525750610189565b84840151827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155809450506001810190505b610138565b8360841415156101ce578383015191508360840360031b6101000382811c811b827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155505b50505050600090505b90565b600060005190508015156101ed57602090505b608481016000525b90565b6000600051905080151561020b57602090505b602081016000525b90565b6000600051905080151561022957602090505b8181016000525b919050565b6000601f19601f83011690505b919050565b60208152505b565b8160031b82820151811c8482610100031b178252505050505b565b600060008051905080151561027e57602090505b8091505061029261028d6101f8565b610247565b815161029c6101f8565b5281516102a881610216565b60005b6001156102dc57602080820184811015156102c75750506102dc565b8183880101518385015280925050505b6102ab565b808303818414151561030557610304602083880101518260031b610100031c8284860161024f565b5b50505061031a81601f19601f84011603610216565b50505b919050565bfe466f6f6f6f6f \ No newline at end of file diff --git a/output/Foo2/Foo2_abi.json b/output/Foo2/Foo2_abi.json new file mode 100644 index 0000000000..e551ea7dfe --- /dev/null +++ b/output/Foo2/Foo2_abi.json @@ -0,0 +1,19 @@ +[ + { + "name": "set_item", + "type": "function", + "inputs": [], + "outputs": [] + }, + { + "name": "get_some_string", + "type": "function", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string" + } + ] + } +] \ No newline at end of file diff --git a/test.fe b/test.fe index 79cb8ba481..e222296a55 100644 --- a/test.fe +++ b/test.fe @@ -1,2 +1,8 @@ -contract Foo: - content: String<100> \ No newline at end of file +struct tt1: + content: String<100> + +struct tt2: + subtt3: tt1 + +contract Foo2: + tt4: tt2 \ No newline at end of file diff --git a/tests/fixtures/features/nested_struct.fe b/tests/fixtures/features/nested_struct.fe new file mode 100644 index 0000000000..5409cadaa7 --- /dev/null +++ b/tests/fixtures/features/nested_struct.fe @@ -0,0 +1,13 @@ +struct tt1: + content: String<100> + +struct tt2: + subtt3: tt1 + +contract Foo: + tt4: tt2 + pub def set_item(): + self.tt4.subtt3.content = String<100>("Fooooo") + pub def get_some_string() -> String<100>: + self.set_item() + return self.tt4.subtt3.content.to_mem() \ No newline at end of file diff --git a/tests/src/features.rs b/tests/src/features.rs index b7688d8ed9..75c664e2fb 100644 --- a/tests/src/features.rs +++ b/tests/src/features.rs @@ -1207,6 +1207,20 @@ fn struct_with_string() { }) } +#[test] +fn nested_struct() { + with_executor(&|mut executor| { + let string_harness = deploy_contract(&mut executor, "nested_struct.fe", "Foo", &[]); + + string_harness.test_function( + &mut executor, + "get_some_string", + &[], + Some(&string_token("Fooooo")), + ); + }) +} + #[rstest( fixture_file, contract_name, From 086d06fa8d5111114f1166a4b62c6e656c15f1b8 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Thu, 24 Jun 2021 09:28:08 +0200 Subject: [PATCH 12/14] addded support for nested structs --- .gitignore | 1 + output/Foo/Foo.bin | 1 - output/Foo/Foo_abi.json | 19 ------------------- output/Foo2/Foo2.bin | 1 - output/Foo2/Foo2_abi.json | 19 ------------------- 5 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 output/Foo/Foo.bin delete mode 100644 output/Foo/Foo_abi.json delete mode 100644 output/Foo2/Foo2.bin delete mode 100644 output/Foo2/Foo2_abi.json diff --git a/.gitignore b/.gitignore index ff277f4686..9b17bd79fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea /target +/output **/*.rs.bk tarpaulin-report.html diff --git a/output/Foo/Foo.bin b/output/Foo/Foo.bin deleted file mode 100644 index 4a4a12f4da..0000000000 --- a/output/Foo/Foo.bin +++ /dev/null @@ -1 +0,0 @@ -61032a80610010600039806000f350fe60003560e01c63d794d55881146100205763e2a9de7481146100ee576100f8565b610028610103565b506100316101da565b6000805b60011561008757602082016084811015156100505750610087565b817e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc5088015483850152809250506001810190505b610035565b816084038260841415156100ce576100cd827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc508801548260031b610100031c8285870161024f565b5b5050506100db8151610235565b6040016100e78261026a565bf3506100f8565b6100f6610103565b505b5060006000f3610322565b6000600660008051905080151561011957602090505b60208082016000528282528261032461013185610216565b3960009250825b600115610189578184016084811015156101525750610189565b84840151827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155809450506001810190505b610138565b8360841415156101ce578383015191508360840360031b6101000382811c811b827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155505b50505050600090505b90565b600060005190508015156101ed57602090505b608481016000525b90565b6000600051905080151561020b57602090505b602081016000525b90565b6000600051905080151561022957602090505b8181016000525b919050565b6000601f19601f83011690505b919050565b60208152505b565b8160031b82820151811c8482610100031b178252505050505b565b600060008051905080151561027e57602090505b8091505061029261028d6101f8565b610247565b815161029c6101f8565b5281516102a881610216565b60005b6001156102dc57602080820184811015156102c75750506102dc565b8183880101518385015280925050505b6102ab565b808303818414151561030557610304602083880101518260031b610100031c8284860161024f565b5b50505061031a81601f19601f84011603610216565b50505b919050565bfe466f6f6f6f6f \ No newline at end of file diff --git a/output/Foo/Foo_abi.json b/output/Foo/Foo_abi.json deleted file mode 100644 index e551ea7dfe..0000000000 --- a/output/Foo/Foo_abi.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "name": "set_item", - "type": "function", - "inputs": [], - "outputs": [] - }, - { - "name": "get_some_string", - "type": "function", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "string" - } - ] - } -] \ No newline at end of file diff --git a/output/Foo2/Foo2.bin b/output/Foo2/Foo2.bin deleted file mode 100644 index 4a4a12f4da..0000000000 --- a/output/Foo2/Foo2.bin +++ /dev/null @@ -1 +0,0 @@ -61032a80610010600039806000f350fe60003560e01c63d794d55881146100205763e2a9de7481146100ee576100f8565b610028610103565b506100316101da565b6000805b60011561008757602082016084811015156100505750610087565b817e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc5088015483850152809250506001810190505b610035565b816084038260841415156100ce576100cd827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc508801548260031b610100031c8285870161024f565b5b5050506100db8151610235565b6040016100e78261026a565bf3506100f8565b6100f6610103565b505b5060006000f3610322565b6000600660008051905080151561011957602090505b60208082016000528282528261032461013185610216565b3960009250825b600115610189578184016084811015156101525750610189565b84840151827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155809450506001810190505b610138565b8360841415156101ce578383015191508360840360031b6101000382811c811b827e2242959533856f2a03f3c7d9431e28ef4fe5cb2a15038c37f1d76d35dc50880155505b50505050600090505b90565b600060005190508015156101ed57602090505b608481016000525b90565b6000600051905080151561020b57602090505b602081016000525b90565b6000600051905080151561022957602090505b8181016000525b919050565b6000601f19601f83011690505b919050565b60208152505b565b8160031b82820151811c8482610100031b178252505050505b565b600060008051905080151561027e57602090505b8091505061029261028d6101f8565b610247565b815161029c6101f8565b5281516102a881610216565b60005b6001156102dc57602080820184811015156102c75750506102dc565b8183880101518385015280925050505b6102ab565b808303818414151561030557610304602083880101518260031b610100031c8284860161024f565b5b50505061031a81601f19601f84011603610216565b50505b919050565bfe466f6f6f6f6f \ No newline at end of file diff --git a/output/Foo2/Foo2_abi.json b/output/Foo2/Foo2_abi.json deleted file mode 100644 index e551ea7dfe..0000000000 --- a/output/Foo2/Foo2_abi.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "name": "set_item", - "type": "function", - "inputs": [], - "outputs": [] - }, - { - "name": "get_some_string", - "type": "function", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "string" - } - ] - } -] \ No newline at end of file From e42924340e928f969dc4df8f4285f4640676869a Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Thu, 24 Jun 2021 10:14:31 +0200 Subject: [PATCH 13/14] . --- tests/fixtures/features/nested_tuple.fe | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/fixtures/features/nested_tuple.fe diff --git a/tests/fixtures/features/nested_tuple.fe b/tests/fixtures/features/nested_tuple.fe new file mode 100644 index 0000000000..19445d1ee2 --- /dev/null +++ b/tests/fixtures/features/nested_tuple.fe @@ -0,0 +1,3 @@ +contract Foo: + pub def bar(my_num: u256) -> (u256, (u256, u256)): + return (my_num, (my_num, my_num)) \ No newline at end of file From 3026ef1b9a7fe16d78e74c4add728ef4ec154437 Mon Sep 17 00:00:00 2001 From: Marek Owsikowski Date: Thu, 24 Jun 2021 12:53:31 +0200 Subject: [PATCH 14/14] nested stuff development --- Cargo.lock | 170 ++++++++++-------------- analyzer/src/traversal/structs.rs | 3 +- tests/fixtures/features/nested_tuple.fe | 9 +- tests/src/features.rs | 10 ++ 4 files changed, 88 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 827344a84c..5494c840e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 - [[package]] name = "aho-corasick" version = "0.7.18" @@ -47,12 +45,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" -[[package]] -name = "ascii" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" - [[package]] name = "atty" version = "0.2.14" @@ -192,9 +184,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byte-slice-cast" @@ -272,9 +264,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" dependencies = [ "jobserver", ] @@ -371,15 +363,12 @@ dependencies = [ [[package]] name = "combine" -version = "3.8.1" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +checksum = "a2d47c1b11006b87e492b53b313bb699ce60e16613c4dddaa91f8f7c220ab2fa" dependencies = [ - "ascii", - "byteorder", - "either", + "bytes", "memchr", - "unreachable", ] [[package]] @@ -407,9 +396,9 @@ dependencies = [ [[package]] name = "crates-index" -version = "0.16.5" +version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8921b4ef00013adbfeb803c4a23c5f311eaaaa06b38826e4f887aadbfd3f1d" +checksum = "30905ea06bd8553b9cbb9ed5f7cbdae18159cc83b8ee3c7ca3c90f0128aa89cc" dependencies = [ "git2", "glob", @@ -425,11 +414,10 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "autocfg", "cfg-if 1.0.0", "lazy_static", ] @@ -533,9 +521,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "env_logger" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", @@ -703,7 +691,7 @@ dependencies = [ "num-bigint", "num-traits", "rstest", - "semver 1.0.0", + "semver 1.0.3", "strum", "vec1", ] @@ -797,7 +785,7 @@ dependencies = [ "insta", "logos", "pretty_assertions", - "semver 1.0.0", + "semver 1.0.3", "serde", "unescape", "uuid", @@ -884,9 +872,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -897,9 +885,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.13.18" +version = "0.13.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b483c6c2145421099df1b4efd50e0f6205479a072199460eff852fa15e5603c7" +checksum = "d9831e983241f8c5591ed53f17d874833e2fa82cac2625f3888c50cbfe136cba" dependencies = [ "bitflags", "libc", @@ -918,9 +906,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" +checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" dependencies = [ "aho-corasick", "bstr", @@ -952,9 +940,9 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] @@ -1011,9 +999,9 @@ checksum = "1f7280c75fb2e2fc47080ec80ccc481376923acb04501957fc38f935c3de5088" [[package]] name = "ignore" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c" +checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" dependencies = [ "crossbeam-utils", "globset", @@ -1147,15 +1135,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.94" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libgit2-sys" -version = "0.12.19+1.1.0" +version = "0.12.21+1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f322155d574c8b9ebe991a04f6908bb49e68a79463338d24a43d6274cb6443e6" +checksum = "86271bacd72b2b9e854c3dcfb82efd538f15f870e4c11af66900effb462f6825" dependencies = [ "cc", "libc", @@ -1300,9 +1288,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -1318,15 +1306,15 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl-probe" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.62" +version = "0.9.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa52160d45fa2e7608d504b7c3a3355afed615e6d8b627a74458634ba21b69bd" +checksum = "7a7907e3bfa08bb85105209cdfcb6c63d109f8f6c1ed6ca318fff5c1853fbc1d" dependencies = [ "autocfg", "cc", @@ -1508,18 +1496,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] [[package]] name = "quick-error" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quote" @@ -1601,7 +1589,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", ] [[package]] @@ -1615,9 +1603,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -1628,15 +1616,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", "redox_syscall", ] [[package]] name = "regex" -version = "1.5.2" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efb2352a0f4d4b128f734b5c44c79ff80117351138733f12f982fe3e2b13343" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", @@ -1645,18 +1633,15 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", -] +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.24" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00efb87459ba4f6fb2169d20f68565555688e1250ee6825cdf6254f8b48fafb2" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rlp" @@ -1766,9 +1751,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76b5842e81eb9bbea19276a9dbbda22ac042532f390a67ab08b895617978abf3" +checksum = "5f3aac57ee7f3272d8395c6e4f502f434f0e289fcd62876f70daa008c20dcabe" [[package]] name = "semver-parser" @@ -1793,18 +1778,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ "proc-macro2", "quote", @@ -1956,9 +1941,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.71" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -1982,9 +1967,9 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" dependencies = [ "libc", "winapi", @@ -2073,9 +2058,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09391a441b373597cf0888d2b052dcf82c5be4fee05da3636ae30fb57aad8484" +checksum = "dbbdcf4f749dd33b1f1ea19b547bf789d87442ec40767d6015e5e2d39158d69a" dependencies = [ "chrono", "combine", @@ -2145,9 +2130,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] @@ -2170,20 +2155,11 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -dependencies = [ - "void", -] - [[package]] name = "url" -version = "2.2.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", @@ -2203,14 +2179,14 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", ] [[package]] name = "vcpkg" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vec1" @@ -2233,12 +2209,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "walkdir" version = "2.3.2" @@ -2354,9 +2324,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.50" +version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" +checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/analyzer/src/traversal/structs.rs b/analyzer/src/traversal/structs.rs index 5ca599ead7..2866049d8a 100644 --- a/analyzer/src/traversal/structs.rs +++ b/analyzer/src/traversal/structs.rs @@ -118,8 +118,7 @@ pub fn struct_def( } } Type::Tuple(tuple_typ) => { - if let Err(AlreadyDefined) = - val.add_field(&name.kind, &FixedSize::Tuple(tuple_typ)) + if let Err(AlreadyDefined) = val.add_field(&name.kind, &FixedSize::Tuple(tuple_typ)) { let first_definition = fields .iter() diff --git a/tests/fixtures/features/nested_tuple.fe b/tests/fixtures/features/nested_tuple.fe index 19445d1ee2..218b12fa1c 100644 --- a/tests/fixtures/features/nested_tuple.fe +++ b/tests/fixtures/features/nested_tuple.fe @@ -1,3 +1,8 @@ contract Foo: - pub def bar(my_num: u256) -> (u256, (u256, u256)): - return (my_num, (my_num, my_num)) \ No newline at end of file + tup: (u256, (u256, u256)) + pub def bar() -> u256: + self.tup= (1, (2, 3)) + return self.tup.item0 + pub def bar2() -> u256: + self.tup= (1, (2, 3)) + return self.tup.item1.item0 \ No newline at end of file diff --git a/tests/src/features.rs b/tests/src/features.rs index 87362858a1..5b55ba6810 100644 --- a/tests/src/features.rs +++ b/tests/src/features.rs @@ -1214,6 +1214,16 @@ fn nested_struct() { }) } +#[test] +fn nested_tuple() { + with_executor(&|mut executor| { + let harness = deploy_contract(&mut executor, "nested_tuple.fe", "Foo", &[]); + + harness.test_function(&mut executor, "bar", &[], Some(&uint_token(1))); + harness.test_function(&mut executor, "bar2", &[], Some(&uint_token(2))); + }) +} + #[rstest( fixture_file, contract_name,