Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Conjunction evaluation is not short-circuiting #646

Closed
chalin opened this issue Feb 27, 2014 · 4 comments · Fixed by #683
Closed

Conjunction evaluation is not short-circuiting #646

chalin opened this issue Feb 27, 2014 · 4 comments · Fixed by #683
Milestone

Comments

@chalin
Copy link
Contributor

chalin commented Feb 27, 2014

In Angular 0.9.8 the test file below behaves as expected: x is initially null and if the button is clicked, it is set to 3. No errors are reported.

In the Angular version in git (tested with bb98990), just loading the file results in:

NoSuchMethodError: method not found: '>'
Receiver: null
Arguments: [0]
STACKTRACE:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      int.< (dart:core-patch/integers.dart:72)
#2      int.<= (dart:core-patch/integers.dart:81)
#3      _operation_less_or_equals_then (package:angular/core/scope.dart:962:56)
...

as if the conjunction && (at the line marked (*)) is no longer short-circuiting; i.e. the right conjunction 0 <= x is still being evaluated.


index.html

<!DOCTYPE html>
<html>
<head><title>Angular test</title></head>
<body>
  <button ng-click="x = 3">Set x to 3</button>
  <p ng-if="x == null">x is null. {{x}}</p>
  <p ng-if="x != null && 0 <= x">x is not negative. {{x}}</p> <!-- (*) -->

  <script type="application/dart">
    import 'package:angular/angular.dart';
    void main() { ngBootstrap(); }
    </script>
  <script src="packages/browser/dart.js"></script>
</body>
</html>
@vicb vicb self-assigned this Mar 3, 2014
@vicb vicb added this to the v0.9.9 milestone Mar 3, 2014
@vicb vicb removed their assignment Mar 3, 2014
@jbdeboer jbdeboer added the bug label Mar 5, 2014
@jbdeboer jbdeboer self-assigned this Mar 5, 2014
@jbdeboer
Copy link
Contributor

jbdeboer commented Mar 5, 2014

@mhevery

With the following element: <div><span ng-if="x != null && 0 <= x">content</span></div>, change detection produces the following watches:

WATCHES: :!=(x, null), :<=(0, x), :&&(!=(x, null), <=(0, x))
WatchGroup[](watches: :!=(x, null), :<=(0, x), :&&(!=(x, null), <=(0, x)))

It looks like we are missing a short-circuit feature in change detection.

@jbdeboer
Copy link
Contributor

jbdeboer commented Mar 5, 2014

Talking to Misko, we don't have short circuits anymore. The real bug here is that 0 <= x is throwing an exception. #683 should fix that bug.

Since Angular handles nulls well, you don't need to say x != null && 0 <= x, 0 <= x is better.

@chalin
Copy link
Contributor Author

chalin commented Mar 6, 2014

@jbdeboer, @mhevery

Talking to Misko, we don't have short circuits anymore. The real bug here is that 0 <= x is throwing an exception. #683 should fix that bug.

Does this also mean that there is no short-circuiting for the ternary operator ?: ? (As you probably know, && and || are sugar for particular applications of ?: --- e.g., see here).

@jbdeboer
Copy link
Contributor

jbdeboer commented Mar 6, 2014

That is correct. Implementing short circuits will be fairly complicated and we don't have good use-cases for them at the moment.

chirayuk added a commit to chirayuk/angular.dart that referenced this issue Mar 7, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

3 participants