Compile time error on incomplete interfaces

22 views
Skip to first unread message

Cogman

unread,
May 21, 2013, 3:07:29 PM5/21/13
to mi...@dartlang.org
class Test
{
  final int _x;
  final int _y;
  
  int get x => _x + 7;
  int get y => 8;
  
  Test.forThing(this._x, this._y);
}

abstract class Tester
{
  int get y;
}

class Jim implements Test, Tester
{
  int get x => 7;
  Jim();
}

void main() {
  Test bob = new Test.forThing(1, 2);
  Test jim = new Jim();
  print(jim.y);
}

Lets say we have the above code.

Now, I can understand not forcing Jim to implement all methods of Test (after all, it may only use 1 or 2 of those methods.) However, it looks like the fact that jim calls the y getter should have immediately thrown a compile time error since Jim doesn't implement a y getter.

Does that sound too crazy?  I just prefer the compile time errors to runtime errors.  I don't know how complex it would be to check that, but I think it might be worth it.

Alan Knight

unread,
May 21, 2013, 3:36:33 PM5/21/13
to General Dart Discussion
The editor used to report unimplemented abstract methods from superclasses. I presume that it's one of the things that hasn't yet been turned on with the new analyzer, but should be soon.


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
 
 

Kasper Lund

unread,
May 21, 2013, 3:40:36 PM5/21/13
to General Dart Discussion, Jaime Wren

As far as I know this warning is almost ready to turned on again. Jaime knows the details!

Cheers,
Kasper

Jaime Wren

unread,
May 21, 2013, 4:12:23 PM5/21/13
to Kasper Lund, General Dart Discussion
It was not trivial to check for all cases specified by the Language Spec, but fortunately we started work on this a little while ago:

Committed this morning with https://codereview.chromium.org/15500002/ (svn version 22949), "Jim" now has a warning.

In cases where there is a single missing override the name of the method/member is in the error code; in cases where there are multiple missing members "missing inherited members" is the error code.  When priorities allow, we'll put a quick fix on the error code to auto-insert the missing methods/getters/setters to resolve the warning.  I expect this to be especially helpful when your interface(s) have many members to override.

- Jaime
Jaime Wren |  Software Engineer | jw...@google.com |  503.877.9736
Reply all
Reply to author
Forward
0 new messages