From 1d04d08a6697e65913ff268ec6d1904c08db9fe2 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Fri, 24 Jan 2025 00:59:17 +1100 Subject: [PATCH] [tests] Add a test for invalid use of opaque resources --- tests/modules/opaque_resource_2.build | 9 +++++++++ tests/modules/opaque_resource_2.exp | 2 ++ tests/modules/opaque_resource_2.p | 28 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/modules/opaque_resource_2.build create mode 100644 tests/modules/opaque_resource_2.exp create mode 100644 tests/modules/opaque_resource_2.p diff --git a/tests/modules/opaque_resource_2.build b/tests/modules/opaque_resource_2.build new file mode 100644 index 00000000..f8082cc6 --- /dev/null +++ b/tests/modules/opaque_resource_2.build @@ -0,0 +1,9 @@ +# This is free and unencumbered software released into the public domain. +# See ../LICENSE.unlicense + +# PLZTEST type compile_failure + +[opaque_resource_2] +type = program +modules = [OpaqueResource2, OpaqueResource] + diff --git a/tests/modules/opaque_resource_2.exp b/tests/modules/opaque_resource_2.exp new file mode 100644 index 00000000..82dc15c0 --- /dev/null +++ b/tests/modules/opaque_resource_2.exp @@ -0,0 +1,2 @@ +opaque_resource_2.p:22: One or more resources needed for this call is + unavailable in this function diff --git a/tests/modules/opaque_resource_2.p b/tests/modules/opaque_resource_2.p new file mode 100644 index 00000000..be4981f2 --- /dev/null +++ b/tests/modules/opaque_resource_2.p @@ -0,0 +1,28 @@ +/* + * vim: ft=plasma + * This is free and unencumbered software released into the public domain. + * See ../LICENSE.unlicense + */ + +module OpaqueResource2 + +import OpaqueResource as OR + +entrypoint +func test() uses IO -> Int { + var s = test2!("Bob") + print!(s ++ "\n") + + return 0 +} + +func test2(s : String) uses OR.Res1 -> String { + // Calling test3 directly is illegal. although Res2 comes from Res1 this + // module doesn't know that because Res2 is opaque. + return test3!(s) +} + +func test3(s : String) uses OR.Res2 -> String { + return "Hi " ++ s ++ "." +} +