提交 d3f19548 编写于 作者: T Tomas Matousek

Report an error if the type of an expression of a query clause changes

上级 75e83b68
......@@ -4326,6 +4326,40 @@ void F()
#region Queries
[Fact]
public void Queries_Update_Signature1()
{
var src1 = @"
using System;
using System.Linq;
class C
{
void F()
{
var result = from a in new[] {1} from b in new[] {2} select b;
}
}
";
var src2 = @"
using System;
using System.Linq;
class C
{
void F()
{
var result = from a in new[] {1.0} from b in new[] {2} select b;
}
}
";
var edits = GetTopEdits(src1, src2);
edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.ChangingQueryLambdaType, "from", "from clause"),
Diagnostic(RudeEditKind.ChangingQueryLambdaType, "select", "select clause"));
}
[Fact]
public void Queries_FromSelect_Update1()
{
......
......@@ -3862,6 +3862,33 @@ End Class
#End Region
#Region "Queries"
<Fact(Skip:="https://github.com/dotnet/roslyn/issues/1315"), WorkItem(1315)>
Public Sub Queries_Update_Signature1()
Dim src1 = "
Imports System
Imports System.Linq
Class C
Sub F()
Dim result = From a In {1} From b In {2} Select b
End Sub
End Class
"
Dim src2 = "
Imports System
Imports System.Linq
Class C
Sub F()
Dim result = From a In {1.0} From b In {2} Select b
End Sub
End Class
"
Dim edits = GetTopEdits(src1, src2)
edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.ChangingQueryLambdaType, "From", "From clause"),
Diagnostic(RudeEditKind.ChangingQueryLambdaType, "Select", "Select clause"))
End Sub
<Fact>
Public Sub Queries_FromSelect_Update()
......
......@@ -887,6 +887,11 @@ internal override bool IsLambda(SyntaxNode node)
return LambdaUtilities.IsLambda(node);
}
internal override bool IsLambdaExpression(SyntaxNode node)
{
return node is LambdaExpressionSyntax;
}
internal override bool TryGetLambdaBodies(SyntaxNode node, out SyntaxNode body1, out SyntaxNode body2)
{
return LambdaUtilities.TryGetLambdaBodies(node, out body1, out body2);
......
......@@ -233,6 +233,7 @@ private SyntaxNode FindStatement(SyntaxNode declarationBody, int position, out i
internal abstract bool IsMethod(SyntaxNode declaration);
internal abstract bool IsLambda(SyntaxNode node);
internal abstract bool IsLambdaExpression(SyntaxNode node);
internal abstract bool IsClosureScope(SyntaxNode node);
internal abstract bool ContainsLambda(SyntaxNode declaration);
internal abstract SyntaxNode GetLambda(SyntaxNode lambdaBody);
......@@ -3195,6 +3196,11 @@ private void ReportLambdaSignatureRudeEdits(SemanticModel oldModel, SyntaxNode o
var newLambda = GetLambda(newLambdaBody);
if (!IsLambdaExpression(newLambda))
{
rudeEdit = RudeEditKind.ChangingQueryLambdaType;
}
diagnostics.Add(new RudeEditDiagnostic(
rudeEdit,
GetDiagnosticSpan(newLambda, EditKind.Update),
......
......@@ -66,6 +66,7 @@ internal static class RudeEditDiagnosticDescriptors
{ GetDescriptorPair(RudeEditKind.ChangingCapturedVariableScope, FeaturesResources.ChangingCapturedVariableScope) },
{ GetDescriptorPair(RudeEditKind.ChangingLambdaParameters, FeaturesResources.ChangingLambdaParameters) },
{ GetDescriptorPair(RudeEditKind.ChangingLambdaReturnType, FeaturesResources.ChangingLambdaReturnType) },
{ GetDescriptorPair(RudeEditKind.ChangingQueryLambdaType, FeaturesResources.ChangingQueryLambdaType) },
{ GetDescriptorPair(RudeEditKind.AccessingCapturedVariableInLambda, FeaturesResources.AccessingCapturedVariableInLambda) },
{ GetDescriptorPair(RudeEditKind.NotAccessingCapturedVariableInLambda, FeaturesResources.NotAccessingCapturedVariableInLambda) },
{ GetDescriptorPair(RudeEditKind.InsertLambdaWithMultiScopeCapture, FeaturesResources.InsertLambdaWithMultiScopeCapture) },
......
......@@ -71,8 +71,7 @@ internal enum RudeEditKind : ushort
NotAccessingCapturedVariableInLambda = 56,
InsertLambdaWithMultiScopeCapture = 57,
DeleteLambdaWithMultiScopeCapture = 58,
// 59 can be used
ChangingQueryLambdaType = 59,
InsertAroundActiveStatement = 60,
DeleteAroundActiveStatement = 61,
......
......@@ -420,6 +420,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Changing the type of &apos;{0}&apos; will prevent the debug session from continuing..
/// </summary>
internal static string ChangingQueryLambdaType {
get {
return ResourceManager.GetString("ChangingQueryLambdaType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Changing the constraint from &apos;{0}&apos; to &apos;{1}&apos; will prevent the debug session from continuing..
/// </summary>
......
......@@ -396,6 +396,9 @@
<data name="ChangingLambdaReturnType" xml:space="preserve">
<value>Changing the return type of '{0}' will prevent the debug session from continuing.</value>
</data>
<data name="ChangingQueryLambdaType" xml:space="preserve">
<value>Changing the type of '{0}' will prevent the debug session from continuing.</value>
</data>
<data name="ChangingCapturedVariableScope" xml:space="preserve">
<value>Changing the declaration scope of a captured variable '{0}' will prevent the debug session from continuing.</value>
</data>
......
......@@ -937,6 +937,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue
Return LambdaUtilities.IsLambda(node)
End Function
Friend Overrides Function IsLambdaExpression(node As SyntaxNode) As Boolean
Return TypeOf node Is LambdaExpressionSyntax
End Function
Friend Overrides Function TryGetLambdaBodies(node As SyntaxNode, ByRef body1 As SyntaxNode, ByRef body2 As SyntaxNode) As Boolean
Return LambdaUtilities.TryGetLambdaBodies(node, body1, body2)
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册