Sdk: strong mode: incorrectly handling plus on `T extends num`

Created on 3 Mar 2016  路  10Comments  路  Source: dart-lang/sdk

import 'dart:math' hide Point, Rectangle;
import 'dart:math' as math;
//...

class Point<T extends num> implements math.Point<T> {

  T x;
  T y;

  Point(this.x, this.y);
  // ...
  Point<T> operator +(math.Point<T> other) {
    return new Point<T>(x + other.x, y + other.y);
  }
  //...
  void offset(T dx, T dy) {
    x += dx;
    y += dy;
  }
}

x + other.x gives the warning: "unsound implicit cast from num to T"

Our logic for plus should understand that it will produce a T. Same problem with the other numeric operations (minus, multiply)

We also have a problem on the offset method. x += dx gives an even more confusing warning: "unsound implicit cast from T to T"

P1 analyzer-strong-mode area-analyzer type-bug

Most helpful comment

Thanks.
dart:math warnings/errors went from 29 to 8.

All 10 comments

Seen while looking at StageXL

CC @kevmoo

Maybe @leafpetersen or @munificent want to take a look at this one?
(I'm juggling various DDC CL's at the moment).

BTW Kevin, since this is "just" a warning, you could fix the other ones and ignore this for now. Though I suspect we'll hit this ourselves in fixing the SDK (dart:math Point probably has the same issue).

I'm hitting this now in dart:math.

I'm still clawing my way on top of loose ends from my vacation, but I'm happy to take this.

\o/ go for it!

Partial fix, without compound assignment.
https://codereview.chromium.org/1950983004

Fix for compound assignments.
https://codereview.chromium.org/1948293003

Fixed.

Thanks.
dart:math warnings/errors went from 29 to 8.

Was this page helpful?
0 / 5 - 0 ratings