-
Notifications
You must be signed in to change notification settings - Fork 4.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
Parse array type in conditional operator #31050
Conversation
@dotnet/roslyn-compiler, @gafter, please review. |
@@ -6262,7 +6245,7 @@ private enum ParseTypeMode | |||
while (this.IsPossibleRankAndDimensionSpecifier()) | |||
{ | |||
bool unused; | |||
var rank = this.ParseArrayRankSpecifier(mode == ParseTypeMode.ArrayCreation, expectSizes, allowQuestionToken: true, out unused); | |||
var rank = this.ParseArrayRankSpecifier(mode == ParseTypeMode.ArrayCreation, expectSizes, questionTokenModeOpt: mode, out unused); | |||
ranks.Add(rank); |
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.
This appears to apply to all levels of a multidimensional array. Shouldn't it apply only to the last? That is, shouldn't we allow var z = e is int[]?[] ? x : y;
(existing code)
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.
We allow e is int[]?[] ? x : y
and e is int[]?[]? ? x : y
. The issue was we were incorrectly parsing the first case by treating the ?
from the conditional as a nullable qualifier on the array type.
I've added tests for arrays of arrays. Thanks.
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 suspect there is an issue parsing multidimensional arrays.
@dotnet/roslyn-compiler, please review. |
@dotnet/roslyn-compiler please review. |
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.
} | ||
|
||
[Fact] | ||
public void ConditionalOperator_NotNullableArray() |
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.
ConditionalOperator_NotNullableArray [](start = 20, length = 36)
Would it be useful to test x is T?[] y
too? I'm afraid we disallow it, but I think we should allow it (seems useful).
Never mind, I think we allow it :-) Maybe still good to 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.
LGTM Thanks
@jaredpar What is the process for preview1 fixes? Thanks |
Since there is a workaround (add parentheses), I'm pushing this back to preview2 (updated label and re-targeted PR). FYI @jaredpar |
@jaredpar for approval for dev16.0-preview2. |
approved |
Customer scenario
Parse error reported for array types used in conditional operator expression:
x is T[] ? y : z
Bugs this fixes
Internal issue
Workarounds, if any
Modify code. For instance, add parentheses:
(x is T[]) ? y : z
Risk
Low.
Performance impact
None.
Is this a regression from a previous update?
Regression from C#7.3.
How was the bug found?
Customer report