Skip to content

Strong mode analyzer doesn't like subtype-overridden subclass members #24753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lexaknyazev opened this issue Oct 29, 2015 · 2 comments
Closed
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on

Comments

@lexaknyazev
Copy link
Contributor

Dart VM version: 1.13.0-dev.7.4 (Tue Oct 27 15:05:26 2015) on "windows_x64"

import 'dart:async';

abstract class Foo {
  EventSink<int> sink;
}

class BarSink implements EventSink<int> {
  void add(int event) {}
  void addError(errorEvent, [StackTrace stackTrace]) {}
  void close() {}
}

class Bar extends Foo {
  BarSink sink;
}

gives
Error:(14, 3) Invalid override. The type of Bar.sink= ((BarSink) → void) is not a subtype of Foo.sink= ((EventSink<int>) → void).

@bwilkerson bwilkerson added Type-Defect legacy-area-analyzer Use area-devexp instead. labels Oct 29, 2015
@vsmenon
Copy link
Member

vsmenon commented Oct 29, 2015

This is intentional, though we really need to improve the message here. The problem is that overriding the setter with a more specific type isn't sound. Code that is just setting the sink field of a Foo with a different EventSink<int> type could inadvertently violate the contract of Bar.

EventSink<int> sink = ...;
Foo f = ...;
f.sink = sink; // Can this ever fail?

Note, this is not a problem with getters. If you declared sink as a getter, you should be fine:

abstract class Foo {
  EventSink<int> get sink;
}

@munificent
Copy link
Member

Duplicate of #24928.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on and removed Priority-Medium labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

5 participants