Roslyn: Crash when writing positional records

Created on 20 Jul 2020  路  5Comments  路  Source: dotnet/roslyn

Version 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)
Area-Compilers Bug New Language Feature - Records Urgency-Soon

Most helpful comment

@YairHalberstadt AFAICT, it shouldn't:

$ git merge-base --is-ancestor 228e2dc 226c0c3; echo $?
1

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.

All 5 comments

Should this be in 16.8 preview 1?
That's still crashing for me.

@YairHalberstadt AFAICT, it shouldn't:

$ git merge-base --is-ancestor 228e2dc 226c0c3; echo $?
1

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.

@jcouv there are still reports of this crashing in 16.8p1. Can you please make sure that either the fix didn't make the cutoff or we fix it?

The fix only made it into 16.8p2. We're also trying to service 16.7

Alright, thanks.

Was this page helpful?
0 / 5 - 0 ratings