提交 9091652e 编写于 作者: V VSadov

Merge pull request #5242 from VSadov/fix4697

Handle local promotion to long lived in stack spiller when local is type substituted
......@@ -1756,6 +1756,11 @@ internal override SynthesizedLocalKind SynthesizedKind
get { return SynthesizedLocalKind.OptimizerTemp; }
}
internal override LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
{
throw new NotImplementedException();
}
internal override SyntaxToken IdentifierToken
{
get { return default(SyntaxToken); }
......
......@@ -1107,11 +1107,8 @@ private void PromoteAndAddLocals(BoundSpillSequenceBuilder builder, ImmutableArr
else
{
Debug.Assert(_F.Syntax.IsKind(SyntaxKind.AwaitExpression));
SynthesizedLocal shortLived = (SynthesizedLocal)local;
SynthesizedLocal longLived = shortLived.WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind.AwaitSpill, _F.Syntax);
_tempSubstitution.Add(shortLived, longLived);
LocalSymbol longLived = local.WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind.AwaitSpill, _F.Syntax);
_tempSubstitution.Add(local, longLived);
builder.AddLocal(longLived, _F.Diagnostics);
}
}
......
......@@ -25,6 +25,8 @@ protected LocalSymbol()
get;
}
internal abstract LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax);
internal abstract bool IsImportedFromMetadata
{
get;
......
......@@ -103,6 +103,11 @@ internal override SynthesizedLocalKind SynthesizedKind
get { return SynthesizedLocalKind.UserDefined; }
}
internal override LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
{
throw ExceptionUtilities.Unreachable;
}
internal override bool IsPinned
{
get
......
......@@ -70,7 +70,7 @@ public SyntaxNode SyntaxOpt
get { return _syntaxOpt; }
}
internal SynthesizedLocal WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
internal override LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
{
return new SynthesizedLocal(
_containingMethodOpt,
......
......@@ -97,5 +97,15 @@ internal override ImmutableArray<Diagnostic> GetConstantValueDiagnostics(BoundEx
{
return _originalVariable.GetConstantValueDiagnostics(boundInitValue);
}
internal override LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
{
var origSynthesized = (SynthesizedLocal)_originalVariable;
return new TypeSubstitutedLocalSymbol(
origSynthesized.WithSynthesizedLocalKindAndSyntax(kind, syntax),
_type,
_containingSymbol
);
}
}
}
......@@ -3400,6 +3400,48 @@ async Task<int> Test(IDisposable id, Task<int> task)
CompileAndVerify(comp.WithOptions(TestOptions.ReleaseExe));
}
[Fact, WorkItem(4697, "https://github.com/dotnet/roslyn/issues/4697")]
public void AwaitInObjInitializer()
{
var source = @"
using System;
using System.Threading.Tasks;
namespace CompilerCrashRepro2
{
public class Item<T>
{
public T Value { get; set; }
}
public class Crasher
{
public static void Main()
{
var r = Build<int>()().Result.Value;
System.Console.WriteLine(r);
}
public static Func<Task<Item<T>>> Build<T>()
{
return async () => new Item<T>()
{
Value = await GetValue<T>()
};
}
public static Task<T> GetValue<T>()
{
return Task.FromResult(default(T));
}
}
}";
var comp = CreateCompilation(source, options: TestOptions.DebugExe);
CompileAndVerify(comp, expectedOutput: "0");
CompileAndVerify(comp.WithOptions(TestOptions.ReleaseExe), expectedOutput: "0");
}
[Fact]
public void AwaitInScriptExpression()
{
......
......@@ -43,6 +43,11 @@ internal sealed override SynthesizedLocalKind SynthesizedKind
get { return SynthesizedLocalKind.UserDefined; }
}
internal sealed override LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
{
throw ExceptionUtilities.Unreachable;
}
internal sealed override bool IsImportedFromMetadata
{
get { return true; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册