-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ILLink: Add test for dataflow in local method group passed as argumen…
…t to delegate Adds a test for issue #95258 which passes without any source code fix.
- Loading branch information
1 parent
8b1d06a
commit 28d35bd
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/DataflowInLocalMethodGroupArgument.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,66 @@ | ||
// 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; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Helpers; | ||
|
||
namespace Mono.Linker.Tests.Cases.DataFlow | ||
{ | ||
[ExpectedNoWarnings] | ||
[SkipKeptItemsValidation] | ||
public class DataflowInLocalMethodGroupArgument | ||
{ | ||
public static void Main () | ||
{ | ||
new GenericWithNonPublicConstructors<int> ().Test (); | ||
GenericWithNonPublicConstructors<int>.TestInstanceLocalMethod (); | ||
} | ||
|
||
public class GenericWithNonPublicConstructors<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] T> | ||
{ | ||
public void Test () | ||
{ | ||
[ExpectedWarning ("IL2087", "PublicFields", "RequiresPublicFields", "T", "GenericWithNonPublicConstructors")] | ||
static int GetIntWithBadDataflow (int x) | ||
{ | ||
typeof (T).RequiresPublicFields(); | ||
return 0; | ||
} | ||
|
||
new Dictionary<int, int> ().GetOrAdd (0, GetIntWithBadDataflow); | ||
} | ||
|
||
public static void TestInstanceLocalMethod () | ||
{ | ||
[ExpectedWarning ("IL2087", "PublicFields", "RequiresPublicFields", "T", "GenericWithNonPublicConstructors")] | ||
int GetIntWithBadDataflow (int x) | ||
{ | ||
typeof (T).RequiresPublicFields(); | ||
return 0; | ||
} | ||
|
||
new Dictionary<int, int> ().GetOrAdd (0, GetIntWithBadDataflow); | ||
} | ||
} | ||
} | ||
|
||
public static class DictionaryExtensions | ||
{ | ||
public static TValue GetOrAdd<TKey, TValue> (this Dictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory) | ||
{ | ||
if (dictionary.TryGetValue (key, out var value)) | ||
return value; | ||
|
||
value = valueFactory (key); | ||
dictionary.TryAdd (key, value); | ||
return value; | ||
} | ||
} | ||
} |