March 12, 2022

Hello,
why this code compile without problems:


struct Query{
    public const SharedPtr!Builder builder;
}

interface Builder{
    void build(ref Query query);
}

struct SharedPtr(T){
    enum touch_T = __traits(hasMember, T, "touch");
    //...
}


void main(){

}

but if ref Query query is scope then there is error?


struct Query{
    public const SharedPtr!Builder builder;
}

interface Builder{
    void build(scope ref Query query);     //SCOPE
}

struct SharedPtr(T){
    enum touch_T = __traits(hasMember, T, "touch");
    //...
}



void main(){

}
src/app.d(3,1): Error: no size because of forward references
src/app.d(4,18): Error: template instance `app.SharedPtr!(Builder)` error instantiating

March 13, 2022

On Saturday, 12 March 2022 at 13:12:25 UTC, vit wrote:

>
enum touch_T = __traits(hasMember, T, "touch");

I think you meant build instead of touch?

struct Query {
  public const SharedPtr!Builder builder;
}

interface Builder {
  void build(ref Query query);
}

struct SharedPtr(T) {
    enum touch_T = __traits(hasMember, T, "build");
}

import std.traits, std.stdio;

void main() {
  Query q;
  q.builder.touch_T.writeln(" #build");
} // true #build