ReSharper 5.0 - Invalid Context Menu Item

I noticed a small, but acknowledgable bug in the behavior of the code inspector that results in a suggestion which creates non-compilable code:

Given the following property definition:

public IEnumerable<Package> Packages {
            get {
                return Items != null && Items.Any()
                    ? Items.Select(i => i.Product).Where(p => p.IsShippable).
                        Select(p =>
                               new Package((float)p.PackagedHeight,
                                           (float)p.PackagedWidth,
                                           (float)p.PackagedLength,
                                           (float)p.PackagedWeight))
                    : null;
            }

}

Where a product's PackagedHeight, PackageWidth, PackagedLength, and PackageWeight are of type Nullable<float>, the code inspector suggests "Check if XXX is not null" on each of those fields. Selecting this suggestion, however, modifies the code like so:

public IEnumerable<Package> Packages {
            get {
                if (p.PackagedXXX != null)
                    return Items != null && Items.Any()
                               ? Items.Select(i => i.Product).Where(p => p.IsShippable).
                                     Select(p =>
                                            new Package((float)p.PackagedHeight,
                                                        (float)p.PackagedWidth,
                                                        (float)p.PackagedLength,
                                                        (float)p.PackagedWeight))
                               : null;
            }
}

Which will not compile because 'p.PackagedXXX' has no meaning outside of the context of the LINQ expression which calls it.

Not a big deal, but probably something worth validating.

1 comment
Comment actions Permalink

Hello Nathan
     I've created a bug-report in our tracker: http://youtrack.jetbrains.net/issue/RSRP-165203. Thank you!

Andrey Serebryansky

Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

Please sign in to leave a comment.