[nem-en] Bugs in extension method implementation
vc
vc at rsdn.ru
Sat Aug 26 15:29:47 CEST 2006
> Well it works for me in simple examples:
>
> tlib.n:
> public module Extend {
> public Reverse['a] (this a : array ['a]) : void {
> System.Array.Reverse (a);
> }
> }
>
> t.n:
> def f (a : array [int]) {
> a.Reverse ();
> }
>
> def a = array [1,2,3];
> f (a);
Try (in reference you need add Nemerle.Compiler.dll):
using System.Console;
using Nemerle.Compiler;
def member : IMember = null;
WriteLine(member.GetName())
You get this error message:
Main.n(5,11,5,25): error : there is no member named `GetName' in
Nemerle.Compiler.IMember with type ?
> So it is probably some other issue. I don't remember if there was any
> fresh bootstrap in boot/ since I fixed this bug, maybe this is the
> reason?
Hardly, as I compile this code by not bootstrap compiler. And the
Reflector shows, that in assembly all ОК.
I find error with the help of debugger. It source a different assemble
modules (with same version) of Nemerle.dll loaded by compiler. In this case
IsDefined() method report false even if in type exist ExtensionAttribute.
I have changed logic of determination of presence the ExtensionAttribute.
Now it finde simply by name. See ncc\external\LibrariesLoader.n line 391:
public static IsExtension (attrsProvider :
System.Reflection.ICustomAttributeProvider) : bool
{
def attrs = attrsProvider.GetCustomAttributes(false);
NArray.Exists(attrs, attr => attr.GetType().Name ==
"ExtensionAttribute")
}
It's the same way as support LINQ ExtensionAttribute and any
ExtensionAttribute defined in any assembly.
PS
Check this solution and if it's OK, update bootstrap, please.
More information about the devel-en
mailing list