C# 14.5.5.1: what means "all methods declared in a base type of T are removed"?

A

Alex Sedow

Method invocation will consist of the following steps:

1. Member lookup (14.3) - evaluate method group set (Base.f() and
Derived.f()) .Standart say:
"The compile-time processing of a method invocation of the form M(A), where
M is a method group and A is
an optional argument-list, consists of the following steps:
 The set of candidate methods for the method invocation is constructed.
Starting with the set of methods
associated with M, which were found by a previous member lookup (14.3),
...."

2. Remove non-applicable methods and methods of base classes. In this
example both Base.f() and Derived.f() are applicable. Standart say:
"... the set is reduced to those
methods that are applicable with respect to the argument list A. The set
reduction consists of applying
the following rules to each method T.N in the set, where T is the type in
which the method N is declared:
If N is not applicable with respect to A (14.4.2.1), then N is removed from
the set.
If N is applicable with respect to A (14.4.2.1), then all methods declared
in a base type of T are removed
from the set."

But what mean words "then all methods declared in a base type of T are
removed from the set"? If all methods must be removed than test() method in
example must invoke Derived.f(), but MSVC# invoke Base.f(). Why? Any
suggestions.

class Source
{
static public implicit operator Target ( Source source )
{ return new Target(); }
}

class Target
{}

class Base
{
public void f ( Source source )
{}
}

class Derived : Base
{
public void f ( Target target ) // this function is applicable
(user-defined implicit conversion used)
{}

public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?
}
}

Alex.
 
M

mikeb

Alex said:
Method invocation will consist of the following steps:

1. Member lookup (14.3) - evaluate method group set (Base.f() and
Derived.f()) .Standart say:
"The compile-time processing of a method invocation of the form M(A), where
M is a method group and A is
an optional argument-list, consists of the following steps:
 The set of candidate methods for the method invocation is constructed.
Starting with the set of methods
associated with M, which were found by a previous member lookup (14.3),
..."

2. Remove non-applicable methods and methods of base classes. In this
example both Base.f() and Derived.f() are applicable. Standart say:
"... the set is reduced to those
methods that are applicable with respect to the argument list A. The set
reduction consists of applying
the following rules to each method T.N in the set, where T is the type in
which the method N is declared:
If N is not applicable with respect to A (14.4.2.1), then N is removed from
the set.
If N is applicable with respect to A (14.4.2.1), then all methods declared
in a base type of T are removed
from the set."

But what mean words "then all methods declared in a base type of T are
removed from the set"? If all methods must be removed than test() method in
example must invoke Derived.f(), but MSVC# invoke Base.f(). Why? Any
suggestions.

class Source
{
static public implicit operator Target ( Source source )
{ return new Target(); }
}

class Target
{}

class Base
{
public void f ( Source source )
{}
}

class Derived : Base
{
public void f ( Target target ) // this function is applicable
(user-defined implicit conversion used)
{}

public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?
}
}

In my test, Derived.test() invokes Derived.f().
 
R

Robert Jordan

Alex said:
Method invocation will consist of the following steps:

1. Member lookup (14.3) - evaluate method group set (Base.f() and
Derived.f()) .Standart say:
"The compile-time processing of a method invocation of the form M(A), where
M is a method group and A is
an optional argument-list, consists of the following steps:
 The set of candidate methods for the method invocation is constructed.
Starting with the set of methods
associated with M, which were found by a previous member lookup (14.3),
..."

2. Remove non-applicable methods and methods of base classes. In this
example both Base.f() and Derived.f() are applicable. Standart say:
"... the set is reduced to those
methods that are applicable with respect to the argument list A. The set
reduction consists of applying
the following rules to each method T.N in the set, where T is the type in
which the method N is declared:
If N is not applicable with respect to A (14.4.2.1), then N is removed from
the set.
If N is applicable with respect to A (14.4.2.1), then all methods declared
in a base type of T are removed
from the set."

But what mean words "then all methods declared in a base type of T are
removed from the set"? If all methods must be removed than test() method in
example must invoke Derived.f(), but MSVC# invoke Base.f(). Why? Any
suggestions.

class Source
{
static public implicit operator Target ( Source source )
{ return new Target(); }
}

class Target
{}

class Base
{
public void f ( Source source )
{}
}

class Derived : Base
{
public void f ( Target target ) // this function is applicable
(user-defined implicit conversion used)
{}

That's not true. The convertion is applied when you
call the method. So you still have 2 distinct methods:

f(Source)
f(Target)
public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?

because f(Source) is still visible and it is the best match.

Bye
Rob
 
A

Alex Sedow

Robert Jordan said:
That's not true. The convertion is applied when you
call the method. So you still have 2 distinct methods:

f(Source)
f(Target)


because f(Source) is still visible and it is the best match.

Bye
Rob

I not there have seen.
f ( source ) invoke Derived.f().

Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top