Skip to content

Generic delegate construction isn't marked as unnecessary with overloads #1254

Description

@SLaks

Source:

var s = new Socket(new SocketInformation());
Task.Factory.FromAsync(s.BeginAccept, s.EndAccept, null);
Task.Factory.FromAsync(new Func<AsyncCallback, object, IAsyncResult>(s.BeginAccept), s.EndAccept, null);

The last two lines bind to the same methods, but the delegate construction isn't marked as unnecessary.

Activity

  1. added this to the milestone on Mar 26, 2015
  2. modified the milestones: 1.0 (stable), on Mar 26, 2015
  3. mavasani commented on Apr 1, 2015

    @mavasani
    Contributor

    @SLaks this is by design, or rather an unsupported simplification.

    Our cast simplifier currently tries to detect unnecessary explicit casts, but doesn't deal with trying to detect redundant invocation expressions, which would be semantically equivalent via an implicit conversion in the simplified code. Note that implementing such a simplifier would be no trivial as there is no easy way to determine if the implicit conversion is equivalent to invoking a specific method/constructor.

  4. SLaks commented on Apr 1, 2015

    @SLaks
    ContributorAuthor

    I'm only talking about delegate constructors, which (I think?) should always be semantically equivalent to an explicit cast.

    How is this harder?

  5. mavasani commented on Apr 18, 2015

    @mavasani
    Contributor

    @srivatsn this is basically a mini-feature request for simplifying redundant object creation expressions for delegates. We would need to add a new simplifier to deal with object creation expression.

  6. removed their assignment
    on Apr 18, 2015
  7. modified the milestones: , 1.0 (stable) on Apr 18, 2015
  8. removed
    Resolution-By DesignThe behavior reported in the issue matches the current design
    on Apr 18, 2015
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

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions