Skip to content

Spurious compiler output when running Flutter tests #34031

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
Hixie opened this issue Jul 31, 2018 · 13 comments
Closed

Spurious compiler output when running Flutter tests #34031

Hixie opened this issue Jul 31, 2018 · 13 comments
Assignees
Labels
customer-flutter customer-fuchsia front-end-fasta P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Hixie
Copy link
Contributor

Hixie commented Jul 31, 2018

IMHO https://dart-review.googlesource.com/c/sdk/+/66160 should be reverted. It's causing spurious warnings when running Flutter's tests:

compiler message: widgets/editable_text_test.dart:1341:23: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(controls.handleCopy(any)).called(1);
compiler message:                       ^
compiler message: widgets/editable_text_test.dart:1344:23: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(controls.handleCut(any)).called(1);
compiler message:                       ^
compiler message: widgets/routes_test.dart:435:30: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(pageRouteAware1.didPush()).called(1);
compiler message:                              ^
compiler message: widgets/routes_test.dart:440:30: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(pageRouteAware1.didPushNext()).called(1);
compiler message:                              ^
compiler message: widgets/routes_test.dart:443:30: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(pageRouteAware2.didPush()).called(1);
compiler message:                              ^
compiler message: widgets/routes_test.dart:446:30: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(pageRouteAware2.didPop()).called(1);
compiler message:                              ^
compiler message: widgets/routes_test.dart:447:30: Warning: This expression has type 'void' and can't be used.
compiler message:       verify(pageRouteAware1.didPopNext()).called(1);
...

By "spurious" I mean that they are messages that the analyzer is not reporting, and that the code works fine.

IMHO the compiler should never output any messages except if it has a fatal error. The analyzer is the tool whose role it is to report problems, not the compiler.

cc @aam @peter-ahe-google

@aam
Copy link
Contributor

aam commented Jul 31, 2018

I imagine that flutter-specific compiler output filtering should be done in flutter engine frontend server, so dart commit would stay, but frontend server is extended with "quiet" mode.

@tvolkert
Copy link
Contributor

This can be seen in the following reduced case:

import 'package:mockito/mockito.dart';
import 'package:test/test.dart';

abstract class Foo {
  void bar(int value);
}

class MockFoo extends Mock implements Foo {}

void main() {
  test('wat?', () {
    Foo foo = new MockFoo();
    foo.bar(2);
    var value = verify(foo.bar(captureAny)).captured.single;
    expect(value, 2);
  });
}

This produces the following output:

$ dart lib/main.dart 
lib/main.dart:14:28: Warning: This expression has type 'void' and can't be used.
    var value = verify(foo.bar(captureAny)).captured.single;
                           ^
00:00 +0: wat?
00:00 +1: All tests passed!

This is showing up in Fuchsia builds as well.

@Hixie
Copy link
Contributor Author

Hixie commented Aug 11, 2018

That code is indeed pretty dubious (you're not supposed to be able to pass a void as an argument), but I guess that means the real question is why does the analyzer not report it?

@Hixie
Copy link
Contributor Author

Hixie commented Aug 11, 2018

cc @devoncarew

@devoncarew
Copy link
Member

but I guess that means the real question is why does the analyzer not report it

@MichaelRFairhurst, is this working as intended, or an analyzer bug?

@tvolkert
Copy link
Contributor

you're not supposed to be able to pass a void as an argument

What about:

verify<void>(foo.bar(captureAny))...

😉

@Hixie
Copy link
Contributor Author

Hixie commented Aug 12, 2018

That's pointless code. The argument can't be used.

@MichaelRFairhurst
Copy link
Contributor

That code is indeed pretty dubious (you're not supposed to be able to pass a void as an argument),

That's not true. A void value cannot be used, so the argument cannot be used in the function.

  f(void arg) {
    print(arg); // error, cannot use arg
  }

Void values are values with a bit saying "do not use." Its perfectly safe to provide any value to f(), including a void value. As opposed to Object, which cannot accept a void value but can accept everything else:

  acceptVoid(void x) {}
  acceptObject(Object x) {}

  acceptVoid(123); // valid
  acceptObject(123); // valid
  acceptVoid(print('')); // valid
  acceptObject(print('')); // invalid

We considered making the third option illegal, but there was no evidence it offered anything of value (no theoretical basis nor data suggesting so) and it would have been a change to mockito's API that would have had a less readable end result.

This was reported in the original flutter-dev post about void: https://groups.google.com/forum/#!searchin/flutter-dev/void$20mockito%7Csort:date/flutter-dev/scnh7SfYa_o/Mcqv70L6AAAJ

*Why ever pass void into a function?( It may seem strange, but it is useful for sequencing. Consider Mockito's nicely readable API: verify(mock.voidMethod()).called(1). This is only allowed where the parameter's type is void, either by definition or through inference on a type parameter.

I am working on a blog post that explains all this stuff better in one clear concise place.

but I guess that means the real question is why does the analyzer not report it?

This is a CFE bug, the analyzer is working correctly.

#33934

@MichaelRFairhurst
Copy link
Contributor

MichaelRFairhurst commented Aug 12, 2018 via email

@mit-mit
Copy link
Member

mit-mit commented Aug 13, 2018

cc @kmillikin

@kmillikin kmillikin self-assigned this Aug 14, 2018
@kmillikin kmillikin added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P1 A high priority bug; for example, a single project is unusable or has many test failures labels Aug 14, 2018
@kmillikin
Copy link

This is due to incorrect handling of void types. Closing in favor of #30470 which has some more discussion.

@kmillikin
Copy link

These warnings should be gone with 9bdf248. How can we verify that?

@aam
Copy link
Contributor

aam commented Sep 5, 2018

Once current dart->engine->flutter roll lands, we could confirm that flutter test run doesn't produce that diagnostic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-flutter customer-fuchsia front-end-fasta P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants