Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler can not resolve overloads of method when it has tupple argument #450

Open
Forester- opened this issue Jan 9, 2013 · 4 comments

Comments

@Forester-
Copy link

Code below has simple class hierarchy A <- B. There are two overloads of method F - F(A) and F(B), also there are two overloads of FT - FT(A * string) and FT(B * string).
In method F(A) compiler correctly resolves between F(A) and F(B). But when method has tupple argument compiler generates error. In method FT(A * string) compiler can not resolve between FT(A * string) and FT(B * string) though argument has type B * string.

Nemerle 1.1.1004.0 (setup from NemerleSetup-net-4.5-v1.1.1004.0-nightly.msi)
Visual Studio 2010
x64 OS

class A { }
class B : A { }

class C
{
  F(a : A) : void
  {
    | a1 is B => F(a1); // here is OK
  }
  F(_ : B) : void {}

  FT(a : A * string) : void
  {
      def (a1, s) = a;
      match(a1)
      {
        | a2 is B => FT((a2, s)); // but here is error : typing fails on ambiguity between overloads
      }
  }
  FT(_ : B * string) : void {}
}
@NN---
Copy link
Member

NN--- commented Jan 10, 2013

Try without parentehsis:

| a2 is  B => FT(a2, s)

http://ideone.com/cBLn9i

@NN--- NN--- closed this as completed Jan 10, 2013
@Forester-
Copy link
Author

It's workaround. And it does work only when method has one tupple argument. It does not work for methods with two and more tupple arguments

class A { }
class B : A { }
class D : A { }

class C
{
  F(a1 : A, a2 : A) : void
  {
    | (a11 is B, a21 is B) => F(a11, a21); // here is OK
  }
  F(_ : B, _ : B) : void {}

  FT(a1 : A * string, a2 : A * string) : void
  {
      def (a11, s1) = a1;
      def (a21, s2) = a2;

      match(a11, a21)
      {
        | (a31 is B, a32 is B) => FT((a31, s1), (a32, s2)); // but here is error : typing fails on ambiguity between overloads
        | (a31 is D, a32 is D) => FT(a31, s1, a32, s2); // here is error : wrong number of parameters in call, needed 2, got 4
        | _ => {}
      }
  }
  FT(_ : B * string, _ : B * string) : void {}
  FT(_ : D * string, _ : D * string) : void {}
}

@NN--- NN--- reopened this Jan 10, 2013
@NN---
Copy link
Member

NN--- commented Jan 11, 2013

Seems like bug in Typer.
You can workaround it simply by specifying partial types:

match((a11, a21))
{
  | (a31 is B, a32 is B) =>  FT((a31, s1) : B * _, (a32, s2));

@Forester-
Copy link
Author

Thank you for your advise.
Now i've already workarounded this problem by using another name for methods which have subclasses arguments. In my case there is two level hierarchy, so it is enough. I'll try to remember your workaround for next time or refactoring. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants