Skip to content

Commit da412ca

Browse files
authored
Add a test for #2358 (#2369)
Currently this causes a crash in the linker due to null location scope.
1 parent d74c97b commit da412ca

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<linker>
3+
<assembly fullname="test" />
4+
</linker>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Mono.Linker.Tests.Cases.LinkAttributes.Dependencies
5+
{
6+
public static class Used
7+
{
8+
public static void Use () { }
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<linker>
3+
<assembly fullname="*">
4+
<type fullname="Mono.Linker.Tests.Cases.LinkAttributes.AttributeToRemoveAttribute">
5+
<attribute internal="RemoveAttributeInstances"/>
6+
</type>
7+
</assembly>
8+
</linker>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using Mono.Linker.Tests.Cases.Expectations.Assertions;
6+
using Mono.Linker.Tests.Cases.Expectations.Metadata;
7+
using Mono.Linker.Tests.Cases.LinkAttributes.Dependencies;
8+
9+
namespace Mono.Linker.Tests.Cases.LinkAttributes
10+
{
11+
[IgnoreDescriptors (false)]
12+
13+
// The test verifies that removed attributes which are later on kept due to descriptors correctly warn.
14+
// The setup is:
15+
// - test assembly with the AttributeToRemoveAttribute type
16+
// - link attributes.xml which marks the attribute for removal (applied early, in this case via command line, but could be a embedded in the test assembly)
17+
// - the attribute is used by the test assembly
18+
// - another assembly lib.dll is added and is referenced (after the attribute is used/marked)
19+
// - This new assembly has a descriptor which marks the entire test assembly (note that it marks the TEST assembly)
20+
// - This marking causes the warning, as it's an explicit request to keep the attribute which was supposed to be removed
21+
22+
[SetupLinkAttributesFile ("LinkerAttributeRemovalAndPreserveAssembly.LinkAttributes.xml")]
23+
24+
[SetupCompileBefore (
25+
"lib.dll",
26+
new[] { "Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.cs" })]
27+
// https://github.com/dotnet/linker/issues/2358 - adding the descriptor currently causes nullref in the linker
28+
// resources: new object[] { new string[] { "Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.Descriptor.xml", "ILLink.Descriptors.xml" } })]
29+
30+
[ExpectedNoWarnings]
31+
32+
class LinkerAttributeRemovalAndPreserveAssembly
33+
{
34+
public static void Main ()
35+
{
36+
TestAttributeRemoval ();
37+
}
38+
39+
[AttributeToRemoveAttribute]
40+
[Kept]
41+
static void TestAttributeRemoval ()
42+
{
43+
Used.Use ();
44+
}
45+
}
46+
47+
public class AttributeToRemoveAttribute : Attribute { }
48+
}

0 commit comments

Comments
 (0)