Skip to content
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

Zone-tests should use generic methods #121

Closed
floitschG opened this issue Aug 9, 2017 · 3 comments
Closed

Zone-tests should use generic methods #121

floitschG opened this issue Aug 9, 2017 · 3 comments
Assignees

Comments

@floitschG
Copy link
Contributor

I'm currently reworking the zones so that they are strong mode clean. In the future, arguments to the ZoneSpecification will require generic closures (for some arguments).

In particular, the following tests are affected:

LibTest/async/Zone/registerBinaryCallback_A01_t01.dart
LibTest/async/Zone/registerCallback_A01_t01.dart
LibTest/async/Zone/registerUnaryCallback_A01_t01.dart

Since the current specification ignores generic arguments, it should be safe to apply the changes already now.

Specifically, they need to be changed as follows:

--- registerCallback_A01_t01.dart.old   2017-08-09 12:18:10.525612538 +0200
+++ registerCallback_A01_t01.dart       2017-08-09 12:22:15.712031061 +0200
@@ -30,12 +30,9 @@
 
   Expect.isTrue(callback is ZoneCallback);
   Expect.equals(0, callback());
- 
-
-  dummy() => 42;
 
   z.fork(specification: new ZoneSpecification(registerCallback:
-        (Zone self, ZoneDelegate parent, Zone zone, f()) => dummy))
+        <R>(Zone self, ZoneDelegate parent, Zone zone, R f()) => () => 42 as R))
       .run(() {
         var callback = Zone.current.registerCallback(f);
         Expect.isTrue(callback is ZoneCallback);
--- registerUnaryCallback_A01_t01.dart.old      2017-08-09 12:14:24.431381935 +0200
+++ registerUnaryCallback_A01_t01.dart  2017-08-09 12:22:07.463949709 +0200
@@ -30,12 +30,10 @@
 
   Expect.isTrue(callback is ZoneUnaryCallback);
   Expect.equals(1, callback(1));
- 
-
-  dummy(_) => 42;
 
   z.fork(specification: new ZoneSpecification(registerUnaryCallback:
-        (Zone self, ZoneDelegate parent, Zone zone, f(arg)) => dummy))
+        <R, T>(Zone self, ZoneDelegate parent, Zone zone, R f(T arg)) =>
+            (_) => 42 as R))
       .run(() {
         var callback = Zone.current.registerUnaryCallback(f);
         Expect.isTrue(callback is ZoneUnaryCallback);
--- registerBinaryCallback_A01_t01.dart.old     2017-08-09 12:20:15.258842964 +0200
+++ registerBinaryCallback_A01_t01.dart 2017-08-09 12:22:22.536098367 +0200
@@ -33,10 +33,9 @@
   Expect.equals(3, callback(1,2));
  
 
-  dummy(_,__) => 42;
-
   z.fork(specification: new ZoneSpecification(registerBinaryCallback:
-        (Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) => dummy))
+        <R, T1, T2>(Zone self, ZoneDelegate parent, Zone zone,
+            R f(T1 arg1, T2 arg2)) => (_, __) => 42 as R))
       .run(() {
         var callback = Zone.current.registerBinaryCallback(f);
         Expect.isTrue(callback is ZoneBinaryCallback);
@alsemenov
Copy link
Contributor

alsemenov commented Aug 10, 2017

It seems to me that there is something wrong with return type of registerXXXCallback parameter value (which is function),
proposed:

<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) => () => 42 as R
<R, T>(Zone self, ZoneDelegate parent, Zone zone, R f(T arg)) =>  (_) => 42 as R
<R, T1, T2>(Zone self, ZoneDelegate parent, Zone zone, R f(T1 arg1, T2 arg2)) => (_, __) => 42 as R

I think it should be changed to

ZoneCallback<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) => () => 42 as R
ZoneUnaryCall<R, T>(Zone self, ZoneDelegate parent, Zone zone, R f(T arg)) =>  (_) => 42 as R
ZoneBinaryCallback<R, T1, T2>(Zone self, ZoneDelegate parent, Zone zone, R f(T1 arg1, T2 arg2)) => (_, __) => 42 as R

@floitschG, do you agree?

@floitschG
Copy link
Contributor Author

The <R> is not a return type. It's the generic argument to the closure.

<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) => () => 42 as R

This is a function that takes a generic argument R (and 4 normal arguments), and returns a closure that returns 42 cast to R.

The return type of the closure is "closure that returns R" -> ZoneCallback<R>. But that type is inferred.

If I wrote this function non-inline it would look like this:

ZoneCallback<R> registerFunction<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) {
  return () => 42 as R;
}

Feel free to write the test this way. It's probably easier to read.

@alsemenov
Copy link
Contributor

The initial proposal causes the dart analyzer to report an error:

D:\dev\dart\co19\LibTest\async\Zone>d:\dev\dart\dart-sdk\bin\dartanalyzer.bat --strong registerCallback_A01_t01.dart
Analyzing registerCallback_A01_t01.dart...
error - The argument type '(Zone, ZoneDelegate, Zone, () -> R) -> () -> R' can't be assigned to the parameter type 'RegisterCallbackHandler(Zone, ZoneDelegate, Zone, () -> dynamic) -> () -> dynamic' at registerCallback_A01_t01.dart:37:47 - argument_type_not_assignable
1 error found.

D:\dev\dart\co19\LibTest\async\Zone>d:\dev\dart\dart-sdk\bin\dartanalyzer.bat --version
dartanalyzer version 1.24.2

alsemenov added a commit that referenced this issue Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants