GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — Add Type Inference for $_ / $PSItem in catch{ } blocks by vexx32 · Pull Request #8020 · PowerShell/PowerShell Conversation
|
|
Perhaps we need a test that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It would be cool to also add special handling for:
try {} catch [SomeSpecificException] { $_.Exception.<TAB> }
I realize this could be a bit messy though and I'm not sure it's commonly needed, so maybe it's not worth it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Can you expand upon that? As-is, the currently available logic handles this as you'd expect, completing the members for a generic exception object. Are there some exceptions with additional members we would want to try to detect from the exception type handed to the catch block itself? I'm not aware of any, but I'm sure there are probably some or could have some definitely in the case of custom exception types as well. Jason Shirk (@lzybkr) I don't think this would go quite in the same place on this code (would it?), so if you could point out where it would need to be added, I'll give it a whirl. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Rain Sallow (/u/ta11ow) (@vexx32) Please add test to demo that both cases work. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
9c1c9c3 to
586aae3
Compare
|
Jason Shirk (@lzybkr) Ilya (@iSazonov) Added tests. With Patrick Meinecke (@SeeminglyScience)'s help, also added in some type inference for typed catch blocks. He came up with the idea of a dummy generic Pretty happy with it! 😄 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0e24c59 to
dd61d52
Compare
|
Clever but simple, perfect. 👍👍👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
$res | Should -HaveCount 1
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you please address the comment?
Line 941 too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
All done. There are a few tests for other things that should probably use this as well, but I think that might be better left to another PR specifically for test revisions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add more catch-es.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Reformatted this for additional Test Cases with a variety of exception types.
Would you like me to add additional tests verifying that constructs like catch [type1], [type2] {} and subsequent catch blocks all work as expected?
Upon having this thought, I just went ahead and did it; figured it better be as robust as we can make it!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I meant:
"try {} catch [System.OverflowException] catch [System.TimeoutException] { $_.Exception }"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
See additional below tests. I suppose I only test catch [type] {$_.Exception} catch {$_.Exception} but if you want me to go through a couple stacks I'm game. :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Add dummy generic errorrecord class for type inference Add logic for inferring errorrecord/exception type Add tests for typed catch block inference Tidy Exception<E> class
Update generic type argument Update tests. (thanks @SeeminglyScience!)
d09fb29 to
b9eaea2
Compare
|
Appveyor caught something funky, don't think it was related. Rebased to restart it. Other than that... everything looks like it works as it ought. 😄 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Autocompletion gives no results for $PSItem / $_ in Catch blocks
There was an error while loading. Please reload this page.