none
Bug in 1.4.40602.0 when Generic and Non-Generic method have the same name and parameters

    Question

  • The Contracts for the Generic method is getting lost and does not show up in the IL.  Below is a code example.  If you just removed the non-generic from the interface then the generic contract works as expected.  But with the non-generic in place the generic contract is getting lost in the re-write.

     

    [ContractClass(typeof(IContractTestContract))]
    interface IContractTest
    {
    	string TestMethod(string arg);
    	T TestMethod<T>(string arg);
    }
    [ContractClassFor(typeof(IContractTest))]
    abstract class IContractTestContract : IContractTest
    {
    	public string TestMethod(string arg)
    	{
    		Contract.Requires(!String.IsNullOrEmpty(arg));
    		throw new NotImplementedException();
    	}
    	public T TestMethod<T>(string arg)
    	{
    		Contract.Requires(!String.IsNullOrEmpty(arg));
    		throw new NotImplementedException();
    	}
    }
    class ContractTest : IContractTest
    {
    	public string TestMethod(string arg) { return null; }
    	public T TestMethod<T>(string arg) { return default(T); }
    }
    class Program
    {
    	static void Main(string[] args)
    	{
    		var c = new ContractTest();
    		//Does not fail static or runtime checks
    		//Contract is getting lost
    		c.TestMethod<string>(null);
    	}
    }
    
    

     

     

    These are my settings for code contracts

    • Edited by AceHack Friday, December 09, 2011 6:57 PM Added more info
    Friday, December 09, 2011 6:52 PM