chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.78k stars 418 forks source link

Compiler errors from use of lambdas, generic functions, and generically parameterized records #12285

Open BryantLam opened 5 years ago

BryantLam commented 5 years ago

Related #8351

Summary of Problem

Bug. Compiler errors from use of first-class functions/lambdas as arguments to a generic member function of generically parameterized record.

record R {
  param size: uint;
}
record S {
  param size: uint;
  var r: R(size);
}

// error: illegal access of first class function
proc S.funcA(const functor): string {
  return functor(r);
}

// error: unresolved call 'S(10:uint(64)).funcB(chpl__fcf_type_R_10_string)'
proc S.funcB(const functor): string
where functor.argTypes == 1*R(size) && functor.retType == string {
  return functor(r);
}

record T {}

record U {
  var t: T;
}

// Okay
proc U.func(const functor): string
where functor.argTypes == 1*T && functor.retType == string {
  return functor(t);
}

proc main() {
  var s: S(10);
  writeln(s.funcA(lambda(r: R(10)){ return r.type:string; }));
  writeln(s.funcB(lambda(r: R(10)){ return r.type:string; }));

  var u: U;
  writeln(u.func(lambda(t: T){ return t.type:string; }));
}

Configuration Information

chpl verison 1.19.0 pre-release (543e9e67b1)

cassella commented 1 year ago

This compiles for me now, with output

R(10:uint(64))
R(10:uint(64))
T