On Mon, 13 Jul 2015 08:01:08 GMT, Sönke Ludwig wrote:
Creating closures can sometimes indeed be tricky when nested scopes are involved, but I have troubles reproducing the errors above. What I have is this: http://dpaste.dzfl.pl/0804d5dbb52f
Is there anything structurally different from what you had?
I adapted your code snippet into a simple vibe project called test:
dub init test vibe.d
In dub.json, seems to be using vibe-d 0.7.19
Here is app.d
https://gist.github.com/gronka/f16b52641de6e481caba
I'm getting the same error when I try to compile
source/app.d(35): Error: need 'this' for 'm_pass' of type 'RequestPass'
If you just want to mix in code to your class, a slightly cleaner approach would be to use a
mixin template
:// user.d mixin template UserMethods() { void register(HTTPServerRequest req, HTTPServerResponse res) { // can use m_pass here } } // bolt.d class Bolt { import bolt.views.user; mixin UserMethods!(); void registerRoutes(URLRouter router) { router.get("/register", &this.register); } }
Oh - that actually looks great. What I didn't like about mixin(import()) is that I'm pretty sure it would become a huge pain to track down compiling/dependency errors.