Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Issue 2707933002: Tests for `void`.

Created:
3 years, 10 months ago by floitsch
Modified:
3 years, 5 months ago
CC:
reviews_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Tests for `void`.

Patch Set 1 #

Patch Set 2 : Add main. #

Patch Set 3 : More tests. #

Total comments: 63

Patch Set 4 : Rebase #

Patch Set 5 : Address comments. #

Total comments: 64
Unified diffs Side-by-side diffs Delta from patch set Stats (+616 lines, -0 lines) Patch
A tests/language/void_type2_test.dart View 1 2 3 4 1 chunk +346 lines, -0 lines 41 comments Download
A tests/language/void_type3_test.dart View 1 chunk +108 lines, -0 lines 3 comments Download
A tests/language/void_type4_test.dart View 1 2 3 4 1 chunk +125 lines, -0 lines 20 comments Download
A tests/language/void_type5_test.dart View 1 2 3 4 1 chunk +37 lines, -0 lines 0 comments Download

Messages

Total messages: 10 (3 generated)
Lasse Reichstein Nielsen
https://codereview.chromium.org/2707933002/diff/40001/tests/language/generic_function_typedef_test.dart File tests/language/generic_function_typedef_test.dart (right): https://codereview.chromium.org/2707933002/diff/40001/tests/language/generic_function_typedef_test.dart#newcode8 tests/language/generic_function_typedef_test.dart:8: class A { Isn't used. https://codereview.chromium.org/2707933002/diff/40001/tests/language/generic_function_typedef_test.dart#newcode11 tests/language/generic_function_typedef_test.dart:11: typedef F<T> ...
3 years, 10 months ago (2017-02-21 09:37:04 UTC) #2
eernst
Several comments on the `void` related tests. (Just one comment on the `Function` type part. ...
3 years, 10 months ago (2017-02-21 13:39:13 UTC) #4
floitsch
Only addressed the comments. Not yet taking the feedback from the meeting into account. https://codereview.chromium.org/2707933002/diff/40001/tests/language/void_type2_test.dart ...
3 years, 10 months ago (2017-02-22 14:44:43 UTC) #5
Leaf
Not sure of the strong/non-strong status of these tests, should maybe add language_strong versions? https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_type2_test.dart ...
3 years, 10 months ago (2017-02-23 21:30:53 UTC) #7
Lasse Reichstein Nielsen
https://codereview.chromium.org/2707933002/diff/40001/tests/language/void_type4_test.dart File tests/language/void_type4_test.dart (right): https://codereview.chromium.org/2707933002/diff/40001/tests/language/void_type4_test.dart#newcode114 tests/language/void_type4_test.dart:114: A<dynamic> a4 = new A<void>(); /// dynamic_assignment: ok? > ...
3 years, 6 months ago (2017-06-02 11:14:23 UTC) #8
eernst
Have to go now -- remaining comments on void_type4_test.dart will follow tomorrow. https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_type2_test.dart File tests/language/void_type2_test.dart ...
3 years, 5 months ago (2017-07-10 16:05:34 UTC) #9
eernst
3 years, 5 months ago (2017-07-11 08:45:43 UTC) #10
Added comments on the remaining test cases.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
File tests/language/void_type4_test.dart (right):

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:72: Object x;  /// 04: ok?   should be ok,
but the setter goes from void to Object.
On 2017/02/23 21:30:53, Leaf wrote:
> I think not ok, at least not as we've formulated this.  I still feel like
we're
> in a bit of a state of confusion as to whether we want void to be equivalent
to
> Object and dynamic + some lints, or void to be a supertype of Object and
> dynamic.  But current thinking seems to be in favor of the supertype
treatment,
> and I think it's just weird to special case out things like this one.

The informal spec of generalized void is built on the following foundation:
`void` is the same type as `Object`, except (1) expressions of type void cannot
occur in certain locations, (2: in the future) voidness preservation, and (3)
function types with `void` as the return type preserve their special placement
in the subtype lattice.

For Dart 2 we will drop (3), which is the only case where `void` is considered
to be a proper supertype of `Object`. Actually, I'd prefer to say that the
special subtype rule for `void Function(...)` is just an explicitly specified
exception; it is not helpful to actually make `void` a proper supertype of
`Object`, because that in turn will require many new exceptions to "undo" that
placement of `void` (such that `void` and `Object` are considered to be the same
type everywhere else).

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:79: Object  /// 05: error
We will only get an error here if we introduce a notion of voidness preservation
for overriding. (In that case the supertype `gee` receives an argument of type
`void` which implies that "the argument is unused", but D.gee grabs the right to
use that argument anyway).

So this is not an error by the current informal spec, but we could add some
simple voidness preservation rules for overriding and make it an error.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:84: A<Object>  /// 06: error
This parameter type was declared as `A<void>` in `A<T>`, so it's an override
`A<void>` --> `A<Object>` in a contravariant position.

We will only get an error here with some kind of voidness preservation for
overriding, and it must be the "full" kind that takes `void` into account also
when it is not the top-level type (that is, when `void` occurs in the actual
type arguments of a generic type or in the argument types or return type of a
function type).

I can't see how it would make sense to add that kind of voidness preservation
checking for overrides without also adding full voidness preservation checking
for data flow (assignments, parameter passing, etc.).

This should then not be an error.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:87: A<Object>  /// 07: error
This parameter type was declared as `A<T>` in `A<T>`, so it's an override
`A<void>` --> `A<Object>` in a contravariant position: Same as line 84, should
not be an error.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:115: <void>   /// implicit_downcast: error
This can only be an error with full support for voidness preservation, so it
should not be an error at this point.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:117: A a3 = new A<void>();  ///
raw_assignment: ok?
Since we don't have voidness preservation at this point this is not an error in
any case (considered as `A<dynamic> a3 = new A<Object>();`).

I made the distinction between "strict" and "normal" voidness preservation
rulesets: The strict ones would disallow assignments where `void` derived
expressions were retyped as `dynamic` (e.g., `new A<void>().foo()` is `void` but
`a3.foo()` is `dynamic`), but I always considered the strict systems to be for
discussion only because everybody else seemed to think that this transition
would obviously be OK.

In that case it is not an error, even with full voidness preservation: It's `ok`
now and in the future.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:118: A<dynamic> a4 = new A<void>();  ///
A_dynamic_assignment: ok?
Same as line 117.

https://codereview.chromium.org/2707933002/diff/80001/tests/language/void_typ...
tests/language/void_type4_test.dart:119: dynamic a5 = new A<void>();  ///
dynamic_assignment: ok?
Since we don't have voidness preservation at this point, this is not an error in
any case.

However, this would never be a voidness preservation violation, no matter which
one of the voidness preservation rulesets we'd use. The point is that it is an
upcast that eliminates the class `A` from the type of the target object (and all
supertypes where its type argument is propagated, which is the empty set), so
we've "forgotten the voidness provided by the type argument to `A`".
 

It is true that `a5.foo()` is an untyped invocation of type `dynamic`, and `new
A<void>().foo()` has type `void`, but we cannot consider that to be a voidness
preservation violation. If we had considered it to be a violation then all data
flows (assignments, parameter passings, returns, etc) from a type containing
void to `dynamic` would be violations, which is even more strict than the
"strict rulesets" I mentioned above.

So this should be OK now and in the future.

Powered by Google App Engine
This is Rietveld 408576698