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

rethink restrictions on variable default attributes #1413

Closed
gavinking opened this issue Sep 2, 2015 · 4 comments
Closed

rethink restrictions on variable default attributes #1413

gavinking opened this issue Sep 2, 2015 · 4 comments

Comments

@gavinking
Copy link
Member

I remember at one stage I relaxed a restriction on setting the value of a variable default attribute, allowing this:

 class C() {
     shared default variable String name = "";
     name = "foo";
 }

I don't think I meant to also allow this:

 class C() {
     shared default String name => "";
     assign name {}
     name = "foo";
 }

But I guess I need to find/review the original discussion of this and re-think it through.

@gavinking gavinking self-assigned this Sep 2, 2015
@gavinking gavinking added this to the 1.2 milestone Sep 2, 2015
@gavinking
Copy link
Member Author

Note that even the first example is currently broken:

shared class Foo()
{
    shared default variable String bar = "woo";
    bar = "waa";
}

shared class Baz()
extends Foo()
{
    String s = "wuh";
    shared actual String bar => "wee";
    assign bar
    {
        print(s);
    }
}

shared void run() => Baz();

@Zambinofex noticed that this prints null.

@lucaswerkmeister
Copy link
Member

@Zambinofex noticed that this prints null.

Also known as @Zambonifofex :)

Regarding the broken example… is there a way to un-break this without making bar = "waa"; erroneous with “default member may not be used in initializer”?

@ghost
Copy link

ghost commented Sep 9, 2015

@Zambinofex noticed that this prints null.

Also know as @Zambonifofex :)

Haha... xP

Also, this prints "<null>" as well:

shared class Foo()
{
    shared default variable String woo;
    woo = "waa";
}

shared class Bar()
extends Foo()
{
    String wii = "wuh";
    shared actual String woo => "wee";
    assign woo
    {
        print(wii);
    }
}

shared void run() => Bar();

Which isn't what I would expect, since, neither of these do:

shared class Foo()
{
    shared default variable String woo = "waa";
}
shared class Foo()
{
    shared default String woo;
    woo = "waa";
}

@gavinking
Copy link
Member Author

OK, so in fact this bug was caused by the proposed change #1379. I've rolled back that change, so I'm closing this issue, and leaving #1379 open for now.

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

2 participants