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

Operators are not properly checked #18

Closed
vsmenon opened this issue Jan 7, 2015 · 5 comments
Closed

Operators are not properly checked #18

vsmenon opened this issue Jan 7, 2015 · 5 comments
Assignees

Comments

@vsmenon
Copy link
Contributor

vsmenon commented Jan 7, 2015

Adding the following test - see the "should be" cases below:

      class A {
        A operator *(B b) {}
        A operator /(B b) {}
        A operator ~/(B b) {}
        A operator %(B b) {}
        A operator +(B b) {}
        A operator -(B b) {}
        A operator <<(B b) {}
        A operator >>(B b) {}
        A operator &(B b) {}
        A operator ^(B b) {}
        A operator |(B b) {}
      }

      class B {
        A operator -(B b) {}
      }

      foo() => new A();

      test() {
        A a = new A();
        B b = new B();
        var c = foo();
        a = a * b;
        a = a * /*pass should be info:DownCast*/c;
        a = a / b;
        a = a ~/ b;
        a = a % b;
        a = a + b;
        a = a + /*pass should be severe:StaticTypeError*/a;
        a = a - b;
        b = /*severe:StaticTypeError*/b - b;
        a = a << b;
        a = a >> b;
        a = a & b;
        a = a ^ b;
        a = a | b;
        c = (/*pass should be warning:DynamicInvoke*/c + b);
      }
@vsmenon vsmenon self-assigned this Jan 8, 2015
@vsmenon
Copy link
Contributor Author

vsmenon commented Jan 8, 2015

More breakage:

double x = 0.0;
x += 1;

fails with a StaticTypeError - we think x + 1 is num (as per spec) and have no place to inject a cast (without rewriting).

The error message is screwy as well (double is not double).

@jacob314
Copy link
Contributor

jacob314 commented Jan 8, 2015

here's one more case:

class Foo {
int length;
}
var list = [];

var y = 0;
list.forEach((x) => /* DDC:severe: StaticTypeError, Type check failed: y += x.length (num) is not of type int */y += x.length);

Another important case is where the list doesn't have a type. Here inference can't help and we need to make sure the error given to the user is understandable. The error/warning/info should be about a dynamic cast from dynamic to int not that num is not an int.

var list = [];
var y = 0;
list.forEach((x) => /* DDC:severe: StaticTypeError, Type check failed: y += x.length (num) is not of type int */y += x.length);

@jacob314
Copy link
Contributor

jacob314 commented Jan 8, 2015

int direction *= -1;

  •  /\* DDC:severe: StaticTypeError, Type check failed: direction *= -1 (num) is not of type int */direction *= -1;
    

@vsmenon
Copy link
Contributor Author

vsmenon commented Jan 9, 2015

One more broken variant:
/* DDC:severe: StaticTypeError, Type check failed: foo[i] += 1 (double) is not of type double */
where foo is Float64List. The error is broken as well here.

@vsmenon
Copy link
Contributor Author

vsmenon commented Jan 12, 2015

These should be fixed now.

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

No branches or pull requests

2 participants