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

Problem with overloading resolution of nested function declaration #448

Closed
PaulKlint opened this issue Dec 20, 2013 · 4 comments
Closed

Comments

@PaulKlint
Copy link
Member

import Exception;
import List;

public test bool tstMapper(list[int] L) {
  int incr(int x) { return x + 1; };
  return mapper(L, incr) == [x + 1 | x <- L];
}

gives

ALT: func(list(parameter("U",value())),[list(parameter("T",value())),func(parameter("U",value()),[parameter("T",value())])])
|rascal://experiments::Compiler::Rascal2muRascal::RascalExpression|(16405,2,<385,76>,<385,78>): "ERROR in overloading resolution: func(list(int()),[list(int()),func(int(),[int()])]); |rascal:///experiments/Compiler/Examples/Tst.rsc|(364,6,\<17,9\>,\<17,15\>)"
@ghost ghost assigned Anastassija Dec 20, 2013
@Anastassija
Copy link
Contributor

The compiler uses the match function of the type checker (from the TypeInstantiation module) to compute type parameter bindings and instantiate types. To do so, it creates a tuple of formal parameter types and a tuple of argument types, and in this case the match function throws invalidMatch exception (see defaultMatch). This becomes also a type checking issue, for example, in the following case:

list[&U] mapper(tuple[list[&T] lst, &U (&T) fun] t) = [ t.fun(elem) | elem <- t.lst ];

value tstMapper(list[int] L) {
  int incr(int x) { return x + 1; };
  return mapper(<L, incr>);
}

error("Could not instantiate type variables in type fun list[&U \<: value](tuple[list[&T \<: value] lst, fun &U \<: value(&T \<: value) fun]) with argument types (tuple[list[int], fun int(int)])",|rascal:///experiments/Compiler/Examples/NestedFunctions5.rsc|(259,17,<10,9>,<10,26>))
|rascal://experiments::Compiler::Rascal2muRascal::RascalModule|(2652,25,<80,12>,<80,37>): "Module contains errors!"

@mahills, could you, please, take a look!

@mahills
Copy link
Member

mahills commented Dec 21, 2013

Will do. I think I'm just going to have to rewrite the match functionality, it's too brittle with these cases (the root problem is that a subtyping check is performed to see if the parameterized type and the actual type can be matched, but this works for all cases except functions, which, because of contravariance, are generally supertypes of the subject).

@mahills
Copy link
Member

mahills commented Dec 21, 2013

I've tested this with a number of Rascal libraries and this appears to be working fine, but please test it within the compiler as well, this was a fairly big change in how parameterized types are matched.

@PaulKlint
Copy link
Member Author

I have tried the original case and am testing other libraries and tests. So far so good. Thanks!

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

No branches or pull requests

3 participants