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

Named arguments don't work with constructor initializers #372

Closed
nex3 opened this issue Nov 8, 2011 · 3 comments
Closed

Named arguments don't work with constructor initializers #372

nex3 opened this issue Nov 8, 2011 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@nex3
Copy link
Member

nex3 commented Nov 8, 2011

If a constructor has optional initializer arguments, as in Foo([int this.a = 1]), using those as named arguments as in new Foo(a: 2) fails:

An unhandled exception has been thrown
NoSuchMethodException - receiver: 'Instance of 'Foo'' function name: 'Foo.' arguments: [-3737570]]
 0. Function: 'Object.noSuchMethod' url: 'bootstrap' line:93 col:3
 1. Function: 'Foo.Foo.' url: '/usr/local/google-old/home/goog/dart/dart/test.dart' line:-1 col:-1
 2. Function: 'main' url: '/usr/local/google-old/home/goog/dart/dart/test.dart' line:7 col:13

@iposva-google
Copy link
Contributor

This is actually a language question. Is Foo([int this.a = 1]) even allowed?


Set owner to @gbracha.
Removed Area-VM label.
Added Area-Language, Accepted labels.

@gbracha
Copy link
Contributor

gbracha commented Nov 21, 2011

The spec is buggy: it does not answer this question properly.

The construction is allowed by the syntax, but there is no way such a parameter could be used, as its name is undefined. The name of this.x could be x, which would mean that it introduced deliberate shadowing (something we warn about) so that is not desirable. It could be this.x, which exposes to the world an implementation detail about how you chose to do initialization, so that too is not desired. So we should leave it undefined, which means it cannot be called. In which case, the spec should clearly state that the an initializing formal cannot be used as an optional parameter to a constructor. This means that if you want an optional parameter, you will have to take the trouble of assigning it to the instance variable manually.

@gbracha
Copy link
Contributor

gbracha commented Nov 21, 2011

Spec has been modified accordingly.


Added Done label.

@nex3 nex3 added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Nov 21, 2011
dart-bot pushed a commit that referenced this issue Jun 12, 2019
2019-06-11 tvolkert@users.noreply.github.com More fixes to cast response to Stream<List<int>> (#385)
2019-06-11 tvolkert@users.noreply.github.com Pass Uint8List to Datagram (#382)
2019-06-11 tvolkert@users.noreply.github.com Cast HttpRequest and HttpClientResponse streams to List<int> (#384)
2019-06-10 sgrekhov@unipro.ru Fixes #364. Change expected result to null for default values of clientMaxWindowBits and serverMaxWindowBits
2019-06-07 sgrekhov@unipro.ru Fixes #380. Added tests for logical and bitwise operations via type aliases
2019-06-07 sgrekhov@unipro.ru Additional fix for #373. Code style improved and more strict pattern checking
2019-06-06 sgrekhov@unipro.ru Fix for #380. Added tests for type aliases for built-in types. Test string concatenation and arithmetic operations
2019-06-05 sgrekhov@unipro.ru Fixes #380. Added tests for type aliases for built-in types initialization
2019-06-05 sgrekhov@unipro.ru Fixes #373. Expect reasonable file mode on Unix
2019-06-04 sgrekhov@unipro.ru Fixes #379. Numerous fixes for io/Process tests
2019-06-04 sgrekhov@unipro.ru Fixes #378. Use Platform.resolvedExecutable instead of 'dart' command
2019-06-04 irina.arkhipets@gmail.com Fixed Issue #375: it's possible that IPv6 loopback does not exist.
2019-06-04 irina.arkhipets@gmail.com Fixed Issue #236: host.host can be either "localhost" or Platform.localHostname.
2019-06-04 irina.arkhipets@gmail.com Issue #370, instantiate-to-bounds: added static tests for non-function type aliases.
2019-06-04 sgrekhov@unipro.ru Fix for #377. Use correct network interface type name (IPvX)
2019-06-04 sgrekhov@unipro.ru Fixes #374. Change pattern for error messages
2019-06-04 irina.arkhipets@gmail.com Issue #370, instantiate-to-bounds: added dynamic tests for non-function type aliases.
2019-06-04 sgrekhov@unipro.ru Fix for #372. Expect.fail() on timeout added
2019-06-04 sgrekhov@unipro.ru Fixes #371. Remove excessive asyncStart()
2019-06-03 irina.arkhipets@gmail.com Issue #147, test super bounded types: added tests for non-function type aliases.
2019-05-30 sgrekhov@unipro.ru Fixes #369. Use correct type arguments to avoid errors
2019-05-30 sgrekhov@unipro.ru Fixes #368. Don't try to bind system port
2019-05-30 sgrekhov@unipro.ru Fixes #367. Remove excessive asyncStart()
2019-05-30 sgrekhov@unipro.ru Fixes #366. Change expected result to SocketException

TBR=whesse@google.com

Change-Id: I137689755907b3333e597d7d210db2b4d37d70d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105641
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: William Hesse <whesse@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

4 participants