diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/Dependencies/OverrideOfAbstractIsKeptNonEmptyLibrary.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/Dependencies/OverrideOfAbstractIsKeptNonEmptyLibrary.cs new file mode 100644 index 000000000000..cfa09483d87b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/Dependencies/OverrideOfAbstractIsKeptNonEmptyLibrary.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.Dependencies +{ + public class OverrideOfAbstractIsKeptNonEmpty_UnusedType + { + } + + public abstract class OverrideOfAbstractIsKeptNonEmpty_BaseType + { + public abstract void Method (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/Dependencies/OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/Dependencies/OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty.cs new file mode 100644 index 000000000000..e7a10c647622 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/Dependencies/OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.Dependencies +{ + public class OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty : + OverrideOfAbstractIsKeptNonEmpty_BaseType + { + Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field; + + public override void Method () + { + _field = null; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKeptNonEmpty.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKeptNonEmpty.cs index b2a3d5f2b048..fe5c42066ed7 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKeptNonEmpty.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKeptNonEmpty.cs @@ -4,12 +4,27 @@ namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { [SetupLinkerArgument ("--enable-opt", "unreachablebodies")] + + // The order is important - since the bug this uncovers depends on order of processing of assemblies in the sweep step + [SetupCompileBefore ("library.dll", new[] { "Dependencies/OverrideOfAbstractIsKeptNonEmptyLibrary.cs" })] + [SetupCompileBefore ( + "librarywithnonempty.dll", + new[] { "Dependencies/OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty.cs" }, + new[] { "library.dll" })] + + [KeptAssembly ("library.dll")] + [KeptAssembly ("librarywithnonempty.dll")] + [RemovedTypeInAssembly("library.dll", typeof(Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType))] + public class OverrideOfAbstractIsKeptNonEmpty { public static void Main () { Base b = HelperToMarkFooAndRequireBase (); b.Method (); + + Dependencies.OverrideOfAbstractIsKeptNonEmpty_BaseType c = HelperToMarkLibraryAndRequireItsBase (); + c.Method (); } [Kept] @@ -18,6 +33,12 @@ static Foo HelperToMarkFooAndRequireBase () return null; } + [Kept] + static Dependencies.OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty HelperToMarkLibraryAndRequireItsBase () + { + return null; + } + [Kept] abstract class Base { @@ -41,11 +62,14 @@ abstract class Base3 : Base2 [KeptBaseType (typeof (Base3))] class Foo : Base3 { + Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field; + [Kept] [ExpectBodyModified] public override void Method () { Other (); + _field = null; } static void Other ()