dotnet/roslyn

Unreachable exception compiling valid VB code with synthesized constructor

Open

#1,452 opened on Mar 20, 2015

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-InteractiveBugInteractive-EnChelp wanted

Description

Ported from TFS WorkItem: 1096576


<SPAN style="COLOR: blue">Sub</SPAN> <SPAN style="COLOR: black">Foo</SPAN><SPAN style="COLOR: black">()</SPAN>
<SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">Sub</SPAN>
<SPAN style="COLOR: blue">Public</SPAN> <SPAN style="COLOR: black">t</SPAN> <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: blue">New</SPAN> <SPAN style="COLOR: #2b91af">Thing</SPAN>
<SPAN style="COLOR: blue">Public</SPAN> <SPAN style="COLOR: black">tcb</SPAN> <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: #2b91af">AsyncCallback</SPAN> <SPAN style="COLOR: black">=</SPAN> <SPAN style="COLOR: blue">AddressOf</SPAN> <SPAN style="COLOR: black">t</SPAN><SPAN style="COLOR: black">.</SPAN><SPAN style="COLOR: black">Foo</SPAN>

End Class Result:System.InvalidOperationException: This program location is thought to be unreachable.   at Microsoft.CodeAnalysis.VisualBasic.Symbols.SourceMemberContainerTypeSymbol.CalculateLocalSyntaxOffsetInSynthesizedConstructor(Int32 localPosition, SyntaxTree localTree, Boolean isShared) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Symbols\Source\SourceMemberContainerTypeSymbol.vb:line 3222   at Microsoft.CodeAnalysis.VisualBasic.Symbols.SynthesizedConstructorSymbol.CalculateLocalSyntaxOffset(Int32 localPosition, SyntaxTree localTree) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Symbols\Source\SynthesizedConstructorSymbol.vb:line 63   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.GetLocalDebugName(LocalSymbol local, LocalDebugId& localId) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 1320   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.DefineLocal(LocalSymbol local, VisualBasicSyntaxNode syntaxNode) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 1265   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitSequenceExpression(BoundSequence sequence, Boolean used) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitExpression.vb:line 381   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitExpression.vb:line 100   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitAssignmentExpression(BoundAssignmentOperator assignmentOperator, Boolean used) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitExpression.vb:line 1554   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitExpression.vb:line 40   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 25   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitStatementAndCountInstructions(BoundStatement statement) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 80   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitSequencePointStatement(BoundSequencePoint node) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\CodeGenerator.vb:line 250   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 19   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 34   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitBlock(BoundBlock scope) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 1222   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\EmitStatement.vb:line 16   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.GenerateImpl() in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\CodeGenerator.vb:line 149   at Microsoft.CodeAnalysis.VisualBasic.CodeGen.CodeGenerator.Generate() in D:\Roslyn\Open\Compilers\VisualBasic\Portable\CodeGen\CodeGenerator.vb:line 93   at Microsoft.CodeAnalysis.VisualBasic.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, BoundStatement block, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DebugDocumentProvider debugDocumentProvider, DiagnosticBag diagnostics, ImmutableArray1 namespaceScopes) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Compilation\MethodCompiler.vb:line 1385<BR>&nbsp;&nbsp; at Microsoft.CodeAnalysis.VisualBasic.MethodCompiler.LowerAndEmitMethod(MethodSymbol method, BoundBlock block, Binder binderOpt, TypeCompilationState compilationState, DiagnosticBag diagsForCurrentMethod, ProcessedFieldOrPropertyInitializers processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, MethodSymbol constructorToInject, ImmutableArray1 namespaceScopes) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Compilation\MethodCompiler.vb:line 1324   at Microsoft.CodeAnalysis.VisualBasic.MethodCompiler.CompileMethod(MethodSymbol method, Predicate1 filter, TypeCompilationState compilationState, ProcessedFieldOrPropertyInitializers processedInitializers, Binder containingTypeBinder, SynthesizedSubmissionFields previousSubmissionFields, MethodSymbol&amp; referencedConstructor) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Compilation\MethodCompiler.vb:line 1125<BR>&nbsp;&nbsp; at Microsoft.CodeAnalysis.VisualBasic.MethodCompiler.CompileNamedType(NamedTypeSymbol symbol, Predicate1 filter) in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Compilation\MethodCompiler.vb:line 613   at Microsoft.CodeAnalysis.VisualBasic.MethodCompiler._Closure$__7._Lambda$__8() in D:\Roslyn\Open\Compilers\VisualBasic\Portable\Compilation\MethodCompiler.vb:line 496   at System.Threading.Tasks.Task.InnerInvoke()   at System.Threading.Tasks.Task.Execute()


  1. Created By Paul Harrington (12/15/2014 12:38:09 PM)

  1. Edited By Paul Harrington (12/15/2014 12:51:43 PM)

(Simplified the repro)


  1. Edited By Wonseok Chae (12/15/2014 1:52:13 PM)

  1. Edited By Aleksey Tsingauz (12/16/2014 11:33:18 AM)

Resolved with changeset 1387208: Stop throwing Unreachable exception in CalculateLocalSyntaxOffsetInSynthesizedConstructor, return -1 instead. _NO_CI_


  1. Edited By Aleksey Tsingauz (12/16/2014 12:01:17 PM)

Tomas indicated that there still might be work to make ENC working properly in scenarios similar to this one.


  1. Edited By Tomas Matousek (12/19/2014 6:33:12 AM)

The right thing to do is for the compiler to stop emitting a closure for the relaxation delegate. Since that was rejected for RTM there is nothing to do here.


  1. Edited By Tomas Matousek (1/13/2015 5:19:29 PM)

Actually, let's revisit this. It might be ok or need just a simple tweak.


Contributor guide