[Issue 11718] New: regression(git head): failed semantic analysis

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 10 11:48:39 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11718

           Summary: regression(git head): failed semantic analysis
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: timothee.cour2 at gmail.com


--- Comment #0 from Timothee Cour <timothee.cour2 at gmail.com> 2013-12-10 11:48:34 PST ---
$dmd_064_2_X -main -unittest -run main.d
#ok

$dmd -main -unittest -run main.d
# Error: struct main.setfields!(A).setfields.Proxy!(true, a, null).Proxy failed
semantic analysis

---
auto setFields_aux(bool isRef,alias foo,string s,T...)(T args)
{
  import std.array:split;
  import std.conv:to;
  enum namesCall=split(s,",");
  static assert(namesCall.length==T.length);
  static if(isRef){
    enum foo2_name="foo";
  }
  else{
    auto foo2=foo;
    enum foo2_name="foo2";
  }

  string getString()
  {
    string ret;    
    foreach(i,vali ; namesCall){
      ret~=foo2_name~`.`~vali~`=`~`args[`~i.to!string~`];`;
    }
    ret~=`return `~foo2_name~`;`;
    return ret;
  }
  mixin(getString());
}

private struct Proxy (bool isRef,alias func, string parameters, Args ...)
{
  private static string addParameter (string parameters, string newParameter)
()
  {
    return parameters is null ? newParameter : parameters ~ "," ~ newParameter;
  }

  Args args;
  this(int dummy,Args args){
    static if(Args.length)
      this.args=args;
  }

  auto opDispatch (string name, T) (T value)
  {
    return Proxy!(isRef,func, addParameter!(parameters, name), Args, T)(0,args,
value);
  }

  auto opCall()()
  {
    return setFields_aux!(isRef,func, parameters)(args);
  }
}

auto setfields(T)(T a){
  return Proxy!(true,a, null)(0);
}
auto setfields(T)(){
  T a;
  return Proxy!(true,a, null)(0);  
}

unittest{ 
  struct A{
    int x;
    float y=10;
    string z;
  }

  auto z1=A.init.setfields.z("a").x(3)();
  auto z2=setfields!A.z("a").x(3)();
}
---

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list