Skip to content

AOT/analyzer should not warn for MakeGenericType of reference type #97408

@sbomer

Description

@sbomer
  • MakeGenericType over reference types is supported in native AOT, so the following should not warn:
void Foo(Type t) {
    if (!t.IsValueType)
        typeof(G<>).MakeGenericType(t); // currently warns with IL3050
}
  • Probably the class constraint should be supported as well:
void Foo<T>() where T : class {
    typeof(G<>).MakeGenericType(typeof(T));
}
  • We may also want to introduce an annotation to propagate the fact that a type is a reference type across methods, for example:
void Foo(Type t) {
    if (!t.IsValueType)
        Bar(t);
}

void Bar([ReferenceType] Type t) {
    typeof(G<>).MakeGenericType(t);
}

(The latter idea is something that has come up in discussion with @vitek-karas and @MichalStrehovsky, not sure if there's another tracking issue for it already.)

Context: https://github.com/dotnet/maui/pull/20058/files/7f4d26ca0aee7dc9d995e9776573125b35ad44b6#r1463169163

Metadata

Metadata

Assignees

Labels

area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions