Skip to content

Types accepted in 'key in AA' expressions during speculative evaluation #21104

Open
@rainers

Description

@rainers

Found this snippet in unit_threaded.assertions:

enum isLikeAssociativeArray(T, K) = is(typeof({
    if(K.init in T) { }
    if(K.init !in T) { }
}));

static assert(isLikeAssociativeArray!(string[string], string));
static assert(!isLikeAssociativeArray!(string[string], int));

This passes even though this fails:

void foo(T, K)()
{
    if(K.init in T) { } // Error: type `string[string]` is not an expression
}

void fooTK()
{
    foo!(string[string], string)();
}

It seems the error is only generated from the glue layer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions