Confused by operator precedence between cascade and assignment

484 views
Skip to first unread message

Sorra Dawnstar

unread,
Apr 19, 2013, 1:50:32 PM4/19/13
to mi...@dartlang.org
According to the precedence table, '..' is higher than '='.

But how about the below code?

void main() {

  var m1 = new My('M1');
  var m2 = new My('M2');
  m1.test()..s = m2.test()..toString();
  
}

class My {
  String s;
  My(this.s);
  test(){return this;}
}

Lasse R.H. Nielsen

unread,
Apr 19, 2013, 2:15:49 PM4/19/13
to mi...@dartlang.org
That will be equivalent to:

main() {
  var m1 = new My('M1');
  var m2 = new My('M2');
  var v = m1.test();
  v.s = m2.test();
  v.toString();
}

/L


--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 



--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

Sorra Dawnstar

unread,
Apr 19, 2013, 11:01:41 PM4/19/13
to mi...@dartlang.org
Yes it runs like that. Doesn't it break the operator precedence?

在 2013年4月20日星期六UTC+8上午2时15分49秒,Lasse Reichstein Holst Nielsen写道:

Sorra Dawnstar

unread,
Apr 19, 2013, 11:01:51 PM4/19/13
to mi...@dartlang.org
Yes it runs like that. Doesn't it break the operator precedence?

在 2013年4月20日星期六UTC+8上午2时15分49秒,Lasse Reichstein Holst Nielsen写道:
That will be equivalent to:

Lasse R.H. Nielsen

unread,
Apr 20, 2013, 3:19:41 PM4/20/13
to mi...@dartlang.org
On Sat, Apr 20, 2013 at 5:01 AM, Sorra Dawnstar <sorrad...@gmail.com> wrote:
Yes it runs like that. Doesn't it break the operator precedence?

Yes and no - aka. it depends on how you look at it.
It helps to think of ".." as not really an operator, but more like a scoping construct (like parentheses). It creates a new scope from the ".." to either the next "..", or the first other scope delimiter (";", ")", "}" or similar).

/L
Reply all
Reply to author
Forward
0 new messages