Enable tests and update features to support new language changes around patterns.#45762
Enable tests and update features to support new language changes around patterns.#457625 commits merged intodotnet:masterfrom
Conversation
| [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | ||
| public async Task TestForSwitchCase_SemanticCheck_NotAfterPredefinedType() => | ||
| await VerifyAbsenceAsync(AddInsideMethod(@"switch (new object()) { case int $$ }")); | ||
| await VerifyKeywordAsync(AddInsideMethod(@"switch (new object()) { case int $$ }")); |
There was a problem hiding this comment.
this is the newly allowed behavior. i.e. you can say case int when ... instead of case int i when ...
| [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | ||
| public async Task TestForSwitchCase_SemanticCheck_AfterLocalConstantVar() => | ||
| await VerifyKeywordAsync(AddInsideMethod(@"const object var = null; switch (new object()) { case var $$ }")); | ||
| await VerifyAbsenceAsync(AddInsideMethod(@"const object var = null; switch (new object()) { case var $$ }")); |
There was a problem hiding this comment.
i specifically regressed this behavior because:
- teh logic to support it was such a pain to keep
- supporting users explicitly namign things like
varis explicitly carved out as something we do not cater for in the IDE.
| { | ||
| return context.IsCatchFilterContext || | ||
| (IsAfterCompleteExpressionOrPatternInCaseLabel(context, out var expressionOrPattern) && | ||
| !IsTypeName(expressionOrPattern, context.SemanticModel, cancellationToken)); |
There was a problem hiding this comment.
all the logic removed was just jumping through hoops to try to prevent when from showing up too much and to support case var when. i.e. having var not be a variable-pattern, but rather some sort of constant pattern. It was intefering with supporting real cases simply and just added too much complexity for a scenario we do not consider important. So it's all been removed and replaced with something much simpler and easier to maintain.
| } | ||
|
|
||
| // Never show `when` after `var` in a pattern. It's virtually always going to be unhelpful as the user is | ||
| // far more likely to be writing `case var someName...` rather than typing `cae var when...` (in the case |
| } | ||
| "; | ||
| await VerifyNoItemsExistAsync(markup); | ||
| await VerifyItemExistsAsync(markup, "P1"); |
There was a problem hiding this comment.
Just trying to better understand, why was this file changed? Does it have to do with the when keyword or is it something separate?
There was a problem hiding this comment.
this used to be illegal in C# but became legal in C# 9.0. i.e. you can continually nest recursive patterns within each other :)
|
|
||
| [Fact(Skip = "https://github.com/dotnet/roslyn/issues/40015"), Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | ||
| [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | ||
| public async Task TestForSwitchCase_SemanticCheck_NotAfterPredefinedType_BeforeBreak() => |
There was a problem hiding this comment.
Update the names of the tests to no longer say "Not" when we expect it
| public async Task TestForSwitchCase_SemanticCheck_AfterTypeAliasAndFieldConstantVar() | ||
| { | ||
| await VerifyKeywordAsync(@" | ||
| await VerifyAbsenceAsync(@" |
There was a problem hiding this comment.
Update test names to have "Not"
No description provided.