Crash when writing positional records
See original GitHub issueVersion Used: vs 16.7.0 preview 4.0 sharplab master as of 18th july
Steps to Reproduce:
The following code in vs crashes immediately:
public record A(B b,) { }
In sharplab you can see the error:
System.AggregateException: One or more errors occurred. (Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax'.)
---> System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax'.
at Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedRecordPropertySymbol.CreateAccessorSymbol(Boolean isGet, CSharpSyntaxNode syntax, PropertySymbol explicitlyImplementedPropertyOpt, String aliasQualifierOpt, Boolean isAutoPropertyAccessor, Boolean isExplicitInterfaceImplementation, DiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordPropertySymbol.cs:line 77
at Microsoft.CodeAnalysis.CSharp.Symbols.SourcePropertySymbolBase..ctor(SourceMemberContainerTypeSymbol containingType, Binder binder, CSharpSyntaxNode syntax, CSharpSyntaxNode getSyntax, CSharpSyntaxNode setSyntax, ArrowExpressionClauseSyntax arrowExpression, ExplicitInterfaceSpecifierSyntax interfaceSpecifier, DeclarationModifiers modifiers, Boolean isIndexer, Boolean hasInitializer, Boolean isAutoProperty, Boolean hasAccessorList, Boolean isInitOnly, RefKind refKind, String name, Location location, TypeWithAnnotations typeOpt, Boolean hasParameters, DiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs:line 72
at Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedRecordPropertySymbol..ctor(SourceMemberContainerTypeSymbol containingType, CSharpSyntaxNode syntax, ParameterSymbol backingParameter, Boolean isOverride, DiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordPropertySymbol.cs:line 24
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.<AddSynthesizedRecordMembersIfNecessary>g__addProperties|162_4(ImmutableArray`1 recordParameters, <>c__DisplayClass162_0& ) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 3099
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilder builder, DiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 3007
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.BuildMembersAndInitializers(DiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 2466
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetMembersAndInitializers() in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 1323
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.MakeAllMembers(DiagnosticBag diagnostics) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 2235
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetMembersByNameSlow() in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 1356
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs:line 492
at Microsoft.CodeAnalysis.CSharp.Symbol.ForceCompleteMemberByLocation(SourceLocation locationOpt, Symbol member, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Symbols/Symbol.cs:line 775
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamespaceSymbol.<>c__DisplayClass49_1.<ForceComplete>b__0(Int32 i) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol_Completion.cs:line 67
at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass6_0`1.<WithCurrentUICulture>b__0(T param) in /_/src/Compilers/Core/Portable/InternalUtilities/UICultureUtilities.cs:line 173
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body)
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamespaceSymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol_Completion.cs:line 56
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceModuleSymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs:line 257
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceAssemblySymbol.ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs:line 907
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSourceDeclarationDiagnostics(SyntaxTree syntaxTree, Nullable`1 filterSpanWithinTree, Func`4 locationFilterOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs:line 2576
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics(CompilationStage stage, Boolean includeEarlierStages, DiagnosticBag diagnostics, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs:line 2468
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics(CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs:line 2383
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetAllDiagnosticsWithoutStateTrackingAsync(ImmutableArray`1 analyzers, CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs:line 465
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetAllDiagnosticsAsync(CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs:line 326
at MirrorSharp.Internal.Roslyn.RoslynSession.GetDiagnosticsAsync(CancellationToken cancellationToken)
at MirrorSharp.Internal.Handlers.SlowUpdateHandler.ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
at MirrorSharp.Internal.Connection.ReceiveAndProcessInternalAsync(CancellationToken cancellationToken)
at MirrorSharp.Internal.Connection.ReceiveAndProcessAsync(CancellationToken cancellationToken)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Crash to desktop upon writing the first parameter of ...
Crash to desktop upon writing the first parameter of the primary constructor for a record nested in classClosed - Fixed View solution
Read more >Using Record Selectors causes Access to crash.
Access crashes when I use the Record Selectors on the left of the flags to Cut or Paste a record and then close...
Read more >C# Records - The good, bad & ugly
You can think of C# Records as a motor cycle crash helmet. They're great for providing some protection for your head in the...
Read more >why Positional Pattern doesn't work for records that have ...
I remember record types need to have two or more positional parameters to have Deconstruct method generated by the compiler, but I was...
Read more >Logic Pro X crashes when recording stops
When I'm done, I stop the recording and Logic crashes. Out of the blue. No backup, no error messages - just shuts down....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@YairHalberstadt AFAICT, it shouldn’t:
My installation of 16.8 Preview 1.0 reports C# Tools version 3.8.0-1.20378.6+226c0c3f392232b3dd7ecd527f1fd00f0f86d7e4, 228e2dc is the commit that merged https://github.com/dotnet/roslyn/pull/46225, the git command is from here and 1 means it’s not an ancestor.
Alright, thanks.