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

Crash in params with interpolated string handler arguments #71488

Closed
333fred opened this issue Jan 4, 2024 · 1 comment
Closed

Crash in params with interpolated string handler arguments #71488

333fred opened this issue Jan 4, 2024 · 1 comment
Assignees
Milestone

Comments

@333fred
Copy link
Member

333fred commented Jan 4, 2024

Sharplab

using System.Runtime.CompilerServices;

M("", $"test");

void M(string s, [InterpolatedStringHandlerArgument(nameof(s))] params CustomHandler[] handlers) {}

[InterpolatedStringHandler]
public class CustomHandler {
    public CustomHandler(int a, int b, string test) {}
    
    public void AppendLiteral(string s) {}
}
System.InvalidCastException: Unable to cast object of type 'SZArray' to type 'Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol'.
   at Microsoft.CodeAnalysis.CSharp.Binder.<CreateConversion>g__createConversion|208_0(SyntaxNode syntax, BoundExpression source, Conversion conversion, Boolean isCast, ConversionGroup conversionGroupOpt, Boolean wasCompilerGenerated, TypeSymbol destination, BindingDiagnosticBag diagnostics, Boolean hasErrors) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs:line 201
   at Microsoft.CodeAnalysis.CSharp.Binder.BindInterpolatedStringHandlerInMemberCall(BoundExpression unconvertedString, ArrayBuilder`1 arguments, ImmutableArray`1 parameters, MemberAnalysisResult& memberAnalysisResult, Int32 interpolatedStringArgNum, BoundExpression receiver, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs:line 905
   at Microsoft.CodeAnalysis.CSharp.Binder.CheckAndCoerceArguments[TMember](MemberResolutionResult`1 methodResult, AnalyzedArguments analyzedArguments, BindingDiagnosticBag diagnostics, BoundExpression receiver, Boolean invokedAsExtensionMethod) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs:line 3411
   at Microsoft.CodeAnalysis.CSharp.Binder.BindInvocationExpressionContinued(SyntaxNode node, SyntaxNode expression, String methodName, OverloadResolutionResult`1 result, AnalyzedArguments analyzedArguments, MethodGroup methodGroup, NamedTypeSymbol delegateTypeOpt, BindingDiagnosticBag diagnostics, CSharpSyntaxNode queryClause) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs:line 1075
   at Microsoft.CodeAnalysis.CSharp.Binder.BindMethodGroupInvocation(SyntaxNode syntax, SyntaxNode expression, String methodName, BoundMethodGroup methodGroup, AnalyzedArguments analyzedArguments, BindingDiagnosticBag diagnostics, CSharpSyntaxNode queryClause, Boolean allowUnexpandedForm, Boolean& anyApplicableCandidates) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs:line 741
   at Microsoft.CodeAnalysis.CSharp.Binder.BindInvocationExpression(SyntaxNode node, SyntaxNode expression, String methodName, BoundExpression boundExpression, AnalyzedArguments analyzedArguments, BindingDiagnosticBag diagnostics, CSharpSyntaxNode queryClause, Boolean allowUnexpandedForm) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs:line 321
   at Microsoft.CodeAnalysis.CSharp.Binder.<BindInvocationExpression>g__bindArgumentsAndInvocation|573_0(InvocationExpressionSyntax node, BoundExpression boundExpression, AnalyzedArguments analyzedArguments, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs:line 225
   at Microsoft.CodeAnalysis.CSharp.Binder.BindInvocationExpression(InvocationExpressionSyntax node, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs:line 214
   at Microsoft.CodeAnalysis.CSharp.Binder.<BindExpressionInternal>g__bindExpressionInternal|325_0(ExpressionSyntax node, BindingDiagnosticBag diagnostics, Boolean invoked, Boolean indexed) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs:line 602
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(ExpressionSyntax node, BindingDiagnosticBag diagnostics, Boolean invoked, Boolean indexed) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs:line 579
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionStatement(CSharpSyntaxNode node, ExpressionSyntax syntax, Boolean allowsAnyExpression, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs:line 648
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionStatement(ExpressionStatementSyntax node, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs:line 641
   at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs:line 72
   at Microsoft.CodeAnalysis.CSharp.Binder.BindSimpleProgramCompilationUnit(CompilationUnitSyntax compilationUnit, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs:line 3581
   at Microsoft.CodeAnalysis.CSharp.Binder.BindMethodBody(CSharpSyntaxNode syntax, BindingDiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs:line 3555
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, Boolean includeInitializersInBody, BoundNode initializersBody, Boolean reportNullableDiagnostics, ImportChain& importChain, Boolean& originalBodyNested, Boolean& prependedDefaultValueTypeConstructorInitializer, InitialState& forSemanticModel) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 1773
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 991
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 530
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0() in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 432
   at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() in /_/src/Compilers/Core/Portable/InternalUtilities/UICultureUtilities.cs:line 139
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__281_0(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 4, 2024
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Jan 5, 2024
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 8, 2024
@jaredpar jaredpar added this to the 17.10 milestone Jan 8, 2024
@333fred 333fred assigned AlekseyTs and unassigned 333fred Jan 8, 2024
@333fred
Copy link
Member Author

333fred commented Jan 8, 2024

I discovered this when reviewing Aleksey's change that actually fixes the issue. As this isn't a user-reported crash, I'll avoid porting the fix over to main directly, and it'll be fixed when params collections merges, so that we avoid merge conflicts between the feature branch and main.

@333fred 333fred modified the milestones: 17.10, .NET 9 Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants