Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
ce442d7
Don't crash on null encoding
davidwengier Jan 13, 2025
ac187ef
Fix test
davidwengier Jan 14, 2025
6742621
Enable extract class and extract interface in LSP
JoeRobich Jan 11, 2025
3db737b
Add tests
JoeRobich Jan 11, 2025
4d5167b
Fixup
JoeRobich Jan 11, 2025
59a55dc
Add Kind property to CodeRefactoringProvider
JoeRobich Jan 14, 2025
4085cc0
Ensure we deploy the build hosts in Roslyn.VisualStudio.Setup
jasonmalinowski Jan 14, 2025
eb77f89
Opt in MS.CA.LS.Protocol into using optprof training data
dibarbet Jan 15, 2025
550c6f8
Change tests to launch the LanguageServer directly instead of hosting…
JoeRobich Jan 16, 2025
dfd0a2a
Turn off ngen for Microsoft.CodeAnalysis.Workspaces.MSBuild
jasonmalinowski Jan 16, 2025
a00b07a
Applied review feedback.
JoeRobich Jan 16, 2025
516f16a
Applied review feedback.
JoeRobich Jan 16, 2025
ee3f33b
Do not catch exceptions when disposing TestLspClient
JoeRobich Jan 17, 2025
bf43020
Push diagnostic suppression filtering flag to feature levels
CyrusNajmabadi Jan 22, 2025
728a8cc
Remove
CyrusNajmabadi Jan 22, 2025
5a1c0b2
Remove
CyrusNajmabadi Jan 22, 2025
e5b1721
Fix
CyrusNajmabadi Jan 22, 2025
25e37fb
Fix
CyrusNajmabadi Jan 22, 2025
9a4da49
Merge branch 'deleteExtension' into suppressedDiagnosticsFlag
CyrusNajmabadi Jan 22, 2025
4202e2d
Initial work to collapse comments at the end of a block
CyrusNajmabadi Jan 22, 2025
e296e09
Merge remote-tracking branch 'upstream/main' into suppressedDiagnosti…
CyrusNajmabadi Jan 22, 2025
af41d67
Use Assert.Empty
CyrusNajmabadi Jan 22, 2025
455d958
Merge remote-tracking branch 'upstream/main' into collapseComments
CyrusNajmabadi Jan 22, 2025
9cab90a
Use Assert.Empty (#76862)
CyrusNajmabadi Jan 22, 2025
4ad7f37
Update tests
CyrusNajmabadi Jan 22, 2025
ab3a37b
Update tests
CyrusNajmabadi Jan 22, 2025
5984584
Remove unused usings
CyrusNajmabadi Jan 22, 2025
30a0670
Simplify
CyrusNajmabadi Jan 22, 2025
e9fa4a6
Update doc
CyrusNajmabadi Jan 22, 2025
68810d9
Merge remote-tracking branch 'upstream/main' into suppressedDiagnosti…
CyrusNajmabadi Jan 22, 2025
3482093
move into loop
CyrusNajmabadi Jan 22, 2025
e0a72d0
Revert "Change PR Val builds to be unsigned (#76358)"
dibarbet Jan 22, 2025
5493cb9
Push diagnostic suppression filtering flag to feature levels (#76849)
CyrusNajmabadi Jan 22, 2025
dd63881
Initial work to collapse comments at the end of a block (#76865)
CyrusNajmabadi Jan 22, 2025
3dba762
Ensure we deploy the build hosts in Roslyn.VisualStudio.Setup (#76747)
jasonmalinowski Jan 22, 2025
c9185a0
Update formatOnType handler to support formatting on NewLine
JoeRobich Jan 23, 2025
1931cda
Revert "Change PR Val builds to be unsigned (#76358)" (#76866)
dibarbet Jan 23, 2025
3e87bdc
Review feedback
JoeRobich Jan 23, 2025
05dbe1c
Update comment
JoeRobich Jan 23, 2025
a4f3d29
Fix new document formatting (#76736)
davidwengier Jan 23, 2025
fc33f3d
Update formatOnType handler to support formatting on NewLine (#76876)
JoeRobich Jan 23, 2025
55e8ff7
Reduce work in ConversionsBase.AddUserDefinedConversionsToExplicitCan…
ToddGrun Jan 23, 2025
9739676
Add feature status of Partial Events and Constructors (#76879)
jjonescz Jan 23, 2025
d5cf1ea
Enc logging (#76042)
tmat Jan 23, 2025
7c1d17a
Record completion of "Simple lambda parameters with modifiers" featur…
CyrusNajmabadi Jan 23, 2025
cd505c9
Remove workaround for old version of SRM. (#76826)
teo-tsirpanis Jan 23, 2025
a8a7c6d
Opt in MS.CA.LS.Protocol into using optprof training data (#76768)
dibarbet Jan 23, 2025
6102e51
Do not offer the containing type when offering completion in teh base…
CyrusNajmabadi Jan 23, 2025
00977b1
Improve handling bad metadata in EE (#76878)
tmat Jan 23, 2025
6f29e13
On-the-fly-docs -- Add quota exceeded dialogue (#76877)
akhera99 Jan 23, 2025
2d1799f
Testing time (#76873)
jaredpar Jan 23, 2025
66ecfa6
Do not offer the containing type when offering completion in teh base…
CyrusNajmabadi Jan 23, 2025
3a8c9a8
Fix throw in generator comparer (#76769)
chsienki Jan 23, 2025
a30dc72
Convert to full prop should update 'field expressions
CyrusNajmabadi Jan 24, 2025
3f1e8c5
Update test
CyrusNajmabadi Jan 24, 2025
e76e4f9
in progress
CyrusNajmabadi Jan 24, 2025
b80df36
in progress
CyrusNajmabadi Jan 24, 2025
5ec15ee
in progress
CyrusNajmabadi Jan 24, 2025
c28f5ec
Support converting to a field backed property
CyrusNajmabadi Jan 24, 2025
b6dec28
Add docs
CyrusNajmabadi Jan 24, 2025
6645d87
Add teset cases
CyrusNajmabadi Jan 24, 2025
ce0844d
inline
CyrusNajmabadi Jan 24, 2025
d8a4dc4
Type safety
CyrusNajmabadi Jan 24, 2025
8e914f9
Speed up 'fix all' for 'use auto prop' by running in parallel
CyrusNajmabadi Jan 24, 2025
db8d8e9
Lock string
CyrusNajmabadi Jan 24, 2025
8d77f7f
Add error reporting
CyrusNajmabadi Jan 24, 2025
34a1414
Update src/Features/Core/Portable/UseAutoProperty/UseAutoPropertyFixA…
CyrusNajmabadi Jan 24, 2025
eb3b07f
Apply suggestions from code review
CyrusNajmabadi Jan 24, 2025
e9da589
Apply suggestions from code review
CyrusNajmabadi Jan 24, 2025
15f06a2
Apply suggestions from code review
CyrusNajmabadi Jan 24, 2025
42a384f
Update src/Features/Core/Portable/UseAutoProperty/UseAutoPropertyFixA…
CyrusNajmabadi Jan 24, 2025
7f21472
Tweak
CyrusNajmabadi Jan 24, 2025
a2943e3
Simplify
CyrusNajmabadi Jan 24, 2025
b1799b7
Simplify
CyrusNajmabadi Jan 24, 2025
8f4e4ff
Simplify
CyrusNajmabadi Jan 24, 2025
8777323
Simplify
CyrusNajmabadi Jan 24, 2025
d3bf94e
Add support for converting an auto-prop to a field-backed property. (…
CyrusNajmabadi Jan 24, 2025
52f788a
Use WithDocumentSyntaxRoots
CyrusNajmabadi Jan 24, 2025
6584966
Simplify
CyrusNajmabadi Jan 24, 2025
0a0a314
Add back intenral EE APIs used by the debugger until the debugger swi…
tmat Jan 24, 2025
a0f2e9d
Speed up 'fix all' for 'use auto prop' by running in parallel (#76905)
CyrusNajmabadi Jan 24, 2025
6010f58
DO not offer to convert typeof to nameof on a generic type
CyrusNajmabadi Jan 24, 2025
6c7df49
Update tests
CyrusNajmabadi Jan 24, 2025
7865b0c
Update tests
CyrusNajmabadi Jan 24, 2025
09a5602
Add generated semantic search API list (#73966)
tmat Jan 24, 2025
83fa931
Enable extract refactorings in LSP (#76718)
JoeRobich Jan 24, 2025
ff40252
Do not offer to convert typeof to nameof on a generic type (#76920)
CyrusNajmabadi Jan 24, 2025
ce6f1b0
Target test projects in Workspaces and Features layers to NetVSShared…
tmat Jan 25, 2025
f060a3f
Remove accidentally added files (#76924)
tmat Jan 25, 2025
096de0c
Always specify Image width/height for glyphs sourced from IGlyphService
sandyarmstrong Jan 26, 2025
7fa4d1d
Update rebuild test Semantic Search Refs exclusions (#76933)
tmat Jan 26, 2025
a87e115
Move merging of partial members to an earlier phase of members constr…
AlekseyTs Jan 27, 2025
010aaef
add configs for net9 branch
dibarbet Jan 27, 2025
7dfca1c
add configs for net9 branch (#76939)
dibarbet Jan 27, 2025
8422efb
Always specify Image width/height for glyphs sourced from IGlyphServi…
sandyarmstrong Jan 27, 2025
e566551
Reduce CPU costs under AnalyzerExecutor.ExecuteSyntaxNodeActions (#76…
ToddGrun Jan 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Roslyn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Expr
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Microsoft.CodeAnalysis.VisualBasic.ResultProvider.UnitTests", "src\ExpressionEvaluator\VisualBasic\Test\ResultProvider\Microsoft.CodeAnalysis.VisualBasic.ResultProvider.UnitTests.vbproj", "{ACE53515-482C-4C6A-E2D2-4242A687DFEE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ExpressionCompiler.Utilities", "src\ExpressionEvaluator\Core\Test\ExpressionCompiler\Microsoft.CodeAnalysis.ExpressionCompiler.Utilities.csproj", "{21B80A31-8FF9-4E3A-8403-AABD635AEED9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ExpressionCompiler.Test.Utilities", "src\ExpressionEvaluator\Core\Test\ExpressionCompiler\Microsoft.CodeAnalysis.ExpressionCompiler.Test.Utilities.csproj", "{21B80A31-8FF9-4E3A-8403-AABD635AEED9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ResultProvider.Utilities", "src\ExpressionEvaluator\Core\Test\ResultProvider\Microsoft.CodeAnalysis.ResultProvider.Utilities.csproj", "{ABDBAC1E-350E-4DC3-BB45-3504404545EE}"
EndProject
Expand Down
2 changes: 0 additions & 2 deletions azure-pipelines-pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ variables:
value: false
- name: Codeql.SkipTaskAutoInjection
value: true
- name: SignType
value: ''

# To retrieve OptProf data we need to authenticate to the VS drop storage.
# If the pipeline is running in DevDiv, the account has access to the VS drop storage.
Expand Down
3 changes: 2 additions & 1 deletion docs/Language Feature Status.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ efforts behind them.

| Feature | Branch | State | Developer | Reviewer | IDE Buddy | LDM Champ |
| ------- | ------ | ----- | --------- | -------- | --------- | --------- |
| [Partial Events and Constructors](https://github.com/dotnet/csharplang/issues/9058) | [features/PartialEventsCtors](https://github.com/dotnet/roslyn/tree/features/PartialEventsCtors) | [In Progress](https://github.com/dotnet/roslyn/issues/76859) | [jjonescz](https://github.com/jjonescz) | [cston](https://github.com/cston), [RikkiGibson](https://github.com/RikkiGibson) | | |
| Runtime Async | [features/runtime-async](https://github.com/dotnet/roslyn/tree/features/runtime-async) | [In Progress](https://github.com/dotnet/roslyn/issues/75960) | [333fred](https://github.com/333fred) | [jcouv](https://github.com/jcouv), [RikkiGibson](https://github.com/RikkiGibson) | | |
| [Simple lambda parameters with modifiers](https://github.com/dotnet/csharplang/blob/main/proposals/simple-lambda-parameters-with-modifiers.md) | [PR](https://github.com/dotnet/roslyn/pull/75400) | [In Progress](https://github.com/dotnet/roslyn/issues/76298) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [jjonescz](https://github.com/jjonescz), [cston](https://github.com/cston) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Null-conditional assignment](https://github.com/dotnet/csharplang/issues/6045) | [null-conditional-assignment](https://github.com/dotnet/roslyn/tree/features/null-conditional-assignment) | [In Progress](https://github.com/dotnet/roslyn/issues/75554) | [RikkiGibson](https://github.com/RikkiGibson) | [cston](https://github.com/cston), [jjonescz](https://github.com/jjonescz) | TBD | [RikkiGibson](https://github.com/RikkiGibson) |
| [Extensions](https://github.com/dotnet/csharplang/issues/8697) | [extensions](https://github.com/dotnet/roslyn/tree/features/extensions) | [In Progress](https://github.com/dotnet/roslyn/issues/76130) | [jcouv](https://github.com/jcouv), [AlekseyTs](https://github.com/AlekseyTs) | [jjonescz](https://github.com/jjonescz), TBD | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [MadsTorgersen](https://github.com/MadsTorgersen) |
| [Dictionary expressions](https://github.com/dotnet/csharplang/issues/8659) | [dictionary-expressions](https://github.com/dotnet/roslyn/tree/features/dictionary-expressions) | [In Progress](https://github.com/dotnet/roslyn/issues/76310) | [cston](https://github.com/cston), [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [333fred](https://github.com/333fred), [jcouv](https://github.com/jcouv) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [`field` keyword in properties](https://github.com/dotnet/csharplang/issues/140) | [field-keyword](https://github.com/dotnet/roslyn/tree/features/field-keyword) | [Merged into 17.12p3](https://github.com/dotnet/roslyn/issues/57012) | [Youssef1313](https://github.com/Youssef1313), [cston](https://github.com/cston) | [333fred](https://github.com/333fred), [RikkiGibson](https://github.com/RikkiGibson) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [First-class Span Types](https://github.com/dotnet/csharplang/issues/7905) | [FirstClassSpan](https://github.com/dotnet/roslyn/tree/features/FirstClassSpan) | [Merged into 17.13p1](https://github.com/dotnet/roslyn/issues/73445) | [jjonescz](https://github.com/jjonescz) | [cston](https://github.com/cston), [333fred](https://github.com/333fred) | | [333fred](https://github.com/333fred), [stephentoub](https://github.com/stephentoub) |
| [Unbound generic types in `nameof`](https://github.com/dotnet/csharplang/issues/8480) | [PR](https://github.com/dotnet/roslyn/pull/75368) | [Merged into 17.13p2](https://github.com/dotnet/roslyn/pull/75368) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [jcouv](https://github.com/jcouv), [AlekseyTs](https://github.com/AlekseyTs) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [String literals in data section as UTF8](https://github.com/dotnet/roslyn/blob/main/docs/features/string-literals-data-section.md) | [PR](https://github.com/dotnet/roslyn/pull/76036) | [Merged into 17.14p1](https://github.com/dotnet/roslyn/issues/76234) | [jjonescz](https://github.com/jjonescz) | [AlekseyTs](https://github.com/AlekseyTs), [cston](https://github.com/cston) | N/A | N/A |
| [Simple lambda parameters with modifiers](https://github.com/dotnet/csharplang/blob/main/proposals/simple-lambda-parameters-with-modifiers.md) | [PR](https://github.com/dotnet/roslyn/pull/75400) | [Merged into 17.14p1](https://github.com/dotnet/roslyn/pull/75400) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [jjonescz](https://github.com/jjonescz), [cston](https://github.com/cston) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |

# Working Set VB

Expand Down
15 changes: 0 additions & 15 deletions eng/Signing.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,4 @@
<FileSignInfo Include="Microsoft.VisualStudio.Threading.dll" CertificateName="MicrosoftSHA2" />
<FileSignInfo Include="StreamJsonRpc.dll" CertificateName="MicrosoftSHA2" />
</ItemGroup>

<!--
We do not intend to ship the artifacts produced for PR validation build so we can skip signing the artifacts.
-->
<Choose>
<When Condition="'$(PreReleaseVersionLabel)' == 'pr-validation' And '$(SignType)' == ''">
<ItemGroup>
<ItemsToSign Remove="@(ItemsToSign)" />
</ItemGroup>

<PropertyGroup>
<AllowEmptySignList>true</AllowEmptySignList>
</PropertyGroup>
</When>
</Choose>
</Project>
10 changes: 10 additions & 0 deletions eng/config/PublishData.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@
"insertionTitlePrefix": "[Do not merge, please close me]",
"vsMajorVersion": 17,
"insertionCreateDraftPR": false
},
"features/vscode_net9": {
"nugetKind": [
"Shipping",
"NonShipping"
],
"vsBranch": "main",
"insertionTitlePrefix": "[Do not merge, please close me]",
"vsMajorVersion": 17,
"insertionCreateDraftPR": true
}
}
}
3 changes: 2 additions & 1 deletion eng/test-rebuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ try {

# Semantic Search reference assemblies can't be reconstructed from source.
# The assemblies are not marked with ReferenceAssemblyAttribute attribute.
" --exclude net9.0\GeneratedRefAssemblies\Microsoft.CodeAnalysis.dll" +
" --exclude net8.0\GeneratedRefAssemblies\Microsoft.CodeAnalysis.dll" +
" --exclude net8.0\GeneratedRefAssemblies\Microsoft.CodeAnalysis.CSharp.dll" +

" --debugPath `"$ArtifactsDir/BuildValidator`"" +
" --sourcePath `"$RepoRoot/`"" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ internal sealed class CSharpConvertTypeOfToNameOfDiagnosticAnalyzer()
{
private static readonly string s_title = CSharpAnalyzersResources.typeof_can_be_converted_to_nameof;

protected override bool SupportsUnboundGenerics(ParseOptions options)
=> options.LanguageVersion().IsCSharp14OrAbove();

protected override bool IsValidTypeofAction(OperationAnalysisContext context)
{
var node = context.Operation.Syntax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Shared.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Shared.Extensions;
Expand Down Expand Up @@ -41,23 +42,9 @@ protected override bool SupportsReadOnlyProperties(Compilation compilation)
protected override bool SupportsPropertyInitializer(Compilation compilation)
=> compilation.LanguageVersion() >= LanguageVersion.CSharp6;

protected override bool SupportsFieldExpression(Compilation compilation)
=> compilation.LanguageVersion() >= LanguageVersion.Preview;

protected override ExpressionSyntax? GetFieldInitializer(VariableDeclaratorSyntax variable, CancellationToken cancellationToken)
=> variable.Initializer?.Value;

protected override bool ContainsFieldExpression(PropertyDeclarationSyntax propertyDeclaration, CancellationToken cancellationToken)
{
foreach (var node in propertyDeclaration.DescendantNodes())
{
if (node.IsKind(SyntaxKind.FieldExpression))
return true;
}

return false;
}

protected override void RecordIneligibleFieldLocations(
HashSet<string> fieldNames,
ConcurrentDictionary<IFieldSymbol, ConcurrentSet<SyntaxNode>> ineligibleFieldUsageIfOutsideProperty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,7 @@ class Goo<T>
{
void M()
{
_ = [|typeof(Goo<int>).Name|];
}
}
}
""",
FixedCode = """
class Test
{
class Goo<T>
{
void M()
{
_ = nameof(Goo<>);
_ = typeof(Goo<int>).Name;
}
}
}
Expand Down Expand Up @@ -321,19 +309,7 @@ class Goo<T>
{
void M()
{
_ = [|typeof(Goo<>).Name|];
}
}
}
""",
FixedCode = """
class Test
{
class Goo<T>
{
void M()
{
_ = nameof(Goo<>);
_ = typeof(Goo<>).Name;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7626,7 +7626,7 @@ public void M1()
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994328")]
public async Task TestDisposePatternWhenAdditionalUsingsAreIntroduced1()
{
#if NET9_0_OR_GREATER
#if NET
var extraUsing = """

using System.Diagnostics.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Shared.Extensions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand All @@ -14,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseAutoProperty;
public sealed partial class UseAutoPropertyTests
{
private static readonly ParseOptions CSharp13 = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp13);
private static readonly ParseOptions CSharp14 = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview);
private static readonly ParseOptions CSharp14 = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersionExtensions.CSharpNext);

[Fact]
public async Task TestNotInCSharp13()
Expand Down Expand Up @@ -1601,4 +1602,111 @@ void M()
}
""", new TestParameters(parseOptions: CSharp14));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76901")]
public async Task TestReadAndWrite()
{
await TestInRegularAndScript1Async(
"""
class C
{
private int [|_g|];

public int CustomGetter
{
get => _g < 0 ? 0 : _g; // Synthesized return value
set => _g = value;
}
}
""",
"""
class C
{
public int CustomGetter
{
get => field < 0 ? 0 : field; // Synthesized return value
set;
}
}
""", new TestParameters(parseOptions: CSharp14));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76901")]
public async Task TestContractCall()
{
await TestInRegularAndScript1Async(
"""
class C
{
private int [|_s|];

public int CustomSetter
{
get => _s;
set
{
Assumes.True(value >= 0); // Validation
_s = value;
}
}
}
""",
"""
class C
{
public int CustomSetter
{
get;
set
{
Assumes.True(value >= 0); // Validation
field = value;
}
}
}
""", new TestParameters(parseOptions: CSharp14));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76901")]
public async Task TestDelegateInvoke()
{
await TestInRegularAndScript1Async(
"""
using System;

class C
{
private int [|_s|];
public event Action<string> OnChanged;

public int ObservableProp
{
get => _s;
set
{
_s = value;
OnChanged.Invoke(nameof(ObservableProp));
}
}
}
""",
"""
using System;

class C
{
public event Action<string> OnChanged;

public int ObservableProp
{
get;
set
{
field = value;
OnChanged.Invoke(nameof(ObservableProp));
}
}
}
""", new TestParameters(parseOptions: CSharp14));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Shared.Extensions;
using Microsoft.CodeAnalysis.CSharp.UseImplicitlyTypedLambdaExpression;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand All @@ -18,7 +19,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseImplicitlyTypedLambd
[Trait(Traits.Feature, Traits.Features.CodeActionsUseImplicitObjectCreation)]
public sealed class UseImplicitlyTypedLambdaExpressionTests
{
private static readonly LanguageVersion CSharp14 = LanguageVersion.Preview;
private static readonly LanguageVersion CSharp14 = LanguageVersionExtensions.CSharpNext;

[Fact]
public async Task TestAssignedToObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ public override DiagnosticAnalyzerCategory GetAnalyzerCategory()

protected abstract bool IsValidTypeofAction(OperationAnalysisContext context);

protected abstract bool SupportsUnboundGenerics(ParseOptions options);

protected override void InitializeWorker(AnalysisContext context)
{
context.RegisterOperationAction(AnalyzeAction, OperationKind.TypeOf);
}
=> context.RegisterOperationAction(AnalyzeAction, OperationKind.TypeOf);

protected void AnalyzeAction(OperationAnalysisContext context)
{
Expand All @@ -47,7 +43,7 @@ protected void AnalyzeAction(OperationAnalysisContext context)

}

private bool IsValidOperation(IOperation operation)
private static bool IsValidOperation(IOperation operation)
{
// Cast to a typeof operation & check parent is a property reference and member access
var typeofOperation = (ITypeOfOperation)operation;
Expand All @@ -69,11 +65,10 @@ private bool IsValidOperation(IOperation operation)
if (typeofOperation.TypeOperand is not INamedTypeSymbol namedType)
return false;

// Non-generic types are always convertible. typeof(X).Name can always be converted to nameof(X)
if (namedType.TypeArguments.Length == 0)
return true;

// Generic types are convertible if the lang supports it. e.g. typeof(X<Y>).Name can be converted to nameof(X<>).
return SupportsUnboundGenerics(operation.Syntax.SyntaxTree.Options);
// Note: generic names like `typeof(List<int>)` are not convertible (since the name will be List`1). However,
// it's fine if an outer part of the name is generic (like `typeof(List<int>.Enumerator)`). as that will be
// convertible to `nameof(List<>.Enumerator)`. So we only need to check the type arguments directly on the type
// here, not on any containing types.
return namedType.TypeArguments.Length == 0;
}
}
Loading
Loading