www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23687] New: IFTI fails forwarding an alias to struct field

https://issues.dlang.org/show_bug.cgi?id=23687

          Issue ID: 23687
           Summary: IFTI fails forwarding an alias to struct field
           Product: D
           Version: D2
          Hardware: Other
                OS: Mac OS X
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ben.james.jones gmail.com

```
import std.stdio;
import std.range;

struct LinkedListAdaptor(alias nextField, T){
        T current;
     safe:
        nothrow:

    this(T head){
        current = head;   
    }

    bool empty() const {
        return current == null;
    }   

    T front() {
        return current;   
    }

    void popFront() {
                current = __traits(child, current, nextField);
    }
}

auto linkedListAdaptor(alias nextField, T)(T head) if(is(T == U*, U)){
        return LinkedListAdaptor!(nextField, T)(head);   

    //fails with:
    //onlineapp.d(27): Error: symbol or expression expected as first argument
of __traits `child` instead of `Node*`
    // return LinkedListAdaptor!(__traits(child, T, nextField), T)(head);   
}

struct Node{
        int data;
    Node* next;
}

void main(){
        Node* head = new Node(10, new Node(20, null));

    auto rng1 = LinkedListAdaptor!(Node.next, Node*)(head); //OK
    auto rng = linkedListAdaptor!(Node.next)(head);
    foreach(const x; rng){
        writeln(x.data);
    }
}
```

fails on the `auto rng = linkedListAdaptor!(Node.next)(head);` line with 

`Error: need `this` for `linkedListAdaptor` of type `pure nothrow  nogc  safe
LinkedListAdaptor!(next, Node*)(Node* head)``

--
Feb 11 2023