Skip to content

order-independent parameters when referencing each other #3226

Open
@anthonyquizon

Description

@anthonyquizon

Eg. A function like this doesn't compile:

fn Module(comptime T: type) type {                                                                                                                                                                                 
    const ListType = ArrayList(T);                                                                                                                                                                                 
                                                                                                                                                                                                                   
    return struct {                                                                                                                                                                                                
        pub fn reduce(
            f: fn(T, @typeOf(init)) @typeOf(init), 
            init: var, 
            list: ListType
        ) @typeOf(init)  {                                                                                                            
        //  ...                                                                                                                                                                                      
        }                                                                                                                                                                                                          
    };                                                                                                                                                                                                             
}     

Where init is ordered before f but is referenced by f with @typeOf.

However, if init is placed at the start of the function, it is able to be referenced

        // ...
        pub fn reduce(
            init: var, 
            f: fn(T, @typeOf(init)) @typeOf(init), 
            list: ListType
        ) @typeOf(init) {                                                                                                            
        //  ...                                                                                                                                                                                      
        }       

I would have thought that @typeOf should be able to reference an argument regardless of order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions