Skip to content
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

Fix syntax generation of explict checked operator from symbol #77102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -31740,7 +31740,8 @@ public OperatorDeclarationSyntax OperatorDeclaration(CoreSyntax.SyntaxList<Attri
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.FalseKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.IsKeyword: break;
case SyntaxKind.IsKeyword:
case SyntaxKind.ExplicitKeyword: break;
default: throw new ArgumentException(nameof(operatorToken));
}
if (parameterList == null) throw new ArgumentNullException(nameof(parameterList));
Expand Down Expand Up @@ -37008,7 +37009,8 @@ public static OperatorDeclarationSyntax OperatorDeclaration(CoreSyntax.SyntaxLis
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.FalseKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.IsKeyword: break;
case SyntaxKind.IsKeyword:
case SyntaxKind.ExplicitKeyword: break;
default: throw new ArgumentException(nameof(operatorToken));
}
if (parameterList == null) throw new ArgumentNullException(nameof(parameterList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5395,7 +5395,8 @@ public static OperatorDeclarationSyntax OperatorDeclaration(SyntaxList<Attribute
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.FalseKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.IsKeyword: break;
case SyntaxKind.IsKeyword:
case SyntaxKind.ExplicitKeyword: break;
default: throw new ArgumentException(nameof(operatorToken));
}
if (parameterList == null) throw new ArgumentNullException(nameof(parameterList));
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Syntax/Syntax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3943,6 +3943,7 @@
<Kind Name="FalseKeyword"/>
<Kind Name="TrueKeyword"/>
<Kind Name="IsKeyword"/>
<Kind Name="ExplicitKeyword"/>
ericstj marked this conversation as resolved.
Show resolved Hide resolved
</Field>
<Field Name="ParameterList" Type="ParameterListSyntax" Override="true"/>
<Choice>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,24 @@ public void TestConversionOperatorDeclaration()
"public static implicit operator global::System.Decimal(global::System.Byte value)\r\n{\r\n}");
}

[Fact, WorkItem(77101, "https://github.com/dotnet/roslyn/issues/77101")]
public void TestExplicitOperatorFromSymbol()
{
var compilation = CSharpCompilation.Create("Test", [SyntaxFactory.ParseSyntaxTree("""
public class C
{
public static explicit operator int(C c) => 0;
ericstj marked this conversation as resolved.
Show resolved Hide resolved
}
""")]);

var c = compilation.GetTypeByMetadataName("C");
var op = c.GetMembers().OfType<IMethodSymbol>().Where(m => m.MethodKind == MethodKind.Conversion).Single();
ericstj marked this conversation as resolved.
Show resolved Hide resolved

VerifySyntax<ConversionOperatorDeclarationSyntax>(
Generator.OperatorDeclaration(op),
"public static explicit operator global::System.Int32(global::C c)\r\n{\r\n}");
ericstj marked this conversation as resolved.
Show resolved Hide resolved
}

[Fact]
public void TestConstructorDeclaration()
{
Expand Down
Loading