Skip to content

Commit c0ee238

Browse files
committed
Add tests
1 parent 89f87e8 commit c0ee238

42 files changed

Lines changed: 798 additions & 8 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/error/comprehension_errors/used_twice3.err

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ Error: Copy violation (at $FILE:13:12)
33
11 | @guppy
44
12 | def foo(qs: list[qubit] @owned) -> list[qubit]:
55
13 | return [q for q in qs for x in bar(q)]
6-
| ^ Variable `q` with non-copyable type `qubit` cannot be moved
7-
| ...
8-
9-
Note:
10-
|
11-
12 | def foo(qs: list[qubit] @owned) -> list[qubit]:
12-
13 | return [q for q in qs for x in bar(q)]
13-
| - Variable `q` already consumed here
6+
| ^ Variable `q` with non-copyable type `qubit` would be moved
7+
| multiple times when evaluating this comprehension
148

159
Guppy compilation failed due to 1 previous error
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Error: Copy violation (at $FILE:26:8)
2+
|
3+
24 | def test(s: MyStruct1 @owned) -> None:
4+
25 | use(s.x)
5+
26 | foo(s.x)
6+
| ^^^ Field `s.x` cannot be borrowed ...
7+
8+
Note:
9+
|
10+
24 | def test(s: MyStruct1 @owned) -> None:
11+
25 | use(s.x)
12+
| --- ... since field `s.x` with non-copyable type `MyStruct2` was
13+
| already consumed here
14+
15+
Guppy compilation failed due to 1 previous error
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from guppylang.decorator import guppy
2+
from guppylang.std.builtins import owned
3+
4+
5+
@guppy.struct(frozen=True)
6+
class MyStruct1:
7+
x: "MyStruct2"
8+
9+
10+
@guppy.struct(frozen=False)
11+
class MyStruct2:
12+
y: int
13+
14+
15+
@guppy.declare
16+
def foo(s: MyStruct2) -> None: ...
17+
18+
19+
@guppy.declare
20+
def use(s: MyStruct2 @owned) -> None: ...
21+
22+
23+
@guppy
24+
def test(s: MyStruct1 @owned) -> None:
25+
use(s.x)
26+
foo(s.x)
27+
28+
29+
test.compile()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Error: Copy violation (at $FILE:21:13)
2+
|
3+
19 | @guppy
4+
20 | def test(s: MyStruct1 @owned) -> None:
5+
21 | foo(s.x, s.x)
6+
| ^^^ Field `s.x` cannot be borrowed ...
7+
8+
Note:
9+
|
10+
20 | def test(s: MyStruct1 @owned) -> None:
11+
21 | foo(s.x, s.x)
12+
| --- ... since field `s.x` with non-copyable type `MyStruct2` was
13+
| already borrowed here
14+
15+
Guppy compilation failed due to 1 previous error
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from guppylang.decorator import guppy
2+
from guppylang.std.builtins import owned
3+
4+
5+
@guppy.struct(frozen=True)
6+
class MyStruct1:
7+
x: "MyStruct2"
8+
9+
10+
@guppy.struct(frozen=False)
11+
class MyStruct2:
12+
y: int
13+
14+
15+
@guppy.declare
16+
def foo(s: MyStruct2, t: MyStruct2) -> None: ...
17+
18+
19+
@guppy
20+
def test(s: MyStruct1 @owned) -> None:
21+
foo(s.x, s.x)
22+
23+
24+
test.compile()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Error: Subscript returned (at $FILE:12:11)
2+
|
3+
10 | @guppy
4+
11 | def foo(xs: array[MyStruct, 20]) -> MyStruct:
5+
12 | return xs[0]
6+
| ^^^^^ Cannot return a subscript of `xs` with non-copyable type
7+
| `array[MyStruct, 20]`
8+
9+
Note: Subscripts on non-copyable types are only allowed to be borrowed, not
10+
returned
11+
12+
Guppy compilation failed due to 1 previous error
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from guppylang.decorator import guppy
2+
from guppylang.std.builtins import array
3+
4+
5+
@guppy.struct(frozen=False)
6+
class MyStruct:
7+
x: int
8+
9+
10+
@guppy
11+
def foo(xs: array[MyStruct, 20]) -> MyStruct:
12+
return xs[0]
13+
14+
foo.compile()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Error: Copy violation (at $FILE:13:11)
2+
|
3+
11 | def foo(s: MyStruct @owned) -> MyStruct:
4+
12 | t = s
5+
13 | return s
6+
| ^ Variable `s` cannot be returned ...
7+
8+
Note:
9+
|
10+
11 | def foo(s: MyStruct @owned) -> MyStruct:
11+
12 | t = s
12+
| - ... since variable `s` with non-copyable type `MyStruct` was
13+
| already moved here
14+
15+
Guppy compilation failed due to 1 previous error
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from guppylang.decorator import guppy
2+
from guppylang.std.builtins import owned
3+
4+
5+
@guppy.struct(frozen=False)
6+
class MyStruct:
7+
x: int
8+
9+
10+
@guppy
11+
def foo(s: MyStruct @owned) -> MyStruct:
12+
t = s
13+
return s
14+
15+
16+
foo.compile()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Error: Copy violation (at $FILE:14:11)
2+
|
3+
12 | if b:
4+
13 | t = s
5+
14 | return s
6+
| ^ Field `s.x` cannot be returned ...
7+
8+
Note:
9+
|
10+
12 | if b:
11+
13 | t = s
12+
| - ... since variable `s` with non-copyable type `MyStruct` was
13+
| already moved here
14+
15+
Guppy compilation failed due to 1 previous error

0 commit comments

Comments
 (0)