Boo

Method overloading dose not work as expected when using Clr extension methods

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not A Bug
  • Affects Version/s: 0.8.2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

The method overloading with Clr extension methods dose not work like expected in the following case:

I i have an class which have a method of parameter object. Now i want to extend this class with an extension method of the parameter string. When i now call this method, the original method is called instead of the string extension method.

This works if booth methods are Extension methods.

Attached a failing testcase for this issue.

Issue Links

Activity

Hide
Avishay Lavie added a comment -

This is by design, and in compliance with C#: Extension methods are only checked if there are no matching methods on the invoked type.

public static class MyExtensions
{
	public static string Method(this MyClass c, string s)
	{
		return "EXTENSION";
	}
}

public class MyClass
{
	public string Method(object o)
	{
		return "Original";
	}
	
	public static void Main()
	{
		Console.WriteLine(new MyClass().Method("abc"));
	}
}

> csc test.cs
> test.exe
Original
Show
Avishay Lavie added a comment - This is by design, and in compliance with C#: Extension methods are only checked if there are no matching methods on the invoked type.
public static class MyExtensions
{
	public static string Method(this MyClass c, string s)
	{
		return "EXTENSION";
	}
}

public class MyClass
{
	public string Method(object o)
	{
		return "Original";
	}
	
	public static void Main()
	{
		Console.WriteLine(new MyClass().Method("abc"));
	}
}

> csc test.cs
> test.exe
Original
Hide
Steve Wagner added a comment -

Ok i dont tryed it with c# because i dont estimate this behavior and i think it is a bad design decision.

Thanks for locking at it.

Show
Steve Wagner added a comment - Ok i dont tryed it with c# because i dont estimate this behavior and i think it is a bad design decision. Thanks for locking at it.
Hide
Avishay Lavie added a comment -

I agree with you, this does seem a little awkward. However I'm not sure it'd be a good idea to deviate from this behavior. Perhaps some of the other devs would like to comment on this.

Show
Avishay Lavie added a comment - I agree with you, this does seem a little awkward. However I'm not sure it'd be a good idea to deviate from this behavior. Perhaps some of the other devs would like to comment on this.
Hide
Steve Wagner added a comment -

As longer i think about i turns out that this behavior inst as bad as it looks like.

If this works, i could very easy be defect my code because after the creation of the extension method my existing code calls the extension method with my change.

Show
Steve Wagner added a comment - As longer i think about i turns out that this behavior inst as bad as it looks like. If this works, i could very easy be defect my code because after the creation of the extension method my existing code calls the extension method with my change.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: