"generic constraint inheritance" .. ?

View: New views
1 Messages — Rating Filter:   Alert me  

"generic constraint inheritance" .. ?

by Jeffery Olson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


fresh off of my last error mail to the list, here's another fun one:

public interface ISomeInterface:
  Id as int:
    get

public class ConstraintChaining:
  public def InnerMethod[of T(ISomeInterface)](foo as T) as int:
    return foo.Id;

  public def OutterMethod[of T(ISomeInterface)](foo as T) as int:
    return InnerMethod[of T](foo)

gives us:
The type 'T' must derive from 'Sandbox.ISomeInterface' in order to
substitute the generic parameter 'T' in
'Sandbox.ConstraintChaining.InnerMethod[of T](T)'.  (BCE0149) -
C:\Users\Administrator\Documents\SharpDevelop
Projects\Sandbox\ConstraintsTest.boo:28,23

the error is on the return statement in OutterMethod[of T]()

the corresponding code in C# compiles:

  public interface ISomeInterface {
    int Id {
      get; set;
    }
  }

  public class ConstraintChaining {
    public int InnerMethod<T>(T foo) where T : ISomeInterface
    {
      return foo.Id;
    }

    public int OutterMethod<T>(T foo) where T : ISomeInterface
    {
      return InnerMethod<T>(foo);
    }
  }

cheers

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---