Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ static IEnumerable<CollectionElementSyntax> GetMatchElements(ImmutableArray<Coll
}
else if (match.Node is ArgumentListSyntax argumentList)
{
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
yield return WithElement(argumentList.WithoutTrivia());
#pragma warning restore RSEXPERIMENTAL006
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ CollectionExpressionSyntax CreateSingleElementCollection(CollectionMatch<TMatchN
CollectionElementSyntax CreateElement(CollectionMatch<TMatchNode> match)
{
if (match.Node is ArgumentListSyntax argumentList)
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
return WithElement(argumentList.WithoutTrivia());
#pragma warning restore RSEXPERIMENTAL006

var expression = (ExpressionSyntax)(object)match.Node;
return match.UseSpread
Expand Down Expand Up @@ -592,7 +594,9 @@ IEnumerable<CollectionElementSyntax> CreateElements(
}
else if (node is ArgumentListSyntax argumentList)
{
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
yield return WithElement(argumentList.WithoutTrivia());
#pragma warning restore RSEXPERIMENTAL006
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5346,7 +5346,9 @@ private BoundExpression BindCollectionExpression(CollectionExpressionSyntax synt
var builder = ArrayBuilder<BoundNode>.GetInstance(syntax.Elements.Count);
foreach (var element in syntax.Elements)
{
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
if (element is WithElementSyntax withElementSyntax)
#pragma warning restore RSEXPERIMENTAL006
{
MessageID.IDS_FeatureCollectionExpressionArguments.CheckFeatureAvailability(diagnostics, syntax, withElementSyntax.WithKeyword.GetLocation());

Expand Down Expand Up @@ -5439,7 +5441,9 @@ static BoundNode bindSpreadElement(SpreadElementSyntax syntax, BindingDiagnostic
static (BoundUnconvertedWithElement? withElement, BoundBadExpression? badExpression) bindWithElement(
Binder @this,
CollectionExpressionSyntax syntax,
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
WithElementSyntax withElementSyntax,
#pragma warning restore RSEXPERIMENTAL006
BindingDiagnosticBag diagnostics)
{
// Report a withElement that is not first. Note: for the purposes of error recovery and diagnostics
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public SimpleNameSyntax? InterceptableNameSyntax
this.Syntax is InvocationExpressionSyntax
or ConstructorInitializerSyntax
or PrimaryConstructorBaseTypeSyntax { ArgumentList: { } }
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
or WithElementSyntax
#pragma warning restore RSEXPERIMENTAL006
or CollectionExpressionSyntax,
$"Unexpected syntax kind for BoundCall: {this.Syntax.Kind()}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Collections;
Expand Down Expand Up @@ -122,7 +123,9 @@ internal static bool CanGetSemanticInfo(CSharpSyntaxNode node, bool allowNamedAr
(node is ExpressionSyntax && (isSpeculative || allowNamedArgumentName || !SyntaxFacts.IsNamedArgumentName(node))) ||
(node is ConstructorInitializerSyntax
or PrimaryConstructorBaseTypeSyntax
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
Copy link
Member

@jcouv jcouv Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead suppress this warning globally within the compiler codebase?
That would avoid sprinkling of suppressions and would make it much easier for the PR that adds a new LangVer #Closed

Copy link
Member Author

@333fred 333fred Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The non-suppressed global warning helped me catch manually-written public APIs that also need to be marked as Experimental. We could consider suppressing it in test projects/IDE, but I very much do not think we should do so in the main compiler codebase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-suppressed global warning helped me catch manually-written public APIs that also need to be marked as Experimental.

How exactly did that help you?

or WithElementSyntax
#pragma warning restore RSEXPERIMENTAL006
or AttributeSyntax
or CrefSyntax);
}
Expand Down Expand Up @@ -657,6 +660,7 @@ private static SymbolInfo GetSymbolInfoFromSymbolOrNone(ITypeSymbol type)
/// <summary>
/// Returns what symbol(s), if any, the given 'with(...)' element syntax bound to in the program.
/// </summary>
[Experimental(RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = "https://github.com/dotnet/roslyn/issues/80613")]
internal SymbolInfo GetSymbolInfo(WithElementSyntax withElement, CancellationToken cancellationToken = default(CancellationToken))
{
CheckSyntaxNode(withElement);
Expand Down Expand Up @@ -5021,8 +5025,10 @@ private SymbolInfo GetSymbolInfoFromNode(SyntaxNode node, CancellationToken canc
return this.GetSymbolInfo(orderingSyntax, cancellationToken);
case PositionalPatternClauseSyntax ppcSyntax:
return this.GetSymbolInfo(ppcSyntax, cancellationToken);
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
case WithElementSyntax withElement:
return this.GetSymbolInfo(withElement, cancellationToken);
#pragma warning restore RSEXPERIMENTAL006
}

return SymbolInfo.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,9 @@ protected internal virtual CSharpSyntaxNode GetBindableSyntaxNode(CSharpSyntaxNo
!(node is JoinIntoClauseSyntax) &&
!(node is QueryContinuationSyntax) &&
!(node is ConstructorInitializerSyntax) &&
#pragma warning disable RSEXPERIMENTAL006 // With Element: https://github.com/dotnet/roslyn/issues/80613
!(node is WithElementSyntax) &&
#pragma warning restore RSEXPERIMENTAL006
!(node is PrimaryConstructorBaseTypeSyntax) &&
!(node is ArrowExpressionClauseSyntax) &&
!(node is PatternSyntax))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// <auto-generated />

#nullable enable
#pragma warning disable RSEXPERIMENTAL006 // Preview language feature API

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// <auto-generated />

#nullable enable
#pragma warning disable RSEXPERIMENTAL006 // Preview language feature API

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -229,6 +230,7 @@ public partial class CSharpSyntaxVisitor<TResult>
public virtual TResult? VisitSpreadElement(SpreadElementSyntax node) => this.DefaultVisit(node);

/// <summary>Called when the visitor visits a WithElementSyntax node.</summary>
[Experimental(global::Microsoft.CodeAnalysis.RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = @"https://github.com/dotnet/roslyn/issues/80613")]
public virtual TResult? VisitWithElement(WithElementSyntax node) => this.DefaultVisit(node);

/// <summary>Called when the visitor visits a QueryExpressionSyntax node.</summary>
Expand Down Expand Up @@ -976,6 +978,7 @@ public partial class CSharpSyntaxVisitor
public virtual void VisitSpreadElement(SpreadElementSyntax node) => this.DefaultVisit(node);

/// <summary>Called when the visitor visits a WithElementSyntax node.</summary>
[Experimental(global::Microsoft.CodeAnalysis.RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = @"https://github.com/dotnet/roslyn/issues/80613")]
public virtual void VisitWithElement(WithElementSyntax node) => this.DefaultVisit(node);

/// <summary>Called when the visitor visits a QueryExpressionSyntax node.</summary>
Expand Down Expand Up @@ -1722,6 +1725,7 @@ public partial class CSharpSyntaxRewriter : CSharpSyntaxVisitor<SyntaxNode?>
public override SyntaxNode? VisitSpreadElement(SpreadElementSyntax node)
=> node.Update(VisitToken(node.OperatorToken), (ExpressionSyntax?)Visit(node.Expression) ?? throw new ArgumentNullException("expression"));

[Experimental(global::Microsoft.CodeAnalysis.RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = @"https://github.com/dotnet/roslyn/issues/80613")]
public override SyntaxNode? VisitWithElement(WithElementSyntax node)
=> node.Update(VisitToken(node.WithKeyword), (ArgumentListSyntax?)Visit(node.ArgumentList) ?? throw new ArgumentNullException("argumentList"));

Expand Down Expand Up @@ -3446,6 +3450,7 @@ public static SpreadElementSyntax SpreadElement(ExpressionSyntax expression)
=> SyntaxFactory.SpreadElement(SyntaxFactory.Token(SyntaxKind.DotDotToken), expression);

/// <summary>Creates a new WithElementSyntax instance.</summary>
[Experimental(global::Microsoft.CodeAnalysis.RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = @"https://github.com/dotnet/roslyn/issues/80613")]
public static WithElementSyntax WithElement(SyntaxToken withKeyword, ArgumentListSyntax argumentList)
{
if (withKeyword.Kind() != SyntaxKind.WithKeyword) throw new ArgumentException(nameof(withKeyword));
Expand All @@ -3454,6 +3459,7 @@ public static WithElementSyntax WithElement(SyntaxToken withKeyword, ArgumentLis
}

/// <summary>Creates a new WithElementSyntax instance.</summary>
[Experimental(global::Microsoft.CodeAnalysis.RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = @"https://github.com/dotnet/roslyn/issues/80613")]
public static WithElementSyntax WithElement(ArgumentListSyntax? argumentList = default)
=> SyntaxFactory.WithElement(SyntaxFactory.Token(SyntaxKind.WithKeyword), argumentList ?? SyntaxFactory.ArgumentList());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// <auto-generated />

#nullable enable
#pragma warning disable RSEXPERIMENTAL006 // Preview language feature API

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -4279,6 +4280,7 @@ public SpreadElementSyntax Update(SyntaxToken operatorToken, ExpressionSyntax ex
/// <item><description><see cref="SyntaxKind.WithElement"/></description></item>
/// </list>
/// </remarks>
[Experimental(global::Microsoft.CodeAnalysis.RoslynExperiments.PreviewLanguageFeatureApi, UrlFormat = @"https://github.com/dotnet/roslyn/issues/80613")]
public sealed partial class WithElementSyntax : CollectionElementSyntax
{
private ArgumentListSyntax? argumentList;
Expand Down
28 changes: 14 additions & 14 deletions src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ Microsoft.CodeAnalysis.CSharp.ForEachStatementInfo.MoveNextAwaitableInfo.get ->
Microsoft.CodeAnalysis.CSharp.SyntaxKind.WithElement = 9081 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetAwaitExpressionInfo(this Microsoft.CodeAnalysis.SemanticModel? semanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.LocalDeclarationStatementSyntax! awaitUsingDeclaration) -> Microsoft.CodeAnalysis.CSharp.AwaitExpressionInfo
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetAwaitExpressionInfo(this Microsoft.CodeAnalysis.SemanticModel? semanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.UsingStatementSyntax! awaitUsingStatement) -> Microsoft.CodeAnalysis.CSharp.AwaitExpressionInfo
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.AddArgumentListArguments(params Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax![]! items) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax!
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken withKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithArgumentList(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken
Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithWithKeyword(Microsoft.CodeAnalysis.SyntaxToken withKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> Microsoft.CodeAnalysis.SyntaxNode?
override Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> void
override Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Accept<TResult>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult>! visitor) -> TResult?
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WithElement(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax? argumentList = null) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WithElement(Microsoft.CodeAnalysis.SyntaxToken withKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> void
virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult>.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> TResult?
[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax
Copy link
Member

@jcouv jcouv Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the SyntaxKind above bet considered experimental too? #Closed

[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.AddArgumentListArguments(params Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax![]! items) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax!
[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken withKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithArgumentList(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken
[RSEXPERIMENTAL006]Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithWithKeyword(Microsoft.CodeAnalysis.SyntaxToken withKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
[RSEXPERIMENTAL006]override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> Microsoft.CodeAnalysis.SyntaxNode?
[RSEXPERIMENTAL006]override Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> void
[RSEXPERIMENTAL006]override Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Accept<TResult>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult>! visitor) -> TResult?
[RSEXPERIMENTAL006]static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WithElement(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax? argumentList = null) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
[RSEXPERIMENTAL006]static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WithElement(Microsoft.CodeAnalysis.SyntaxToken withKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax!
[RSEXPERIMENTAL006]virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> void
[RSEXPERIMENTAL006]virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult>.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> TResult?
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Syntax/Syntax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@
</Field>
<Field Name="Expression" Type="ExpressionSyntax" />
</Node>
<Node Name="WithElementSyntax" Base="CollectionElementSyntax">
<Node Name="WithElementSyntax" Base="CollectionElementSyntax" Experimental="https://github.com/dotnet/roslyn/issues/80613">
<Kind Name="WithElement"/>
<Field Name="WithKeyword" Type="SyntaxToken">
<Kind Name="WithKeyword"/>
Expand Down
Loading