Skip to content

Instantly share code, notes, and snippets.

@SergeyTeplyakov
Last active August 29, 2015 14:04
Show Gist options
  • Save SergeyTeplyakov/3b8e805faeff06f7b701 to your computer and use it in GitHub Desktop.
Save SergeyTeplyakov/3b8e805faeff06f7b701 to your computer and use it in GitHub Desktop.
Nasty Code Contract bug
class CornerCaseSample
{
private readonly Lazy<int> _lazy;
public CornerCaseSample(string s)
{
// Any issues with this code?
Contract.Requires(s != null);
_lazy = new Lazy<int>(() => s.Length);
}
}
class Program
{
static void Main(string[] args)
{
var sample = new CornerCaseSample("foo");
Console.WriteLine("All fine!");
}
}
// Decompliled version of CornerCaseSample
class CornerCaseSampleImpl
{
public CornerCaseSampleImpl(string s)
{
CornerCaseSample_<>c__DisplayClass0_0 class_ = new CornerCaseSample_<>c__DisplayClass0_0();
__ContractsRuntime.Requires(class_.s > null, null, "s != null");
<>c__DisplayClass0 class2 = new <>c__DisplayClass0();
class2.s = s;
this._lazy = new Lazy<int>(new Func<int>(class2.<.ctor>b__2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment