diff --git a/sway-error/src/error.rs b/sway-error/src/error.rs index 0b957921be9..8e4147e01db 100644 --- a/sway-error/src/error.rs +++ b/sway-error/src/error.rs @@ -653,6 +653,8 @@ pub enum CompileError { ConfigTimeConstantNotALiteral { span: Span }, #[error("ref mut parameter not allowed for main()")] RefMutableNotAllowedInMain { param_name: Ident }, + #[error("returning raw_ptrs are not allowed for main()")] + PointerReturnNotAllowedInMain { span: Span }, } impl std::convert::From for CompileError { @@ -828,6 +830,7 @@ impl Spanned for CompileError { ConfigTimeConstantNotAConstDecl { span } => span.clone(), ConfigTimeConstantNotALiteral { span } => span.clone(), RefMutableNotAllowedInMain { param_name } => param_name.span(), + PointerReturnNotAllowedInMain { span } => span.clone(), } } } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/Forc.lock new file mode 100644 index 00000000000..0638ba9e991 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/Forc.lock @@ -0,0 +1,14 @@ +[[package]] +name = 'core' +source = 'path+from-root-51D3AF48CE04FAE0' +dependencies = [] + +[[package]] +name = 'raw_ptr_ret' +source = 'root' +dependencies = ['std'] + +[[package]] +name = 'std' +source = 'path+from-root-51D3AF48CE04FAE0' +dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/Forc.toml new file mode 100644 index 00000000000..8d7e5d05906 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "raw_ptr_ret" + +[dependencies] +std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/src/main.sw new file mode 100644 index 00000000000..d8a58c7de7d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/src/main.sw @@ -0,0 +1,6 @@ +script; + +fn main() -> raw_ptr { + let ptr = asm(r1) { r1: raw_ptr }; + ptr +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/test.toml new file mode 100644 index 00000000000..9b9236281e8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/raw_ptr_ret/test.toml @@ -0,0 +1,4 @@ +category = "fail" + +# check: fn main() -> raw_ptr { +# nextln: $()returning raw_ptrs are not allowed for main() diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/Forc.lock new file mode 100644 index 00000000000..fb42f43caf3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/Forc.lock @@ -0,0 +1,14 @@ +[[package]] +name = 'core' +source = 'path+from-root-D3556C503E51030C' +dependencies = [] + +[[package]] +name = 'std' +source = 'path+from-root-D3556C503E51030C' +dependencies = ['core'] + +[[package]] +name = 'vec_ret' +source = 'root' +dependencies = ['std'] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/Forc.toml new file mode 100644 index 00000000000..b9613943adf --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "vec_ret" + +[dependencies] +std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/src/main.sw new file mode 100644 index 00000000000..ed0aa9652e2 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/src/main.sw @@ -0,0 +1,8 @@ +script; + +use std::vec::Vec; + +fn main() -> Vec { + let vec = ~Vec::new(); + vec +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/test.toml new file mode 100644 index 00000000000..5fde6486495 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/raw_ptr/vec_ret/test.toml @@ -0,0 +1,4 @@ +category = "fail" + +# check: fn main() -> Vec { +# nextln: $()returning raw_ptrs are not allowed for main()