Skip to content

Commit

Permalink
[tests] Add a test for invalid use of opaque resources
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBone committed Jan 26, 2025
1 parent adec1e8 commit 1d04d08
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/modules/opaque_resource_2.build
Original file line number Diff line number Diff line change
@@ -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]

2 changes: 2 additions & 0 deletions tests/modules/opaque_resource_2.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
opaque_resource_2.p:22: One or more resources needed for this call is
unavailable in this function
28 changes: 28 additions & 0 deletions tests/modules/opaque_resource_2.p
Original file line number Diff line number Diff line change
@@ -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 ++ "."
}

0 comments on commit 1d04d08

Please sign in to comment.