Navigation Menu

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 concatenation error: String + String not a constant operation. #15853

Closed
DartBot opened this issue Jan 2, 2014 · 8 comments
Closed

String concatenation error: String + String not a constant operation. #15853

DartBot opened this issue Jan 2, 2014 · 8 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 2, 2014

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


What steps will reproduce the problem?

  1. For full steps to reproduce, see:
    http://stackoverflow.com/questions/20883018/dart-string-concatenation-error-exptected-type-is-num

What is the expected output? What do you see instead?
Expected Dart to allow string to be concatenated. Instead Dart issues compiler error stating "An expression of type 'num' was expected."

What version of the product are you using? On what operating system?
Dart 1.0.0 (r30798)
64-bit Ubuntu 12.04

Please provide any additional information below.

@lrhn
Copy link
Member

lrhn commented Jan 2, 2014

This is (sadly) working as intended.
The "+" operator on strings is not considered a compile time constant operation, because it's not listed in the list of such in "Constants" section of the specification.

The "+" operator on Strings was introduced later in the language's life, when that list was already written, so we should consider adding it as well.

I'm making this an enhancement request on the specification, to add String + String as a constant expression.


cc @gbracha.
Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.
Changed the title to: "String concatenation error: String + String not a constant operation.".

@lrhn
Copy link
Member

lrhn commented Feb 20, 2014

Please add 'String * int' as a constant expression as well as 'String + String'.

@gbracha
Copy link
Contributor

gbracha commented Feb 20, 2014

String * int?

@kevmoo
Copy link
Member

kevmoo commented Apr 5, 2014

"foo" * 3 => "foofoofoo"

@gbracha
Copy link
Contributor

gbracha commented Aug 27, 2014

Set owner to @gbracha.
Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented Jan 3, 2015

So String+ String is a constant (and has been for a while). String* int isn't and is not expected to be.


Added Done label.

@DartBot
Copy link
Author

DartBot commented Feb 13, 2015

This comment was originally written by @mezoni


"foo" * 3 => "foofoofoo"

Is this also constant?

"foofoofoo" ~/ 3 => "foo"
  

@lrhn
Copy link
Member

lrhn commented Feb 13, 2015

Sorry, only (integer) scalar multiplication is available, there are no multiplicative inverses on strings.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Feb 13, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Mar 1, 2016
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). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants