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

Initialization in lazy function parameter allows immutable member not to be initialized #18619

Open
dlangBugzillaToGithub opened this issue Jun 28, 2013 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

David Eckardt reported this on 2013-06-28T09:00:44Z

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

CC List

Description

class C
{
	immutable int x;
	
	this()
	{
		this.f(this.x = 5);
	}
	
	void f(lazy int x){}
}

C.int isn't initialized, although this code compiles.
Whether C.int is initialized or not depends on the, in general indeterministic, behavior of f(), this should be a compile time error.
@dlangBugzillaToGithub
Copy link
Author

public (@mihails-strasuns) commented on 2013-06-28T09:21:47Z

I think this is part of a bigger problem:

----------------------------------------
class A
{
    immutable int x;

    void delegate() f;

    this()
    {
        x = 40;
        f = () { x = 42; };
    }
}

void main()
{
    import std.stdio;
    auto a = new A();
    writeln(a.x);
    a.f();
    writeln(a.x);
}
----------------------------------------

40
42

@dlangBugzillaToGithub
Copy link
Author

maxim commented on 2013-06-28T11:08:00Z

The root is that delegate construction does not respect immutability at all.

struct S
{
   void foo() immutable {}
   void baz() 
   {
      //foo();
      (&foo)();
   }
}

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