Skip to content

Commit

Permalink
Merge pull request #12999 from jcouv/replay-89be981
Browse files Browse the repository at this point in the history
Don't run the IteratorRewriter on BaseMethodWrapperSymbols (#12676)
  • Loading branch information
Pilchie authored Aug 8, 2016
2 parents 8c6bc98 + 151f875 commit eb964d4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,15 @@ internal override void AddSynthesizedAttributes(ModuleCompilationState compilati

AddSynthesizedAttribute(ref attributes, this.DeclaringCompilation.TrySynthesizeAttribute(WellKnownMember.System_Diagnostics_DebuggerHiddenAttribute__ctor));
}

internal override TypeSymbol IteratorElementType
{
get
{
// BaseMethodWrapperSymbol should not be rewritten by the IteratorRewriter
return null;
}
}
}
}
}
68 changes: 68 additions & 0 deletions src/Compilers/CSharp/Test/Semantic/Semantics/IteratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,73 @@ public void TopLevelYieldBreak()
Assert.NotNull(yieldNode);
Assert.Equal(SyntaxKind.YieldBreakStatement, yieldNode.Kind());
}

[Fact]
[WorkItem(11649, "https://github.com/dotnet/roslyn/issues/11649")]
public void IteratorRewriterShouldNotRewriteBaseMethodWrapperSymbol()
{
var text =
@"using System.Collections.Generic;
class Base
{
protected virtual IEnumerable<int> M()
{
yield break;
}
class D : Base
{
protected override IEnumerable<int> M()
{
base.M(); // the rewriting of D.M() synthesizes a BaseMethodWrapperSymbol for this base call, with return type IEnumerable,
// but it should not in turn be lowered by the IteratorRewriter
yield break;
}
}
}";
var comp = CreateCompilationWithMscorlib(text, options: TestOptions.DebugDll);
comp.VerifyEmitDiagnostics(); // without the fix for bug 11649, the compilation would fail emitting
CompileAndVerify(comp);
}

[Fact]
[WorkItem(11649, "https://github.com/dotnet/roslyn/issues/11649")]
public void IteratorRewriterShouldNotRewriteBaseMethodWrapperSymbol2()
{
var source =
@"using System.Collections.Generic;
class Base
{
public static void Main()
{
System.Console.WriteLine(string.Join("","", new D().M()));
}
protected virtual IEnumerable<int> M()
{
yield return 1;
yield return 2;
yield break;
}
class D : Base
{
protected override IEnumerable<int> M()
{
yield return 0;
foreach (var n in base.M())
{
yield return n;
}
yield return 3;
yield break;
}
}
}";
var comp = CompileAndVerify(source, expectedOutput: "0,1,2,3", options: TestOptions.DebugExe);
comp.Compilation.VerifyDiagnostics();
}
}
}

0 comments on commit eb964d4

Please sign in to comment.