diff options
author | Sven Boemer <sbomer@gmail.com> | 2022-02-24 23:23:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-24 23:23:41 +0300 |
commit | e9cfb5413a6a7a7b5bfc3b9a73671be2b18642cf (patch) | |
tree | d586fc27196a0d8ddf916cab704f74ccc55dae03 | |
parent | 74d69676a9b4fa7022f8bdaf5a574e7063d8c9a1 (diff) |
Fix invalid cast of type parameter (#2643)darc-release/6.0.2xx-e41dfdf1-4206-46d4-8291-d43fda61dd29darc-release/6.0.2xx-a5d6e3d9-4f6e-4daf-afc1-cb773cc0bec7darc-release/6.0.2xx-2663cc0a-439b-4ea0-a70c-c7fd96f1eb4fdarc-release/6.0.2xx-1774e2a9-b600-4f69-a509-772b749afdb0darc-release/6.0.2xx-091aeeb5-bd98-49e5-9813-9b4179462b79
-rw-r--r-- | src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs | 4 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs index d52bc04bd..aff22c907 100644 --- a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs +++ b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs @@ -172,10 +172,10 @@ namespace ILLink.RoslynAnalyzer for (int i = 0; i < typeParams.Length; i++) { var typeParam = typeParams[i]; var typeArg = typeArgs[i]; - if (!typeParam.HasConstructorConstraint) + if (!typeParam.HasConstructorConstraint || + typeArg is not INamedTypeSymbol { InstanceConstructors: { } typeArgCtors }) continue; - var typeArgCtors = ((INamedTypeSymbol) typeArg).InstanceConstructors; foreach (var instanceCtor in typeArgCtors) { if (instanceCtor.Arity > 0) continue; diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs index 482ff2de1..cc5f3b373 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -748,9 +748,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability var _ = new Action (GenericWithStaticMethod<TestType>.GenericTypeWithStaticMethodWhichRequires); } + static T MakeNew<T> () where T : new() => new T (); + static T MakeNew2<T> () where T : new() => MakeNew<T> (); + public static void Test () { GenericTypeWithStaticMethodViaLdftn (); + MakeNew2<TestType> (); } } |