-
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
feat: Update CFG checker to use new diagnostics #589
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf60207
fix: Use whole cell when storing source for functions in jupyter
mark-koch db5c493
fix: Take all spans into account when determining snippet alignment
mark-koch fd2b53a
feat: Update CFG checker to use new diagnostics
mark-koch 184b496
Make new line in test clearer
mark-koch d760742
Use list addition
mark-koch 6773c2b
Merge branch 'diag/linenos' into diag/cfg
mark-koch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
9 changes: 9 additions & 0 deletions
9
tests/diagnostics/snapshots/test_two_spans_different_lineno_lens.txt
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Error: Can't compare apples with oranges (at <unknown>:99:6) | ||
| | ||
97 | apple == orange | ||
98 | apple == orange | ||
99 | apple == orange | ||
| ^^ Comparison attempted here | ||
| | ||
100 | apple == orange | ||
| ----- This is an apple |
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,11 @@ | ||
Guppy compilation failed. Error in file $FILE:9 | ||
Error: Variable not defined (at $FILE:9:15) | ||
| | ||
7 | return z | ||
8 | else: | ||
9 | return z | ||
| ^ `z` might be undefined ... | ||
| | ||
6 | if x and (z := y + 1): | ||
| - ... if this expression is `False` | ||
|
||
7: return z | ||
8: else: | ||
9: return z | ||
^ | ||
GuppyError: Variable `z` is not defined on all control-flow paths. | ||
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,11 @@ | ||
Guppy compilation failed. Error in file $FILE:7 | ||
Error: Variable not defined (at $FILE:7:11) | ||
| | ||
5 | def foo(x: bool) -> int: | ||
6 | (y := 1) if x else (z := 2) | ||
7 | return z | ||
| ^ `z` might be undefined ... | ||
| | ||
6 | (y := 1) if x else (z := 2) | ||
| - ... if this expression is `True` | ||
|
||
5: def foo(x: bool) -> int: | ||
6: (y := 1) if x else (z := 2) | ||
7: return z | ||
^ | ||
GuppyError: Variable `z` is not defined on all control-flow paths. | ||
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,14 @@ | ||
Guppy compilation failed. Error in file $FILE:8 | ||
Error: Different types (at $FILE:8:11) | ||
| | ||
6 | y = 3 | ||
7 | (y := y + 1) if x else (y := True) | ||
8 | return y | ||
| ^ Variable `y` may refer to different types | ||
| | ||
7 | (y := y + 1) if x else (y := True) | ||
| - This is of type `int` | ||
| | ||
7 | (y := y + 1) if x else (y := True) | ||
| - This is of type `bool` | ||
|
||
6: y = 3 | ||
7: (y := y + 1) if x else (y := True) | ||
8: return y | ||
^ | ||
GuppyError: Variable `y` can refer to different types: `int` (at 7:5) vs `bool` (at 7:28) | ||
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,11 @@ | ||
Guppy compilation failed. Error in file $FILE:10 | ||
Error: Variable not defined (at $FILE:10:11) | ||
| | ||
8 | else: | ||
9 | z = 2 | ||
10 | return z | ||
| ^ `z` might be undefined ... | ||
| | ||
6 | if x: | ||
| - ... if this expression is `True` | ||
|
||
8: else: | ||
9: z = 2 | ||
10: return z | ||
^ | ||
GuppyError: Variable `z` is not defined on all control-flow paths. | ||
Guppy compilation failed due to 1 previous error |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
to my eye this looks like
if x False
rather thanif x and (z := y + 1) is False
...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.
I think the message is correct:
If
x
were true thenz
would be defined because of the walrus assignment even if the whole thing tends out to be false.If
x
is false, thenz
is not defined becauseand
short circuitsThere 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.
This is the test:
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.
that makes sense! thanks