[hackathon] Support nice syntax for ValueArray in most type contexts.#57286
Closed
VSadov wants to merge 2 commits intodotnet:demos/lowlevelhackathonfrom
Closed
[hackathon] Support nice syntax for ValueArray in most type contexts.#57286VSadov wants to merge 2 commits intodotnet:demos/lowlevelhackathonfrom
VSadov wants to merge 2 commits intodotnet:demos/lowlevelhackathonfrom
Conversation
Member
Author
|
@cston @stephentoub @davidwrighton - please take a look. |
VSadov
commented
Oct 20, 2021
| // https://github.com/dotnet/roslyn/issues/32464 | ||
| // Should capture invalid dimensions for use in `SemanticModel` and `IOperation`. | ||
| Error(diagnostics, ErrorCode.ERR_ArraySizeInDeclaration, rankSpecifier); | ||
| var size0 = dimension[0]; |
Member
Author
There was a problem hiding this comment.
Most interesting part of the change is here.
Here I intercept already parsed elementType[constExpr] and instead of giving a ERR_ArraySizeInDeclaration error, I bind it to a ValueArray type of corresponding length.
The rest is supporting changes, tests, etc...
Member
Author
cston
reviewed
Oct 23, 2021
| receiverOpt = null; | ||
| } | ||
| else if (symbol.ContainingType?.IsValueArrayType() == true) | ||
| else if (symbol.ContainingType?.IsValueArrayType(symbol.DeclaringCompilation ) == true) |
Contributor
cston
reviewed
Oct 23, 2021
| } | ||
| else | ||
| { | ||
| arrSize = sizeExpr.ConstantValue.UInt64Value; |
Contributor
cston
reviewed
Oct 23, 2021
| public static bool IsValueArrayType(this TypeSymbol type, CSharpCompilation compilation) | ||
| { | ||
| if (type.OriginalDefinition.SpecialType != SpecialType.System_ValueArray_TR) | ||
| if ((object)type.OriginalDefinition != compilation?.GetWellKnownType(WellKnownType.System_ValueArray_TR)) |
Contributor
4 tasks
Member
|
Marked as draft to make some room in our review queue. Ping when we should take another look. Thanks |
Member
|
@VSadov Is there a csharplang proposal to move forward with this new syntax? It looks nice indeed. |
Member
Author
|
this PR no longer needs to be open |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

This change allows writing code with struct arrays in terms of
Type[length]:@cston - I have also changed
ValueArray<T, Size>Roslyn classification fromSpecialTypetoWellKnownType.I do not have a strong opinion on which it should be, but
WellKnownis a lot easier to test in the absence of the actual type by providing a mock implementation.