-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Improve type inference and completions #16963
Improve type inference and completions #16963
Conversation
The |
If it is persistent on CI you can temporary add test code (in tests or Engine itself) :-) |
Looks like I was right about that test but now a different unrelated test is failing... |
But the test doesn't fail on other PRs or daily builds. |
These are the 3 runs I've had on this PR:
First run had the Enum out of range error due to bad RNG luck. The next 2 runs replaced that error with a different error The tabexpansion error that is there in all 3 runs is perfectly legit but like I said earlier it only exists because the test is designed around type inference not working. We need a different test to test if the completion code is correctly blocked from doing conversions. |
Yes, I see the same errors in other PRs. |
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
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.
Sorry for the long delay. Changes look good to me overall. Left a few comments.
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs
Show resolved
Hide resolved
@MartinGC94 Can you have a look at the failing test. |
@adityapatwardhan I would like some assistance with it. As far as I can tell, the test is failing because it thinks a conversion happened, when in reality it's just the type inference that is now working properly. I don't know how to build a new test that tests that conversion doesn't happen in constrained language mode. |
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
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.
LGTM.
@daxian-dbw I have no idea. I can't reproduce that on my system: -Edit: I misread what you wrote. |
@MartinGC94 Got it, thanks! |
I'm not sure. |
My point about I'm not sure if there is a test to cover the disallowing-conversion-to-intptr scenario. It would be better to add a test to cover just that. |
Could reflection be used for the test?
|
Can't we replace it with this test? |
Maybe. It depends on what should be tested. Based on the description for the SafeExprEvaluator descriptionThis class is very similar to the restricted language checker, but it is meant to allow more things, yet still be considered "safe", at least in the sense that tab completion can rely on it to not do bad things. The primary use is for intellisense where you don't want to run arbitrary code, but you do want to know the values of various expressions so you can get the members.I would assume the goal of the test was to be sure |
Does Besides, you cannot invoke the method |
Yes, see this: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L5802 and this: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L7392
No, as far as I can tell it's the compiler,
You sort of can. If you are in full language mode when you are defining
|
Yeah, |
…GC94/PowerShell into TypeInferenceImprovements
Alright, I've updated the test. Thanks for the assist @daxian-dbw |
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.
LGTM
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
@MartinGC94 Thank you for your contribution! |
🎉 Handy links: |
PR Summary
Fixes #15811
Fixes #9949
Fixes #11803
Fixes #15885
Fixes #17257
Improves the type inference in the following scenarios:
[System.Collections.Generic.IList[System.Text.StringBuilder]]$null)[0]
($var -as [ICloneable])
(Note it only works with type literals, it still doesn't work with other expression types)(0..10).ForEach{$_}
Improves tab completion in the following ways:
ForEach-Object -MemberName
([void]("")).
Fixes a failed assertion due to a missing null check.
PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).