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

Specification of ! and + unary operators is unclear #359

Closed
DartBot opened this issue Nov 6, 2011 · 4 comments
Closed

Specification of ! and + unary operators is unclear #359

DartBot opened this issue Nov 6, 2011 · 4 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@DartBot
Copy link

DartBot commented Nov 6, 2011

This issue was originally filed by [email protected]


These two operators are allowed to be used in a unary expression, but they are not allowed to be user defined. I could not find a definition in the spec for how they are supposed to behave. Here are the rough rules that I am assuming until I hear something more definitive:

  1. The + operator is roughly the same as 'assert(x is num)' where it will check that it is being applied to a number type and will otherwise be a noop. My inclination would be to be even stricter here and remove this operator from the language - but add it to the syntax for NUMERIC literals as this is the place that many programmers are used to using it.
  2. The ! operator will check that its argument is a bool and if so will return the opposite bool value. Otherwise it will signal an error in some appropriate way? It's a little troubling to me that I can't figure out the right error message here. MethodMissing seems correct - but there's no defined method to me missing...

Thanks for any help clarifying the behavior of these operators.

@floitschG
Copy link
Contributor

I would expect !x to behave exactly like: (x? false: true)
(No need to search for error-messages).


Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Nov 8, 2011

The spec should give definitions for operators that are not user defined, and it doesn't. User defined operators are spec'ed by the library code that defines them.

PS: mail me about high priority questions; I may overlook bugs for a day or two.


Set owner to @gbracha.
Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented Nov 8, 2011

 I've now spec'ed both, but will move to eliminate unary + altogether. I don't know what we have unary + for. It is a no-op (for all types) and serves no purpose. FWIW, in JS, +"abc" evaluates to NaN!


Added Done label.

@DartBot
Copy link
Author

DartBot commented Nov 9, 2011

This comment was originally written by [email protected]


Thanks for clarifying! Are you sure that you don't want us to implement + (non-number) -> NaN? It seems like such a valuable feature that I don't know why we would leave it out of dart <smile>. +1 to making + go away completely.

Minor suggestion. I would have found it easier to find the new spec rules if both + and ! were defined in the same clause either under prefixExpression or unaryExpression.

@DartBot DartBot added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Nov 9, 2011
nex3 pushed a commit that referenced this issue Aug 31, 2016
These files are no longer generated
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). P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

4 participants