-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Update function checker to use new diagnostics #590
Changes from all commits
bf60207
db5c493
772e3cf
184b496
d760742
b120118
6a22364
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Error: Can't compare apples with oranges (at <unknown>:99:6) | ||
| | ||
97 | apple == orange | ||
98 | apple == orange | ||
99 | apple == orange | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😁 |
||
| ^^ Comparison attempted here | ||
| | ||
100 | This apple is on another line | ||
| ----- This is an apple |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
Guppy compilation failed. Error in file $FILE:5 | ||
Error: Missing type annotation (at $FILE:5:17) | ||
| | ||
3 | | ||
4 | @compile_guppy | ||
5 | def foo(x: bool, y) -> int: | ||
| ^ Argument requires a type annotation | ||
|
||
3: @compile_guppy | ||
4: def foo(x: bool, y) -> int: | ||
^ | ||
GuppyError: Argument type must be annotated | ||
Guppy compilation failed due to 1 previous error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
Guppy compilation failed. Error in file $FILE:5 | ||
Error: Missing type annotation (at $FILE:5:0) | ||
| | ||
3 | | ||
4 | @compile_guppy | ||
5 | def foo(x: bool): | ||
| ^^^^^^^^^^^^^^^^^ | ||
6 | return x | ||
| ^^^^^^^^^^^^ Return type must be annotated | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it'd be nice if this could highlight the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, the Python AST doesn't give us a span for this. Taking the first line is also not valid since you could have weird stuff like def foo(
# No arguments, so no argument spans
) : # Closing paren on separate line + extra spaces before the colon |
||
3: @compile_guppy | ||
4: def foo(x: bool): | ||
^^^^^^^^^^^^^^^^^ | ||
GuppyError: Return type must be annotated | ||
Guppy compilation failed due to 1 previous error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
Guppy compilation failed. Error in file $FILE:5 | ||
Error: Missing type annotation (at $FILE:5:0) | ||
| | ||
3 | | ||
4 | @compile_guppy | ||
5 | def foo(): | ||
| ^^^^^^^^^^ | ||
6 | return | ||
| ^^^^^^^^^^ Return type must be annotated | ||
|
||
3: @compile_guppy | ||
4: def foo(): | ||
^^^^^^^^^^ | ||
GuppyError: Return type must be annotated. Try adding a `-> None` annotation. | ||
Help: Looks like `foo` doesn't return anything. Consider annotating it with `-> | ||
None`. | ||
|
||
Guppy compilation failed due to 1 previous error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
Guppy compilation failed. Error in file $FILE:5 | ||
Error: Missing type annotation (at $FILE:5:0) | ||
| | ||
3 | | ||
4 | @compile_guppy | ||
5 | def foo(): | ||
| ^^^^^^^^^^ | ||
| ... | ||
7 | return x | ||
| ^^^^^^^^^^^^^^^^ Return type must be annotated | ||
|
||
3: @compile_guppy | ||
4: def foo(): | ||
^^^^^^^^^^ | ||
GuppyError: Return type must be annotated. Try adding a `-> None` annotation. | ||
Help: Looks like `foo` doesn't return anything. Consider annotating it with `-> | ||
None`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 |
||
|
||
Guppy compilation failed due to 1 previous error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
Guppy compilation failed. Error in file $FILE:9 | ||
Error: Illegal assignment (at $FILE:9:8) | ||
| | ||
7 | | ||
8 | def bar() -> None: | ||
9 | y += 2 | ||
| ^^^^^^ Variable `y` may not be assigned to since `y` is captured | ||
| from an outer scope | ||
| | ||
6 | y = x + 1 | ||
| - `y` defined here | ||
|
||
7: | ||
8: def bar() -> None: | ||
9: y += 2 | ||
^^^^^^ | ||
GuppyError: Variable `y` defined in an outer scope (at 6:4) may not be assigned to | ||
Guppy compilation failed due to 1 previous error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
Guppy compilation failed. Error in file $FILE:11 | ||
Error: Illegal assignment (at $FILE:11:8) | ||
| | ||
9 | if 3 > 2: | ||
10 | z = y | ||
11 | y = 2 | ||
| ^^^^^ Variable `y` may not be assigned to since `y` is captured | ||
| from an outer scope | ||
| | ||
6 | y = x + 1 | ||
| - `y` defined here | ||
|
||
9: if 3 > 2: | ||
10: z = y | ||
11: y = 2 | ||
^^^^^ | ||
GuppyError: Variable `y` defined in an outer scope (at 6:4) may not be assigned to | ||
Guppy compilation failed due to 1 previous error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
Guppy compilation failed. Error in file $FILE:11 | ||
Error: Illegal assignment (at $FILE:11:12) | ||
| | ||
9 | | ||
10 | def baz() -> None: | ||
11 | y += 2 | ||
| ^^^^^^ Variable `y` may not be assigned to since `y` is captured | ||
| from an outer scope | ||
| | ||
6 | y = x + 1 | ||
| - `y` defined here | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it worth sorting the code spans based on the lines they appear in the file? it looks a little bit like this is one snippet and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's a good idea. However, we'll need to be careful because the grammar might break in some cases when reordering:
We'd need two version of the span labels depending on which order they are outputted. I created #608 to collect these improvement ideas |
||
9: | ||
10: def baz() -> None: | ||
11: y += 2 | ||
^^^^^^ | ||
GuppyError: Variable `y` defined in an outer scope (at 6:4) may not be assigned to | ||
Guppy compilation failed due to 1 previous error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool to detect overlapping spans and only print the
outer
once likebut that seems tricky...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good idea, Rust also does this! Added to #608