Inspired by this question I have tried a following code on Mono 2.10.9 and Visual Studio 2010:
public class Example
{
public static void Main()
{
Foo(1);
}
public static void Foo( dynamic x )
{
Example.Bar(x);
}
static void Bar( dynamic x )
{
x++;
}
int count;
void Bar( int x )
{
count++;
}
}
As you can see, Foo
is static, so it can only access static Bar
- and I explicitly invoke the static version!
I know that I would not be able to declare static void Bar( int x )
, because a non-static version exists.
However, changing the argument type of non-static Bar
to, let's say, string, makes everything alright.
Why is that? What are the rules here? Is it possible to call the static method?
Maybe it's a Mono DLR issue?
EDIT: For clarification. I would like to know what rules turn an explicit call to static method (at least I think it's explicit) into a call to a non-static one? This is obviously impossible from static context.
Or, if there are no such rules, can it be a bug? Can this behaviour be somehow avoided?