www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - 2.057 regression and Result structs in std.algorithm

Some code using std.algorithm.filter broke today when I updated dmd.

Here's a test case:
import std.stdio, std.algorithm;

void main() {
  writeln(filter!"a != 'r'"("Merry Christmas!"));
Compiling with -inline gives:
/src/phobos/std/algorithm.d(1120): Error: function
std.algorithm.filter!("a != 'r'").filter!(string).filter is a nested
function and cannot be accessed from formatValue

This reduced test case gives a clue as to what is going on:
auto fun()
  struct Result {
    this(int u) {}

    auto bar() {
        return Result(0);
  return Result();

void main() {
  auto t = fun();
  auto a = t.bar();
Compiled with -inline:
t.d(7): Error: function t.fun is a nested function and cannot be
accessed from main

It seems what is happening is that bar is being inlined in main, but
dmd doesn't know where to get the new fun.Result's context pointer

I'll file a bug report on this, but it made me wonder why
std.algorithm has so many non-static Result structs. Would it be a
good idea to make them static, where possible?

Dec 16 2011