forked from dotnet/linker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for dotnet#3112 with pseudo-circular reference when bas…
…e provides iface method (dotnet#3120) Add test case for dotnet#3112 with pseudo-circular reference with ifaces Commit migrated from dotnet@2172c79
- Loading branch information
1 parent
4eaa85d
commit 64988c9
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
....Interfaces/BaseProvidesInterfaceEdgeCase/BaseProvidesInterfaceMethodCircularReference.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
using Mono.Linker.Tests.Cases.Inheritance.Interfaces.BaseProvidesInterfaceEdgeCase.Dependencies; | ||
|
||
namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.BaseProvidesInterfaceEdgeCase | ||
{ | ||
/// <summary> | ||
/// Reproduces the issue found in https://github.com/dotnet/linker/issues/3112. | ||
/// <see cref="Derived1"/> derives from <see cref="Base"/> and uses <see cref="Base"/>'s method to implement <see cref="IFoo"/>, | ||
/// creating a psuedo-circular assembly reference (but not quite since <see cref="Base"/> doesn't implement IFoo itself). | ||
/// In the linker, IsMethodNeededByInstantiatedTypeDueToPreservedScope would iterate through <see cref="Base"/>'s method's base methods, | ||
/// and in the process would trigger the assembly of <see cref="IFoo"/> to be processed. Since that assembly also has <see cref="Derived2"/> that | ||
/// inherits from <see cref="Base"/> and implements <see cref="IBar"/> using <see cref="Base"/>'s methods, the linker adds | ||
/// <see cref="IBar"/>'s method as a base to <see cref="Base"/>'s method, which modifies the collection as it's being iterated, causing an exception. | ||
/// </summary> | ||
[SetupCompileBefore ("base.dll", new[] { "Dependencies/Base.cs" })] // Base Implements IFoo.Method (psuedo-reference to ifoo.dll) | ||
[SetupCompileBefore ("ifoo.dll", new[] { "Dependencies/IFoo.cs" }, references: new[] { "base.dll" })] // Derived2 references base.dll (circular reference) | ||
[SetupCompileBefore ("derived1.dll", new[] { "Dependencies/Derived1.cs" }, references: new[] { "ifoo.dll", "base.dll" })] | ||
public class BaseProvidesInterfaceMethodCircularReference | ||
{ | ||
[Kept] | ||
public static void Main () | ||
{ | ||
_ = new Derived1 (); | ||
Foo (); | ||
} | ||
|
||
[Kept] | ||
public static void Foo () | ||
{ | ||
((IFoo) null).Method (); | ||
object x = null; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ker.Tests.Cases/Inheritance.Interfaces/BaseProvidesInterfaceEdgeCase/Dependencies/Base.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.BaseProvidesInterfaceEdgeCase.Dependencies | ||
{ | ||
public class Base | ||
{ | ||
public virtual void Method () | ||
{ | ||
throw new NotImplementedException (); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...Tests.Cases/Inheritance.Interfaces/BaseProvidesInterfaceEdgeCase/Dependencies/Derived1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.BaseProvidesInterfaceEdgeCase.Dependencies | ||
{ | ||
public class Derived1 : Base, IFoo | ||
{ | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ker.Tests.Cases/Inheritance.Interfaces/BaseProvidesInterfaceEdgeCase/Dependencies/IFoo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.BaseProvidesInterfaceEdgeCase.Dependencies | ||
{ | ||
public interface IFoo | ||
{ | ||
void Method (); | ||
} | ||
public interface IBar | ||
{ | ||
void Method (); | ||
} | ||
public class Derived2 : Base, IBar | ||
{ | ||
} | ||
} |