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

[scope] Fwd reference error with nested struct #19235

Open
dlangBugzillaToGithub opened this issue Feb 17, 2017 · 5 comments
Open

[scope] Fwd reference error with nested struct #19235

dlangBugzillaToGithub opened this issue Feb 17, 2017 · 5 comments

Comments

@dlangBugzillaToGithub
Copy link

Radu Racariu (@rracariu) reported this on 2017-02-17T07:21:16Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=17194

CC List

Description

The following:

struct V
{
    W w;
    
    struct W
    {
        this(scope ref V v)
        {
            this.v = &v;
        }
        V* v;
    }
}

void main()
{
	V v;
}

Produces this:

Error: struct app.V no size because of forward reference

Expecting: to compile.

Error is also not pointing the line number the issue was suppose to be.

Work around:

1. Removing the "scope" keyword makes the program compile.

2. Changing W ctor signature to: 

this(scope V* v)
{
 this.v = v;
}

also makes it work.

Compiled with dmd 2.073.1 on win32
@dlangBugzillaToGithub
Copy link
Author

syniurge commented on 2017-07-14T21:30:12Z

It's not specific to nested classes:

struct S {
    S2 a;
}

struct S2 {
    void foo(scope S s) { }
}

=> Error: struct S no size because of forward reference

Kinda related: issue 17548 was another bogus forward ref error originating from the same TypeStruct.hasPointers call in TypeFuntion.semantic (but as I understand it that call isn't the actual problem).

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2017-07-15T06:12:04Z

Elle's example stopped working after https://github.com/dlang/dmd/pull/5897 but I don't know enough about scope whether know if this can be marked as a regression.

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2017-08-31T06:33:35Z

This is a bit of a hopeless circular tangle. 'scope' is ignored if the type has no pointers. So S is checked for pointers. S.a is of type S2, which then must be checked for pointers. Checking S2 for pointers means evaluating each member to see if it is a field, which gets us back to looking at the 'scope'.

Not sure if this is reasonably fixable.

@dlangBugzillaToGithub
Copy link
Author

radu.racariu (@rracariu) commented on 2017-08-31T08:17:21Z

I think the original description is different than Elie's example.

For one, the argument is sent by ref - the issue I was describing is related to the interaction of 'scope' and 'ref'.

I expected that 'scope ref V' be the same as 'scope V*'

@dlangBugzillaToGithub
Copy link
Author

radu.racariu (@rracariu) commented on 2017-11-06T15:49:53Z

Just to point that "scope" is to blame here, removing "scope" from the inner stuct ctor like:

+++++++++++++++++++
struct V
{
    W w;
    
    struct W
    {
        this(/*scope*/ ref V v)
        {
            this.v = &v;
        }
        V* v;
    }
}

void main()
{
	V v;
}
+++++++++++++++++++

compiles without errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant