Last active
August 29, 2015 14:04
-
-
Save SergeyTeplyakov/3b8e805faeff06f7b701 to your computer and use it in GitHub Desktop.
Nasty Code Contract bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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