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

Error on registerWebInterface with a parameterized constructor class #2438

Closed
o3o opened this issue Apr 29, 2020 · 12 comments
Closed

Error on registerWebInterface with a parameterized constructor class #2438

o3o opened this issue Apr 29, 2020 · 12 comments

Comments

@o3o
Copy link

o3o commented Apr 29, 2020

When I register a class with a parameterized constructor. I get the following error:

Error: static assert:  "Instances may only be returned from parameter-less functions (__ctor)!"

This happens in all projects that were successfully built before.
For example:

$ git clone git@github.com:rejectedsoftware/diskuto.git
$ cd diskuto/examples/embed-raw
$ dub build

/home/o3o/.dub/packages/vibe-d-0.8.6/vibe-d/web/vibe/web/web.d(200,6): Error: static assert:  "Instances may only be returned from parameter-less functions (__ctor)!"
../../source/diskuto/web.d(33,29):        instantiated from here: registerWebInterface!(DiskutoWebInterface, cast(MethodStyle)5)
dmd failed with exit code 1.

My environment

$ dmd --version
DMD64 D Compiler v2.091.0

$ dub --version
DUB version 1.16.0-beta.1, built on Jul 22 2019

Thank you

@Geod24
Copy link
Contributor

Geod24 commented Apr 29, 2020

So it is failing with v0.8.6. Which version did it last work with ?

@o3o
Copy link
Author

o3o commented Apr 29, 2020

With 0.8.6 !

I checked code and Sönke introduced this assert in 2014

commit 5c744e9cd4fedb8a4b9a80aad66f53d51c805cc4
Author: Sönke Ludwig <sludwig@rejectedsoftware.com>
Date:   Tue Jul 22 15:45:43 2014 +0200
 
-				router.match(minfo.method, concatURL(settings.urlPrefix, url), (req, res) {
-					handleRequest!(M, overload)(req, res, instance, settings);
-				});
+				static if (is(RT == class) || is(RT == interface)) {
+					// nested API
+					static assert(
+						ParameterTypeTuple!overload.length == 0,
+						"Instances may only be returned from parameter-less functions ("~M~")!"
+					);
+					auto subsettings = settings.dup;
+					subsettings.urlPrefix = concatURL(settings.urlPrefix, url, true);
+					registerWebInterface!RT(router, __traits(getMember, instance, M)(), subsettings);
+				} else {
+					router.match(minfo.method, concatURL(settings.urlPrefix, url), (req, res) {
+						handleRequest!(M, overload)(req, res, instance, settings);
+					});
+				}
 			}

@o3o
Copy link
Author

o3o commented Apr 29, 2020

I tried:

$ dub build  --compiler=ldc

It works!

@Geod24
Copy link
Contributor

Geod24 commented Apr 29, 2020

So it sounds like a compiler issue. What LDC version ?

@o3o
Copy link
Author

o3o commented Apr 29, 2020

I think so...

My ldc:

$ ldc --version
LDC - the LLVM D compiler (1.20.1):
  based on DMD v2.090.1 and LLVM 9.0.1
  built with LDC - the LLVM D compiler (1.19.0)
  Default target: x86_64-pc-linux-gnu
  Host CPU: bdver2
  http://dlang.org - http://wiki.dlang.org/LDC

@Geod24
Copy link
Contributor

Geod24 commented May 1, 2020

Alright, it's a regression introduced by dlang/phobos#7385
The following code:

import std.traits;

class Bar
{
    this (int i) {}
}

static foreach (M; __traits(allMembers, Bar))
{
    static foreach (overload; MemberFunctionsTuple!(Bar, M))
        pragma(msg, M, ": ", ReturnType!overload);
}

Would return (pre-2.091.0):

toString: string
toHash: ulong
opCmp: int
opEquals: bool

After:

__ctor: Bar
toString: string
toHash: ulong
opCmp: int
opEquals: bool

We need to ignore __ctor in Vibe.d, but the regression is still annoying as it prevents compiling older versions of Vibe.d with newer compiler.

@Geod24
Copy link
Contributor

Geod24 commented May 1, 2020

Fix submitted in #2439

@o3o
Copy link
Author

o3o commented May 3, 2020

Thank you very much Mathias...

Now fails also with ldc.. :(

Geod24 added a commit to Geod24/vibe.d that referenced this issue May 3, 2020
Geod24 added a commit to Geod24/vibe.d that referenced this issue May 3, 2020
@WebFreak001
Copy link
Contributor

workaround: remove the constructor, make a private load function and construct it and call that load function before passing to registerWebInterface

@o3o
Copy link
Author

o3o commented May 4, 2020

It's a blocking issue, it stops me from doing my job, WebFreak001 suggestion's it's correct but I've a lot of classes to modify.
@Geod24 can you create a temporary fork (like this)?

Thank you

@o3o
Copy link
Author

o3o commented May 20, 2020

Add a temporary fork.

@Geod24
Copy link
Contributor

Geod24 commented May 20, 2020

@o3o : Sorry I forgot to answer. Personally what I do is use path dependencies + submodules.
You need this and this.

The original reason for doing this was to manually override our dependencies' dependencies.

s-ludwig added a commit that referenced this issue May 24, 2020
Fix #2438 - Error on registerWebInterface with a parameterized constructor class
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

3 participants