Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPServerRequest.context.get cannot be used with classes and interfaces #2004

Open
quickfur opened this issue Dec 14, 2017 · 0 comments
Open

Comments

@quickfur
Copy link
Contributor

Code:

interface MyInterface { }
void func(HTTPServerRequest req) {
    auto intf = req.context.get!MyInterface("abc");
}

Compiler output:

/usr/src/d/vibe.d/utils/vibe/utils/dictionarylist.d(198): Error: cannot implicitly convert expression `this.get(key, delegate const(MyInterface)() => null)` of type `const(MyInterface)` to `inout(MyInterface)`
main.d(41): Error: template instance vibe.utils.dictionarylist.DictionaryList!(VariantN!32LU, true, 2LU, false).DictionaryList.get!(MyInterface) error instantiating

The same error occurs if the interface is changed to class, and if the class/interface isn't directly stored in req.context, but is part of a struct.

Expected behaviour: it should be possible to store class and interface references in HTTPServerRequest.context.

Currently-known workaround: specify the default argument with T.init explicltly.

interface MyInterface { }
void func(HTTPServerRequest req) {
    auto intf = req.context.get!MyInterface("abc",
        MyInterface.init); // <-- this works
}

I looked at the code and found comments mentioning a dmd bug and a bunch of overloads that supposedly works around said bug. However, the workaround doesn't seem to work for classes/interfaces.

@quickfur quickfur changed the title HTTPServerRequest.context.get cannot be instantiated with classes and interfaces HTTPServerRequest.context.get cannot be used with classes and interfaces Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant