Showing posts with label bugs. Show all posts
Showing posts with label bugs. Show all posts

Wednesday, June 18, 2008

IntellSense Bug

Four days ago while I was working on LINQ I found an error of VS2008's IntellSense. After notifying it at the Microsoft Connect site, I was ready to post a comment  about this issue. Before we see how to reproduce this error I have to say that I can see it because I read Jon Skeet's C# book in the morning.

By definition, it is possible to have an extensor method of extensible type T and a static method in T that have the same signature. We should remember that an extension method is pure sintactic sugar, the this modifier makes the method get tagged with System.Runtime.CompilerServices.ExtensionAttribute if it complies with the other rules, thus, this is just a simple method.

It's in this situation where IntellSense gets confused. Let's reproduce it.

 public class A
{
public static void Method(A obj){Console.WriteLine("instance");}
public static void Foo() { }
}

public static class AHelper
{
public static void Method(this A obj) { Console.WriteLine("extension");}
}

static class Program
{
static void Main()
{
A objA = new A();
objA.Method();
Console.Read();
}
}

At the second instruction of Main method, if you activate the IntellSense's engine after you type the punctuator (".")  you will see how the Method doesn't have the expected icon, and neither does the tooltip beginning with "(extension)":



Once finnish the writing the name we could see how its now recognized as an extensions method by IntellSense:



If we erase the static method of the class, the extension method is redeemed.


See you soon bloggers :)

Bug en IntellSense

Hace como 4 días mientras trabajaba con LINQ le encontré un fallo al IntellSense de VS2008. Tras notificarlo en el sitio Microsoft Connect me dispongo a comentarlo en este post. Antes de empezar a ver como reproducir este error del IDE de C# debo decir que pude percatarme de el por haber leído en la mañana el capitulo sobre el tema en el libro de Jon Skeet sobre C#.

Por definición es posible tener un método extensor de tipo extensible T y un método estático en T que tengan la misma firma. Recordemos que un método extensor es puro azúcar sintáctico, el modificador this hace que se marque un método que cumpla las características con el atributo  System.Runtime.CompilerServices.ExtensionAttribute, a los efectos es un método como otro cualquiera.

Es en esta situación donde IntellSense se confunde. Vamos a reproducirlo:

 public class A
{
public static void Method(A obj){Console.WriteLine("instance");}
public static void Foo() { }
}

public static class AHelper
{
public static void Method(this A obj) { Console.WriteLine("extension");}
}

static class Program
{
static void Main()
{
A objA = new A();
objA.Method();
Console.Read();
}
}

En la segunda instruccion del metodo Main, si usted activa el motor de IntellSense luego de haber escrito el punctuator (".") vera como el metodo Method no tiene el icono esperado, tampoco el tooltip comienza con "(extension)":



 


Una vez terminado de escribir el nombre del método podemos ver como ya es reconocido por IntellSense como método extensor:



Si borramos el método estático de la clase el método extensor quedaría reivindicado:



Hasta otra bloggers :)