boo-lang / boo

The Boo Programming Language.
BSD 3-Clause "New" or "Revised" License
874 stars 148 forks source link

Generic matching bug with internally-declared callables #103

Open masonwheeler opened 9 years ago

masonwheeler commented 9 years ago
namespace GenericsBugs
class Foo[of T]:

   private callable Bar(value as Foo[of T]) as T

   _bar as Bar

   public def BreakSomething():
      _bar(self)

This should compile and work as expected, assuming _bar is assigned somewhere. Unfortunately, it never makes it that far.

The best overload for the method 'GenericsBugs.Foo.Bar' is not compatible with the argument list '(GenericsBugs.Foo[of T])'. (BCE0017)

masonwheeler commented 9 years ago

Making a change to Boo.Lang.Compiler.TypeSystem.Generics.GenericConstructedType seems to fix this, only to run into another error down the road. Here's the partial fix:

    public virtual bool IsAssignableFrom(IType other)
    {
        if (other == null)
            return false;

        if (other == this || other.IsSubclassOf(this) || (other.IsNull() && !IsValueType) || IsGenericAssignableFrom(other))
            return true;

        return false;
    }

    public bool IsGenericAssignableFrom(IType other)
    {
        var ci = this.ConstructedInfo;
        if (ci == null)
            return false;
        var gd = ci.GenericDefinition;
        if (gd == null)
            return false;

        return gd.IsAssignableFrom(other);
    }

But now, when attempting to compile this:

Language feature not implemented: referencing generic parameter of outer type. (BCE0031)

masonwheeler commented 6 years ago

Update: After a lot of work has been done on improved generic types support, this error is fixed, but now we get a different one:

Foo.Bar[of T] requires 1 arguments.