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

length() method wrap does not handle alias this well #271

Open
imzhaodong opened this issue Oct 29, 2020 · 4 comments
Open

length() method wrap does not handle alias this well #271

imzhaodong opened this issue Oct 29, 2020 · 4 comments

Comments

@imzhaodong
Copy link

When I wrap a simple class like this:

struct ProductType
{
    string value;
    alias value this;
}

wrapAggregate!(ProductType);

The compiler report error:
../../.dub/packages/autowrap-0.6.2/autowrap/pyd/source/autowrap/python/wrap.d(266,25): Error: no property length for type symmetry.carbon.client.CarbonClient.ProductType
../../.dub/packages/autowrap-0.6.2/autowrap/pyd/source/autowrap/python/wrap.d(98,9): Error: template instance autowrap.python.wrap.Lengths!(ProductType) error instantiating
source/symmetry/carbon/pyd_manual.d(47,5): instantiated from here: wrapAggregate!(ProductType)

Here is the relevant code at file pyd/source/autowrap/python/wrap.d line 266

261 private template Lengths(T) {
262     import pyd.pyd: Len;
263     import std.meta: AliasSeq;
264
265     static if(is(typeof(T.init.length)))
266         alias Lengths = Len!(T.length);
267     else
268         alias Lengths = AliasSeq!();
269 }

So we can see the compiler complain for line 266 that it cannot find length method for T. I think this is because the alias this confused compiler. And there should be a simple solution I think, in this case we do not even need len() python method in the worst case.

@atilaneves
Copy link
Collaborator

Unfortunately, this is a pyd limitation. It's true that autowrap isn't doing the right thing, but it's also true that it's impossible to do the right thing with pyd's current API.

atilaneves added a commit to atilaneves/autowrap that referenced this issue Oct 30, 2020
atilaneves added a commit that referenced this issue Nov 2, 2020
@imzhaodong
Copy link
Author

If I can add extra code into this being wrapped class, will that help? Say add a length() function into it?

@imzhaodong
Copy link
Author

Or is there a way I can let autowrap ignore generate len for this class?

@imzhaodong
Copy link
Author

Daniel Zhao 10:57 AM
If I can add extra code into this being wrapped class, will that help? Say add a length() function into it?
Or is there a way I can let autowrap ignore generate len for this class?

atilaneves 6:48 PM
Yes, that would do it
Adding length

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

2 participants