Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for #2260 #2263

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 ();
}
}
Original file line number Diff line number Diff line change
@@ -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 :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm not sure what the "non-empty" in NonEmptyLibrary or WithNonEmpty refer to - maybe the names could be simplified?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to keep the names starting with the name of the test - so that it's easy to tell which dependencies belong to which test.

OverrideOfAbstractIsKeptNonEmpty_BaseType
{
Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field;

public override void Method ()
{
_field = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,34 @@
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")]

// Uncomment after this bug is fixed
// https://github.com/mono/linker/issues/2260
//[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 ();

// Remove after this bug is fixed
// https://github.com/mono/linker/issues/2260
new Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType ();
}

[Kept]
Expand All @@ -18,6 +40,12 @@ static Foo HelperToMarkFooAndRequireBase ()
return null;
}

[Kept]
static Dependencies.OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty HelperToMarkLibraryAndRequireItsBase ()
{
return null;
}

[Kept]
abstract class Base
{
Expand All @@ -41,11 +69,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 ()
Expand Down