-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Collection expressions: synthesize single-element list type for IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T> #71147
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
670fe8a
WIP
c497c73
Make enumerator a nested type
alrz 8d16231
Misc
alrz 2ebc77a
Merge remote-tracking branch 'origin/main' into singleton
alrz 2de4a5e
Additional members
alrz 51f63a1
Misc
alrz 9b80f87
Add test
alrz eeec801
Fixup test
alrz 109644b
Whitespace
alrz 353b988
Whitespace
alrz 18e13a0
Whitespace
alrz c565c0c
Address feedback
alrz 2162208
Test missing types and members
alrz 01fff67
Add test
alrz 3775120
Reorder
alrz a5d6b93
Merge remote-tracking branch 'origin/main' into singleton
alrz 185f693
Formatting
alrz 58e9343
Fixup
alrz 8618a34
Merge remote-tracking branch 'origin/main' into singleton
alrz c741478
Use collection expressions
alrz 1cd42ff
Simplify
alrz ae02076
Check special types and members
alrz 0c427eb
Unnesting symbols because it's never done whether or not the type is …
alrz f0e6b62
Add missing missing member test
alrz b171018
Singleton -> SingleElement
alrz 93c560e
Merge remote-tracking branch 'origin/main' into singleton
alrz 687ca8c
Rename test methods
alrz 7710b76
Revert partial modifier
alrz 2105c5d
Rename variable
alrz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
49 changes: 49 additions & 0 deletions
49
...able/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListEnumeratorConstructor.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
| { | ||
| internal sealed class SynthesizedReadOnlyListEnumeratorConstructor : SynthesizedInstanceConstructor | ||
| { | ||
| internal SynthesizedReadOnlyListEnumeratorConstructor(SynthesizedReadOnlyListEnumeratorTypeSymbol containingType, TypeSymbol parameterType) : base(containingType) | ||
| { | ||
| Parameters = ImmutableArray.Create( | ||
| SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(parameterType), ordinal: 0, RefKind.None, "item")); | ||
| } | ||
|
|
||
| public override ImmutableArray<ParameterSymbol> Parameters { get; } | ||
|
|
||
| internal override bool SynthesizesLoweredBoundBody => true; | ||
|
|
||
| internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics) | ||
| { | ||
| SyntheticBoundNodeFactory f = new SyntheticBoundNodeFactory(this, this.GetNonNullSyntaxNode(), compilationState, diagnostics); | ||
| f.CurrentFunction = this; | ||
|
|
||
| try | ||
| { | ||
| var baseConstructor = ContainingType.BaseTypeNoUseSiteDiagnostics.InstanceConstructors.Single(); | ||
| var field = ContainingType.GetFieldsToEmit().First(); | ||
| var parameter = Parameters.Single(); | ||
|
|
||
| var block = f.Block( | ||
| // object..ctor(); | ||
| f.ExpressionStatement(f.Call(f.This(), baseConstructor)), | ||
| // _item = item; | ||
| f.Assignment(f.Field(f.This(), field), f.Parameter(parameter)), | ||
| // return; | ||
| f.Return()); | ||
| f.CloseMethod(block); | ||
| } | ||
| catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex) | ||
| { | ||
| diagnostics.Add(ex.Diagnostic); | ||
| f.CloseMethod(f.ThrowNull()); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
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 know you didn't name this variable, but... number of what? We need to rename this for clarity. If you want to do it now, go for it, if not we can do it in a follow up.
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.
Tried
lastSpreadIndexhere 57dc299 but that's more than a rename. I'll leave it out of this PR.