Consider the following minimal example:
class Clazz<T> {}
Clazz<R> join<R, A extends R, B extends R>(Clazz<A> a, Clazz<B> b) => Clazz<R>();
void main() {
final a = Clazz<int>();
final b = Clazz<double>();
print(a); // 'Clazz<int>'
print(b); // 'Clazz<double>'
print(join(a, b)); // 'Clazz<dynamic>', but would like 'Clazz<num>'
}
I would expect that calling join would return an instance of Clazz with the most specific generic type, yet Dart always infers dynamic as the generic type. I also tried without success with a static extension method (same problem) and with a method within the class itself (unable to specify type constraints). What can I do to get the desired behavior?