-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow emission of diagnostics inside GuppyError (#553)
Closes #538. * Allow to pass a `Diagnostic` object to `GuppyError` instead of an error message * The old error reporting system remains untouched until we have migrated everything to the new diagnostics system * Adds a `TypeMismatchError` diagnostic as a test to ensure that the pipeline works
- Loading branch information
Showing
21 changed files
with
177 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:13 | ||
Error: Type mismatch (at $FILE:13:13) | ||
| | ||
11 | @guppy(module) | ||
12 | def main() -> None: | ||
13 | array(1, False) | ||
| ^^^^^ Expected expression of type `int`, got `bool` | ||
|
||
11: @guppy(module) | ||
12: def main() -> None: | ||
13: array(1, False) | ||
^^^^^ | ||
GuppyTypeError: Expected expression of type `int`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Guppy compilation failed. Error in file $FILE:19 | ||
Error: Type mismatch (at $FILE:19:11) | ||
| | ||
17 | @guppy(module) | ||
18 | def test() -> Callable[[qubit @owned], qubit]: | ||
19 | return foo | ||
| ^^^ Expected return value of type `qubit @owned -> qubit`, got | ||
| `qubit -> qubit` | ||
|
||
17: @guppy(module) | ||
18: def test() -> Callable[[qubit @owned], qubit]: | ||
19: return foo | ||
^^^ | ||
GuppyTypeError: Expected return value of type `qubit @owned -> qubit`, got `qubit -> qubit` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:6 | ||
Error: Type mismatch (at $FILE:6:11) | ||
| | ||
4 | @guppy | ||
5 | def foo() -> int: | ||
6 | return 1.0 | ||
| ^^^ Expected return value of type `int`, got `float` | ||
|
||
4: @guppy | ||
5: def foo() -> int: | ||
6: return 1.0 | ||
^^^ | ||
GuppyTypeError: Expected return value of type `int`, got `float` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:17 | ||
Error: Type mismatch (at $FILE:17:11) | ||
| | ||
15 | @guppy(module) | ||
16 | def main(x: bool, y: tuple[bool]) -> None: | ||
17 | foo(x, y) | ||
| ^ Expected argument of type `bool`, got `(bool)` | ||
|
||
15: @guppy(module) | ||
16: def main(x: bool, y: tuple[bool]) -> None: | ||
17: foo(x, y) | ||
^ | ||
GuppyTypeError: Expected argument of type `bool`, got `(bool)` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:17 | ||
Error: Type mismatch (at $FILE:17:8) | ||
| | ||
15 | @guppy(module) | ||
16 | def main() -> None: | ||
17 | foo(False) | ||
| ^^^^^ Expected argument of type `(?T, ?T)`, got `bool` | ||
|
||
15: @guppy(module) | ||
16: def main() -> None: | ||
17: foo(False) | ||
^^^^^ | ||
GuppyTypeError: Expected argument of type `(?T, ?T)`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Guppy compilation failed. Error in file $FILE:17 | ||
Error: Type mismatch (at $FILE:17:11) | ||
| | ||
15 | @guppy(module) | ||
16 | def main(x: array[int, 42], y: array[int, 43]) -> None: | ||
17 | foo(x, y) | ||
| ^ Expected argument of type `array[int, 42]`, got `array[int, | ||
| 43]` | ||
|
||
15: @guppy(module) | ||
16: def main(x: array[int, 42], y: array[int, 43]) -> None: | ||
17: foo(x, y) | ||
^ | ||
GuppyTypeError: Expected argument of type `array[int, 42]`, got `array[int, 43]` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:17 | ||
Error: Type mismatch (at $FILE:17:14) | ||
| | ||
15 | @guppy(module) | ||
16 | def main(x: bool) -> None: | ||
17 | y: None = foo(x) | ||
| ^^^^^^ Expected expression of type `None`, got `bool` | ||
|
||
15: @guppy(module) | ||
16: def main(x: bool) -> None: | ||
17: y: None = foo(x) | ||
^^^^^^ | ||
GuppyTypeError: Expected expression of type `None`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:17 | ||
Error: Type mismatch (at $FILE:17:14) | ||
| | ||
15 | @guppy(module) | ||
16 | def main(x: bool) -> None: | ||
17 | y: None = foo(foo(foo(x))) | ||
| ^^^^^^^^^^^^^^^^ Expected expression of type `None`, got `bool` | ||
|
||
15: @guppy(module) | ||
16: def main(x: bool) -> None: | ||
17: y: None = foo(foo(foo(x))) | ||
^^^^^^^^^^^^^^^^ | ||
GuppyTypeError: Expected expression of type `None`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:17 | ||
Error: Type mismatch (at $FILE:17:14) | ||
| | ||
15 | @guppy(module) | ||
16 | def main() -> None: | ||
17 | x: bool = foo() | ||
| ^^^^^ Expected expression of type `bool`, got `(?T, ?T)` | ||
|
||
15: @guppy(module) | ||
16: def main() -> None: | ||
17: x: bool = foo() | ||
^^^^^ | ||
GuppyTypeError: Expected expression of type `bool`, got `(?T, ?T)` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:15 | ||
Error: Type mismatch (at $FILE:15:13) | ||
| | ||
13 | @guppy(module) | ||
14 | def main() -> None: | ||
15 | MyStruct(0) | ||
| ^ Expected argument of type `(int, int)`, got `int` | ||
|
||
13: @guppy(module) | ||
14: def main() -> None: | ||
15: MyStruct(0) | ||
^ | ||
GuppyTypeError: Expected argument of type `(int, int)`, got `int` | ||
Guppy compilation failed due to 1 previous error |
13 changes: 7 additions & 6 deletions
13
tests/error/struct_errors/constructor_arg_mismatch_poly.err
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:19 | ||
Error: Type mismatch (at $FILE:19:16) | ||
| | ||
17 | @guppy(module) | ||
18 | def main() -> None: | ||
19 | MyStruct(0, False) | ||
| ^^^^^ Expected argument of type `int`, got `bool` | ||
|
||
17: @guppy(module) | ||
18: def main() -> None: | ||
19: MyStruct(0, False) | ||
^^^^^ | ||
GuppyTypeError: Expected argument of type `int`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:12 | ||
Error: Type mismatch (at $FILE:12:26) | ||
| | ||
10 | @guppy(module) | ||
11 | def main() -> int: | ||
12 | return (foo, foo)(42, False) | ||
| ^^^^^ Expected argument of type `int`, got `bool` | ||
|
||
10: @guppy(module) | ||
11: def main() -> int: | ||
12: return (foo, foo)(42, False) | ||
^^^^^ | ||
GuppyTypeError: Expected argument of type `int`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:6 | ||
Error: Type mismatch (at $FILE:6:15) | ||
| | ||
4 | @compile_guppy | ||
5 | def foo(x: int) -> int: | ||
6 | return foo(True) | ||
| ^^^^ Expected argument of type `int`, got `bool` | ||
|
||
4: @compile_guppy | ||
5: def foo(x: int) -> int: | ||
6: return foo(True) | ||
^^^^ | ||
GuppyTypeError: Expected argument of type `int`, got `bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Guppy compilation failed. Error in file $FILE:11 | ||
Error: Type mismatch (at $FILE:11:11) | ||
| | ||
9 | return x > 0 | ||
10 | | ||
11 | return bar | ||
| ^^^ Expected return value of type `int -> int`, got `int -> | ||
| bool` | ||
|
||
9: return x > 0 | ||
10: | ||
11: return bar | ||
^^^ | ||
GuppyTypeError: Expected return value of type `int -> int`, got `int -> bool` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:11 | ||
Error: Type mismatch (at $FILE:11:15) | ||
| | ||
9 | return f() | ||
10 | | ||
11 | return bar(foo) | ||
| ^^^ Expected argument of type `() -> int`, got `int -> int` | ||
|
||
9: return f() | ||
10: | ||
11: return bar(foo) | ||
^^^ | ||
GuppyTypeError: Expected argument of type `() -> int`, got `int -> int` | ||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:11 | ||
Error: Type mismatch (at $FILE:11:15) | ||
| | ||
9 | return f(42) | ||
10 | | ||
11 | return bar(foo) | ||
| ^^^ Expected argument of type `int -> bool`, got `int -> int` | ||
|
||
9: return f(42) | ||
10: | ||
11: return bar(foo) | ||
^^^ | ||
GuppyTypeError: Expected argument of type `int -> bool`, got `int -> int` | ||
Guppy compilation failed due to 1 previous error |
Oops, something went wrong.