提交 5a5ea2a6 编写于 作者: V vsadov

CR feedback

上级 ca41aeda
......@@ -1887,6 +1887,7 @@ internal static uint GetValEscape(BoundExpression expr, uint scopeOfTheContainin
case BoundKind.Local:
return ((BoundLocal)expr).LocalSymbol.ValEscapeScope;
case BoundKind.StackAllocArrayCreation:
case BoundKind.ConvertedStackAllocExpression:
return Binder.TopLevelScope;
......@@ -2054,6 +2055,7 @@ internal static bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint
}
return true;
case BoundKind.StackAllocArrayCreation:
case BoundKind.ConvertedStackAllocExpression:
if (escapeTo < Binder.TopLevelScope)
{
......
......@@ -75,20 +75,6 @@ internal partial class Binder
sourceTuple.HasErrors);
}
// identity stackalloc conversions result in a converted node
// to indicate that stackalloc conversions are no longer applicable.
// nothing else changes
if (source.Kind == BoundKind.StackAllocArrayCreation)
{
var sourceStackAlloc = (BoundStackAllocArrayCreation)source;
source = new BoundConvertedStackAllocExpression(
sourceStackAlloc.Syntax,
sourceStackAlloc.ElementType,
sourceStackAlloc.Count,
sourceStackAlloc.Type,
sourceStackAlloc.HasErrors);
}
// We need to preserve any conversion that changes the type (even identity conversions, like object->dynamic),
// or that was explicitly written in code (so that GetSemanticInfo can find the syntax in the bound tree).
if (!isCast && source.Type == destination)
......
......@@ -3016,9 +3016,9 @@ private void BindArrayInitializerExpressions(InitializerExpressionSyntax initial
StackAllocArrayCreationExpressionSyntax node, DiagnosticBag diagnostics)
{
bool hasErrors = false;
var inLegalPosition = (IsInMethodBody || IsLocalFunctionsScopeBinder) && node.IsLegalSpanStackAllocPosition();
if (!IsInMethodBody && !IsLocalFunctionsScopeBinder ||
!node.IsLegalSpanStackAllocPosition())
if (!inLegalPosition)
{
hasErrors = true;
diagnostics.Add(
......@@ -3105,7 +3105,7 @@ private void BindArrayInitializerExpressions(InitializerExpressionSyntax initial
}
TypeSymbol type = null;
if (!node.IsVariableDeclarationInitialization())
if (inLegalPosition && !node.IsVariableDeclarationInitialization())
{
CheckFeatureAvailability(node, MessageID.IDS_FeatureRefStructs, diagnostics);
GetWellKnownTypeMember(Compilation, WellKnownMember.System_Span_T__ctor, diagnostics, syntax: node);
......
......@@ -227,7 +227,7 @@ void M()
}
[Fact]
public void ConditionalExpressionOnSpan_NonConvertible()
public void ConditionalExpressionOnSpan_BothStackallocSpans()
{
CreateCompilationWithMscorlibAndSpan(@"
class Test
......
......@@ -7560,13 +7560,7 @@ void M(int* p = stackalloc int[1])
CreateStandardCompilation(text, options: TestOptions.UnsafeReleaseDll).VerifyDiagnostics(
// (4,21): error CS1525: Invalid expression term 'stackalloc'
// void M(int* p = stackalloc int[1])
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "stackalloc").WithArguments("stackalloc").WithLocation(4, 21),
// (4,21): error CS0656: Missing compiler required member 'System.Span`1..ctor'
// void M(int* p = stackalloc int[1])
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "stackalloc int[1]").WithArguments("System.Span`1", ".ctor").WithLocation(4, 21),
// (4,21): error CS0518: Predefined type 'System.Span`1' is not defined or imported
// void M(int* p = stackalloc int[1])
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "stackalloc int[1]").WithArguments("System.Span`1").WithLocation(4, 21)
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "stackalloc").WithArguments("stackalloc").WithLocation(4, 21)
);
}
......
......@@ -2876,13 +2876,7 @@ static void Main(string[] args)
CreateStandardCompilation(text, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)).VerifyDiagnostics(
// (4,30): error CS1525: Invalid expression term 'stackalloc'
// int* property { get; } = stackalloc int[256];
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "stackalloc").WithArguments("stackalloc").WithLocation(4, 30),
// (4,30): error CS0656: Missing compiler required member 'System.Span`1..ctor'
// int* property { get; } = stackalloc int[256];
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "stackalloc int[256]").WithArguments("System.Span`1", ".ctor").WithLocation(4, 30),
// (4,30): error CS0518: Predefined type 'System.Span`1' is not defined or imported
// int* property { get; } = stackalloc int[256];
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "stackalloc int[256]").WithArguments("System.Span`1").WithLocation(4, 30)
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "stackalloc").WithArguments("stackalloc").WithLocation(4, 30)
);
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册