From a1c4f361eff40830b0c971257f88eccc6f60deb6 Mon Sep 17 00:00:00 2001 From: TomasMatousek Date: Fri, 3 Oct 2014 23:37:45 -0700 Subject: [PATCH] The synthesized variable used for storing the value of Select Case should be long-lived. (changeset 1348097) --- .../Core/Portable/SynthesizedLocalKind.cs | 12 ++-- .../LocalRewriter/LocalRewriter_SelectCase.vb | 4 +- .../VisualBasic/Test/Emit/PDB/PDBTests.vb | 71 ++++++++++++++++--- .../Semantic/BasicCompilerSemanticTest.vbproj | 2 +- .../{SelectCaseTest.vb => SelectCaseTests.vb} | 4 +- 5 files changed, 75 insertions(+), 18 deletions(-) rename Src/Compilers/VisualBasic/Test/Semantic/Semantics/{SelectCaseTest.vb => SelectCaseTests.vb} (99%) diff --git a/Src/Compilers/Core/Portable/SynthesizedLocalKind.cs b/Src/Compilers/Core/Portable/SynthesizedLocalKind.cs index 13486883782..94a80fbd614 100644 --- a/Src/Compilers/Core/Portable/SynthesizedLocalKind.cs +++ b/Src/Compilers/Core/Portable/SynthesizedLocalKind.cs @@ -107,11 +107,10 @@ internal enum SynthesizedLocalKind // VB TODO: ForDirection = 14, - // VB TODO: - // degenerate select key (can we EnC when stopped on case?) - - // VB TODO: XmlInExpressionLambda locals are always lifted and must have distinct names. - XmlInExpressionLambda = 15, + /// + /// Local variable used to store the value of Select Case during the execution of Case statements. + /// + SelectCaseValue = 15, // VB TODO OnErrorActiveHandler = 16, @@ -169,6 +168,9 @@ internal enum SynthesizedLocalKind /// CachedAnonymousMethodDelegate = 31, + // VB TODO: XmlInExpressionLambda locals are always lifted and must have distinct names. + XmlInExpressionLambda = 32, + /// /// All values have to be less than or equal to () /// diff --git a/Src/Compilers/VisualBasic/Portable/Lowering/LocalRewriter/LocalRewriter_SelectCase.vb b/Src/Compilers/VisualBasic/Portable/Lowering/LocalRewriter/LocalRewriter_SelectCase.vb index 56559d4bbe2..072b62bd7d5 100644 --- a/Src/Compilers/VisualBasic/Portable/Lowering/LocalRewriter/LocalRewriter_SelectCase.vb +++ b/Src/Compilers/VisualBasic/Portable/Lowering/LocalRewriter/LocalRewriter_SelectCase.vb @@ -193,6 +193,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic statementBuilder.Add(New BoundSequencePoint(selectExprStmtSyntax, Nothing)) End If + If generateUnstructuredExceptionHandlingResumeCode Then RegisterUnstructuredExceptionHandlingResumeTarget(selectExprStmtSyntax, canThrow:=True, statements:=statementBuilder) ' If the Select throws, a Resume Next should branch to the End Select. @@ -217,7 +218,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim selectExprType = rewrittenSelectExpression.Type ' Store the select expression result in a temp - Dim tempLocal = New SynthesizedLocal(Me.currentMethodOrLambda, selectExprType, SynthesizedLocalKind.LoweringTemp) + Dim selectStatementSyntax = DirectCast(selectExprStmtSyntax.Parent, SelectBlockSyntax).SelectStatement + Dim tempLocal = New SynthesizedLocal(Me.currentMethodOrLambda, selectExprType, SynthesizedLocalKind.SelectCaseValue, selectStatementSyntax) tempLocals = ImmutableArray.Create(Of LocalSymbol)(tempLocal) Dim boundTemp = New BoundLocal(rewrittenSelectExpression.Syntax, tempLocal, selectExprType) diff --git a/Src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb b/Src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb index 6b9c56c044d..3de7152bd04 100644 --- a/Src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb +++ b/Src/Compilers/VisualBasic/Test/Emit/PDB/PDBTests.vb @@ -1940,9 +1940,9 @@ End Module - + - + @@ -2069,7 +2069,7 @@ End Module - + @@ -2133,9 +2133,9 @@ End Module - + - + @@ -2199,9 +2199,9 @@ End Module - + - + @@ -2392,7 +2392,7 @@ End Module - + @@ -7522,6 +7522,61 @@ End Class +) + End Sub + + + Sub SynthesizedVariableForSelectCastValue() + Dim source = + + +Imports System +Class C + Sub F(args As String()) + Select Case args(0) + Case "a" + Console.WriteLine(1) + Case "b" + Console.WriteLine(2) + Case "c" + Console.WriteLine(3) + End Select + End Sub +End Class + + + + Dim c = CreateCompilationWithMscorlibAndVBRuntime(source, options:=TestOptions.DebugDll) + c.VerifyDiagnostics() + c.VerifyPdb("C.F", + + + + + + + + + + + + + + + + + + + + + + + + + + + + ) End Sub diff --git a/Src/Compilers/VisualBasic/Test/Semantic/BasicCompilerSemanticTest.vbproj b/Src/Compilers/VisualBasic/Test/Semantic/BasicCompilerSemanticTest.vbproj index 0dc19a3b2eb..271db48b4b5 100644 --- a/Src/Compilers/VisualBasic/Test/Semantic/BasicCompilerSemanticTest.vbproj +++ b/Src/Compilers/VisualBasic/Test/Semantic/BasicCompilerSemanticTest.vbproj @@ -203,7 +203,7 @@ - + diff --git a/Src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTest.vb b/Src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb similarity index 99% rename from Src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTest.vb rename to Src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb index aaaa3f01270..b2aa9510827 100644 --- a/Src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTest.vb +++ b/Src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb @@ -1,12 +1,10 @@ ' Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Roslyn.Test.Utilities Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics - Public Class SelectCaseTest + Public Class SelectCaseTests Inherits BasicTestBase Public Sub SelectCaseExpression_NothingLiteral() -- GitLab