Skip to content

Commit

Permalink
Add line info in IL2001 and IL2002 (dotnet/linker#2041)
Browse files Browse the repository at this point in the history
* Add line info in IL2001 and IL2002

* Update test

* PR feedback

* Preserve fields and methods

Commit migrated from dotnet/linker@8f1fc25
  • Loading branch information
mateoatr authored May 19, 2021
1 parent b81f296 commit 2917fc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/tools/illink/src/linker/Linker.Steps/DescriptorMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,21 @@ protected override void ProcessType (TypeDefinition type, XPathNavigator nav)
Debug.Assert (ShouldProcessElement (nav));

TypePreserve preserve = GetTypePreserve (nav);
if (preserve != TypePreserve.Nothing)
switch (preserve) {
case TypePreserve.Fields when !type.HasFields:
LogWarning ($"Type {type.GetDisplayName ()} has no fields to preserve", 2001, nav);
break;

case TypePreserve.Methods when !type.HasMethods:
LogWarning ($"Type {type.GetDisplayName ()} has no methods to preserve", 2002, nav);
break;

case TypePreserve.Fields:
case TypePreserve.Methods:
case TypePreserve.All:
_context.Annotations.SetPreserve (type, preserve);
break;
}

bool required = IsRequired (nav);
ProcessTypeChildren (type, nav, required);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Mono.Linker.Tests.Cases.LinkXml
[SetupLinkerDescriptorFile ("LinkXmlErrorCases.xml")]
[SetupLinkerArgument ("--skip-unresolved", "true")]

[ExpectedWarning ("IL2001", "TypeWithNoFields", FileName = "LinkXmlErrorCases.xml", SourceLine = 3, SourceColumn = 6)]
[ExpectedWarning ("IL2002", "TypeWithNoMethods", FileName = "LinkXmlErrorCases.xml", SourceLine = 4, SourceColumn = 6)]
[ExpectedWarning ("IL2007", "NonExistentAssembly", FileName = "LinkXmlErrorCases.xml", SourceLine = 47, SourceColumn = 4)]
[ExpectedWarning ("IL2008", "NonExistentType", FileName = "LinkXmlErrorCases.xml", SourceLine = 6, SourceColumn = 6)]
[ExpectedWarning ("IL2009", "NonExistentMethod", "TypeWithNoMethods", FileName = "LinkXmlErrorCases.xml", SourceLine = 9, SourceColumn = 8)]
Expand All @@ -28,14 +30,12 @@ public static void Main ()
}

[Kept]
[ExpectedWarning ("IL2001", "TypeWithNoFields")]
class TypeWithNoFields
{
private void Method () { }
}

[Kept]
[ExpectedWarning ("IL2002", "TypeWithNoMethods")]
struct TypeWithNoMethods
{
}
Expand Down

0 comments on commit 2917fc8

Please sign in to comment.