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

String concat operator '+' perhaps binding too strongly. #428

Closed
DartBot opened this issue Nov 11, 2011 · 2 comments
Closed

String concat operator '+' perhaps binding too strongly. #428

DartBot opened this issue Nov 11, 2011 · 2 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@DartBot
Copy link

DartBot commented Nov 11, 2011

This issue was originally filed by [email protected]


What steps will reproduce the problem?

  1. var s = 'hello' + foo != null ? " world." : "";

What is the expected output? What do you see instead?

I expected the entire expression after the + operator to be evaluated before being bound to the operator itself. The operator is binding strongly to the 'foo' Object, rather than the expression result.

The following works however, because of the explicit binding defined by the parenthesis:
var s = 'hello' + (foo != null ? " world." : "");

What version of the product are you using? On what operating system?
Version 0.1.0.201111090748
Dart Editor: build 1357

Please provide any additional information below.

@whesse
Copy link
Contributor

whesse commented Nov 14, 2011

The precedence of the operators (binding strength) is decided by the parser, so addition of two numbers and concatenation of two strings must have the same binding strength. In general, it is impossible to know what the types of the inputs to a "+" operation are statically - they must be tested dynamically at runtime.

Because the order of operations is based on that of C-family and Java-family languages, and people really want to be able to write tests like
sum == subtotal_a + subtotal_b, et. cetera, it is impossible
to make + bind less tightly than comparisons. The conditional operator (a ? b : c)
binds even less tightly, so your expectation about the binding of + is very different
from the expectations of most programmers.


Added WontFix label.

@DartBot
Copy link
Author

DartBot commented Nov 14, 2011

This comment was originally written by [email protected]


You're right, I checked the expression binding in C# and it works the
same.. I'll make a note not to submit "bugs" after marathon coding
sessions anymore.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

3 participants