Skip to content

Trim analyzer doesn't warn on GetType().GetMethods() #86921

Closed

Description

@agocke

The following doesn't seem to produce an analyzer warning:

class C
{
    public static void Main()
    {
        M("abc");
    }
    public static void M(object o)
    {
        var methods = o.GetType().GetMethods();
    }
}

Activity

  1. ghost added
    untriaged
    on May 30, 2023
  2. added
    area-Tools-ILLink
    and removed
    untriaged
    on May 30, 2023
  3. added this to the 8.0.0 milestone on May 30, 2023
  4. vitek-karas commented on May 31, 2023

    @vitek-karas
    Member

    There are two parts to this:

    One is that we haven't implemented type hierarchy annotations in the analyzer at all yet. That said implementing the object.GetType() is definitely the simple part - implementing full type hierarchy marking diagnostics is much more work. But the two could be done separatly.

    Second is that analyzer has a different philosophy to trimmer and ilc. The design is such that if the analyzer doesn't know about something, it will NOT warn about it. Which is the opposite of trimmer and ilc both of which would warn as soon as they hit something they can't reason about. This is intentional to avoid producing warnings from the analyzer which are later on NOT reported by the trimmer/ilc and thus just confusing.
    This was very important during analyzer bring up, as we didn't want to produce tons of warnings just because the analyzer didn't implement some specific behavior yet.
    This specific case is an example of such case (what if the call is OK, without implementing the logic the analyzer would always warn about it).

    Maybe it's about time we change the policy - given that analyzer is almost on par with trimmer now.

    That said, there are (and always will be) cases where the analyzer can't produce the same warnings because it doesn't have a full program view. These should be rare, but they will always exist. Hopefully if we switch the policy these cases won't start to show up as extra noise (and only as missing warnings, which there are already quite a few).

  5. modified the milestones: 8.0.0, 9.0.0 on Sep 1, 2023
  6. ghost added
    in-pr
    on Oct 19, 2023
  7. ghost removed
    in-pr
    on Nov 1, 2023
  8. ghost locked as resolved and limited conversation to collaborators on Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions