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

Issue 11545 - Aggregate function literal member should not have access to enclosing scope #2824

Merged
1 commit merged into from
Mar 14, 2014

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Nov 19, 2013

@yebblies
Copy link
Member

Does it still work with 'delegate' instead of 'function' ?

@9rnsr
Copy link
Contributor Author

9rnsr commented Nov 19, 2013

Currently, declaring delegate in aggregate DeclDefs scope is not allowed (Error: function literals cannot be class members).

@Garciat
Copy link

Garciat commented Nov 19, 2013

I'm not sure if this will be fixed by this pull request in its current state, but it should also be noted that:

import std.stdio;

class hello {
    int function(int) f = function(int x) {
        return x;
    };
}

void main() {
    auto h = new hello();
    // segfaults
    writeln(h.f(42));
}

@@ -2833,6 +2833,12 @@ Expression *NewExp::interpret(InterState *istate, CtfeGoal goal)
VarDeclaration *v = s->isVarDeclaration();
assert(v);
Expression *m;
if (v->inuse)
{
error("cannot construct class %s during field %s.%s initializer semantic",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to 11545?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is related to the improvement of test/fail_compilation/ice10259.d. Without this change, the added test case will cause ICE.

@9rnsr
Copy link
Contributor Author

9rnsr commented Nov 19, 2013

@Garciat Between class and struct, there's no difference to the issue. Your example will also be fixed by this.

@CyberShadow
Copy link
Member

Thanks for fixing this! 👍

@CyberShadow
Copy link
Member

I noticed a problem with this pull (not a regression):

import std.algorithm;
import std.array;

struct S
{
    static immutable int[] pairs = [];
    static immutable int[] pairTokens = pairs.map!(a => a).array();
}

This still fails to compile, with the cryptic message Error: this.__lambda3 has no value inside std.algorithm.

@@ -720,6 +720,8 @@ class FuncLiteralDeclaration : public FuncDeclaration
Dsymbol *syntaxCopy(Dsymbol *);
bool isNested();
bool isVirtual();
bool addPreInvariant();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an unrelated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is necessary to skip invariant emission for the lambdas in aggregate member scope.

class C {
    enum x = () { ... };   // This lambda should not have invariant
    invariant {}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, what confused me was the missing override, but we're in C++. Doh!

@ghost
Copy link

ghost commented Mar 13, 2014

LGTM other than the introduction of addPreInvariant and addPostInvariant, which seem like unrelated changes.

@ghost
Copy link

ghost commented Mar 14, 2014

Auto-merge toggled on

ghost pushed a commit that referenced this pull request Mar 14, 2014
Issue 11545 - Aggregate function literal member should not have access to enclosing scope
@ghost ghost merged commit 195a3b1 into dlang:master Mar 14, 2014
@9rnsr
Copy link
Contributor Author

9rnsr commented Mar 14, 2014

Thanks!

@CyberShadow
Copy link
Member

Thanks everyone! This is a great improvement.

DustMite master should now compile for everyone :)

@9rnsr 9rnsr deleted the fix11545 branch March 14, 2014 08:11
@quickfur
Copy link
Member

quickfur commented Sep 5, 2014

This PR introduced this bug: https://issues.dlang.org/show_bug.cgi?id=13424

This pull request was closed.
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

Successfully merging this pull request may close these issues.

5 participants