I understand about the problem in general, the original example I gave,
allowed 2 solutions, as yours does, and I wondered whether this was the
cause, the revised example allows 1 solution, and fails in the same
way...so basically you are saying type inference doesn't work in general
for such problems even when there is a unique solution....it's not the
end of the world, though I object to the error message, which implies no
such solution exists, when quite demonstrably it does...yet I've seen
other cases where I've had an error asking me to explicitly define the
types...rather than reject that a solution exists. 

At best I think the error message to be misleading and there is a
significant hole in the type inference mechanism, at worst it wouldn't
surprise me if there is a bug in there...the error would seem to imply
it thinks it's proved no solution exists, when at least one does.

Thanks for your insight, time to revisit my whole design.

> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [EMAIL PROTECTED] On Behalf Of Barry Kelly
> Sent: 28 February 2008 19:58
> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> Subject: Re: [ADVANCED-DOTNET] extensions methods and type
inference....
> 
> "Nicholls, Mark" <[EMAIL PROTECTED]> wrote:
> > [snip]
> 
> Extension methods don't do inference that can't be done by normal
method
> call inference either - the fact that the error occurs with extension
> methods is irrelevant. Calling an extension method M defined in class
C
> using the extension syntax x.M() is equivalent to trying to call it as
> C.M(x), and the equivalent transformation in your problem case has the
> same failure.
> 
> The problem isn't so much the dependency in the generic constraints,
but
> rather that the generic type arguments can't be inferred using the
> actual argument types. Your Extension.Test method is parameterized
over
> two types, but only uses one of those types in the argument list, so
the
> inference can't be completed - it's like having two variables but only
> one equation. The generic constraints aren't used in the inference
> process.
> 
> I've rewritten your case to expose why it can't be solved in general,
> too; I also changed the definition of Test<,> to distinguish between
B<>
> the generic type and B the type argument.
> 
> Here's a different version which would have ambiguous resolutions if
the
> generic constraints were actually used in the inference process:
> 
> ---8<---
> using System;
> 
> static class Program
> {
>     static void Main()
>     {
>         C t = new C();
>         t.Test();                        // #1
>         t.Test<int,C>();                 // #2
>         t.Test<string,C>();              // #3
>     }
> }
> 
> public interface B<T>
> {
> }
> 
> public class C : B<int>, B<string>
> {
> }
> 
> public static class Extension
> {
>     static public void Test<T,U>(this U self)
>         where U : B<T>
>     {
>     }
> }
> --->8---
> 
> As you can see here, there are two possible inferences (in this case)
> for T, #2 and #3.
> 
> -- Barry
> 
> --
> http://barrkel.blogspot.com/
> 
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
> 
> View archives and manage your subscription(s) at
> http://discuss.develop.com



CONFIDENTIALITY NOTICE

This e-mail (and any attached files) is confidential and protected by 
copyright (and other intellectual property rights). If you are not the 
intended recipient please e-mail the sender and then delete the email and 
any attached files immediately. Any further use or dissemination is 
prohibited.

While MTV Networks Europe has taken steps to ensure that this email and 
any attachments are virus free, it is your responsibility to ensure that 
this message and any attachments are virus free and do not affect your 
systems / data.

Communicating by email is not 100% secure and carries risks such as delay, 
data corruption, non-delivery, wrongful interception and unauthorised 
amendment. If you communicate with us by e-mail, you acknowledge and 
assume these risks, and you agree to take appropriate measures to minimise 
these risks when e-mailing us. 

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, 
Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions 
International and Comedy Central are all trading names of MTV Networks 
Europe.  MTV Networks Europe is a partnership between MTV Networks Europe 
Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain 
is UK House, 180 Oxford Street, London W1D 1DS, UK.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to