I've just upgraded to VS2015.1 and got a compiler crash when trying to compile one of my projects. If you put the following repo code in a console application (and add a reference to moq.dll) the code in line 12 crashes my compiler. It seems to happen during a Roslyn lamdba rewrite call.
using System.Collections.Generic;
using System.Linq;
using Moq;
namespace RoslynError
{
class Program
{
static void Main(string[] args)
{
var mockRepo = new MockRepository(MockBehavior.Strict);
var obj = mockRepo.OneOf<DTO>(x => x.Value == (OptionEnum?)null);
}
}
class DTO
{
public DTO(OptionEnum? enumVal)
{
Value = enumVal;
}
public OptionEnum? Value;
}
enum OptionEnum
{
NotSpecified
}
}
Anyone know why the crash occurs?
The following simpler example also reproduces the problem, which is related to rewriting type conversion nodes in expression trees:
using System;
using System.Linq.Expressions;
namespace Bug461
{
class Program
{
enum Test { }
static void Main()
{
Expression<Func<Test?, bool>> x = t => t == (Test?)null;
}
}
}
Edit: I edited the code slightly to avoid a warning.
Edit 2: The bug is caused by https://github.com/dotnet/roslyn/commit/5c602fc6 where the demoted enum operand (which is the null literal) doesn't have an associated type.
Edit 3: I made a pull request with a proposed fix: https://github.com/dotnet/roslyn/pull/7227
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With