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

Constructor initialiser list: the compiler doesn't fail when the initialisation list contain many initialisation fot he same instance variable #485

Closed
DartBot opened this issue Nov 16, 2011 · 4 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.

Comments

@DartBot
Copy link

DartBot commented Nov 16, 2011

This issue was originally filed by bulavitc...@gmail.com


Tested on Dartboard and dart vm on macos lion and I receive the same result

I was playing with the object creation in dart. In the version 0.05 of
the language spec I came across to the frase:

"It is a compile time error if more than one initializer corresponding
to a given instance variable appears in k's initializer list"

this is the code I try to run: (http://try.dartlang.org/s/lWMg)

class Test {
  int _x, _y;
  Test():this._x=0, this._x=1, this._x=2 {}
  dump() {
    print('x: ${_x} y: ${_y}');
  }
}

main () {
var x = new Test();
x.dump();
}

From my understanding this should throw an exception as i try to
initialise few times the same instance variable.

and probably this statement doesn't work as well:
"It is a compile-time error if k's initializer list con-
tains an initializer for a variable that is initialized by means of an initializing
formal of k"

http://try.dartlang.org/s/QL4g

@DartBot
Copy link
Author

DartBot commented Nov 17, 2011

This comment was originally written by drfibonacci@google.com


Added Area-VM, Triaged labels.

@ghost
Copy link

ghost commented Nov 17, 2011

Set owner to @mhausner.

@iposva-google
Copy link
Contributor

Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Jan 22, 2013

This comment was originally written by @mhausner


This has been fixed a long time ago. When executing the above code, the compiler reports the expected error:

Error: line 4 pos 21: duplicate initialization for field _x@0x1024d784
  Test():this._x=0, this._x=1, this._x=2 {}
                    ^


Added Fixed label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

2 participants