History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-54149
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Ilya Ryzhenkov
Reporter: Vladimir Reshetnikov
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
ReSharper

'Convert foreach to for' forgets to insert explicit cast

Created: 07 Dec 07 17:27   Updated: 13 Mar 08 22:38
Component/s: Generate Action
Fix Version/s: 4.0
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 573


 Description  « Hide
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] xs = {1,2};
        List<byte> bs = new List<byte>();

        foreach (byte x in xs)
        { 
            bs.Add(x);
        }
    }
}

This code is OK. Apply 'Convert foreach to for'. Result:

using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] xs = {1,2};
        List<byte> bs = new List<byte>();

        for (int i = 0; i < xs.Length; i++)
        {
            byte x = xs[i]; // error CS0266: Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
            bs.Add(x);
        }
    }
}

Expected:

using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] xs = {1,2};
        List<byte> bs = new List<byte>();

        for (int i = 0; i < xs.Length; i++)
        {
            byte x = (byte) xs[i]; // OK
            bs.Add(x);
        }
    }
}


 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.