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

dynamic calls on some operators seems broken? #502

Closed
vsmenon opened this issue Apr 15, 2016 · 3 comments
Closed

dynamic calls on some operators seems broken? #502

vsmenon opened this issue Apr 15, 2016 · 3 comments
Labels

Comments

@vsmenon
Copy link
Contributor

vsmenon commented Apr 15, 2016

The following Dart:

bool inRange(min, value, max) => (min <= value) && (value <= max);

void main() {
  var result = inRange(2, 7, 10);
  print(result);
}

generates this:

  test.inRange = function(min, value, max) {
    return dart.as(dart.dsend(min, '<=', value), core.bool)['&&'](dart.as(dart.dsend(value, '<=', max), core.bool));
  };

  test.main = function() {
    let result = setteronly.inRange(2, 7, 10);
    core.print(result);
  };

which, at runtime, triggers:

Uncaught TypeError: dart.as(...).&& is not a function

It's fine if inRange parameters are typed.

@rakudrama rakudrama self-assigned this Apr 29, 2016
@rakudrama
Copy link
Contributor

rakudrama commented Apr 29, 2016

The problem appears to be that the static type on parenthesized expressions is not updated by inserting reified coercions.
We can either make reify_coercions.dart adjust the static type on parentheses (or look through parentheses when querying the type - I prefer adjusting the tree to be correct).

We should also make boolean conversions explicit and lighter weight. e.g. rather than relying on

  if (dart.notNull(dart.as(x, core.bool))) ...

have something like

if (dart.test(x)) ...

@jmesserly
Copy link
Contributor

I prefer adjusting the tree to be correct

+1! :)

@rakudrama
Copy link
Contributor

Fixed by 961542e
Boolean conversion issue moved to #536

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants