Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Analyzer - support unknown values for some untracked values #2755

Closed

Description

@vitek-karas

Currently the analyzer only tracks values which are "interesting", which really means System.Type or System.String. Both of these can carry DAM annotations. Everything is not tracked and flows through the system as TopValue which means "empty".

In some cases though, the intrinsic handling works with other types of values, for example integers or arrays. Analyzer has some basic handling of integers mostly around constants and some basic handling of arrays when created locally. But it doesn't track "unknown" values, instead it tracks the rest as "empty" value.

"empty" value means that it will not cause warnings (that's the purpose of the value), unlike "unknown" which typically produces warnings as it represents "can't figure this our statically".

This means that for example code like this:

class MyOwnGeneric<[DAM(All)] T> { }

static void MakeMyOwnGeneric(Type[] types)
{
     typeof(MyOwnGeneric).MakeGenericType(types); // No warning in the analyzer, linker warns
}

In this case analyzer doesn't warn because the parameter to MakeGenericType is "empty" value, and so the entire call is effectively ignored. Linker warns, because it knows that the type has requirements on the generic parameters, and thus if it can't figure out the generic arguments it needs to warn.

Activity

  1. vitek-karas commented on Apr 22, 2022

    @vitek-karas
    MemberAuthor
    class MyOwnGeneric<[DAM(All)] T> { }
    
    static void MakeMyOwnGeneric(int length)
    {
         var types = new Type[length]; // Since length is unknown the array should be either treated as unknown as a whole, or at least its size should be as such
         types[0] = typeof(TestType);
         typeof(MyOwnGeneric).MakeGenericType(types); // No warning in the analyzer, linker warns
    }

    Currently since the length is treated as "empty", the value of the array creation is also "empty" -> no warnings.

  2. vitek-karas commented on Apr 22, 2022

    @vitek-karas
    MemberAuthor

    I'm going to add method tracking as well - similar scenario for MethodInfo values:

    void GenericMethod<[DAM(All)] T>() {}
    
    static void MakeItAGeneric(MethodInfo method)
    {
        method.MakeGenericMethod(typeof(TestType));  // linker warns, analyzer doesn't
    }

    Same reason - the untracked value is considered "empty" (unlike linker where it's "unknown").

  3. changed the title [-]Analyzer - support unknown values for arrays[/-] [+]Analyzer - support unknown values for some untracked values[/+] on Apr 22, 2022
  4. added this to the Future milestone on Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions