I get "Error: mismatched function return type inference" errors with choosing the return type for functions that work on ranges using, e.g, std.algorithm or std.range functions, but have different behavior based on runtime values. The return type is always a range with the same underlying type.

Here's an example:

auto foo(int[] ints) {
  import std.range;
  if (ints.length > 10) {
    return chain(ints[0..5], ints[8..$]);
  } else {
//return ints; // Error: mismatched function return type inference of int[] and Result return chain(ints[0..0], ints[0..$]); // This workaround compiles
  }
}

Is there a compatible return type that can be used, or some other workaround? I couldn't find one when searching for the error or looking at the phobos source code.

Thanks! orip

Reply via email to