-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more type `void` and `dynamic` tests
- Loading branch information
Showing
4 changed files
with
268 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion The special type `void` is used to indicate that the value of an | ||
/// expression is meaningless and intended to be discarded. | ||
/// | ||
/// @description Checks that a type with `void` bound is not treated the same | ||
/// way as the type `dynamic`, by attempting to invoke a non-existing member. | ||
/// @author [email protected] | ||
typedef Void = void; | ||
|
||
void f<T extends Void>(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class A<T extends Void> { | ||
T t; | ||
A(this.t); | ||
|
||
test() { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
class B { | ||
static void foo<T extends Void>(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
void bar<T extends Void>(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
mixin M<T extends Void> { | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
enum E<T extends Void> { | ||
e0; | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
class C {} | ||
|
||
extension Ext<T extends Void> on C { | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
extension type ET<T extends Void>(int _) { | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
main() { | ||
print(f); | ||
print(A); | ||
print(M); | ||
print(E); | ||
print(C); | ||
print(ET); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion If a generic type is used but type arguments are not provided, | ||
/// the type arguments default to type `dynamic`. | ||
/// | ||
/// @description Checks that a static type of a type parameter with no bounds is | ||
/// not treated the same way as the type `dynamic`, by attempting to invoke a | ||
/// non-existing member. | ||
/// @author [email protected] | ||
void f<T>(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class A<T> { | ||
T t; | ||
A(this.t); | ||
|
||
test() { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
class B { | ||
static void foo<T>(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
void bar<T>(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
mixin M<T> { | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
enum E<T> { | ||
e0; | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
class C {} | ||
|
||
extension Ext<T> on C { | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
extension type ET<T >(int _) { | ||
test(T t) { | ||
t.nonExistingMember; | ||
// ^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
main() { | ||
print(f); | ||
print(A); | ||
print(M); | ||
print(E); | ||
print(C); | ||
print(ET); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion If a generic type is used but type arguments are not provided, | ||
/// the type arguments default to type `dynamic`. | ||
/// | ||
/// @description Checks that a type with `dynamic` as a bound is treated the | ||
/// same as the type `dynamic`, and similarly for a bound which is a type alias | ||
/// of `dynamic`. | ||
/// @author [email protected] | ||
typedef Dynamic = dynamic; | ||
|
||
void f1<T extends dynamic>(T t) { | ||
t.whatever; | ||
} | ||
|
||
void f2<T extends Dynamic>(T t) { | ||
t.whatever; | ||
} | ||
|
||
class A<T1 extends dynamic, T2 extends Dynamic> { | ||
T1 t1; | ||
T2 t2; | ||
A(this.t1, this.t2); | ||
|
||
test() { | ||
t1.whatever; | ||
t2.whatever; | ||
} | ||
} | ||
|
||
class B { | ||
static void foo<T extends dynamic>(T t) { | ||
t.whatever; | ||
} | ||
void bar<T extends Dynamic>(T t) { | ||
t.whatever; | ||
} | ||
} | ||
|
||
mixin M<T extends dynamic> { | ||
test(T t) { | ||
t.whatever; | ||
} | ||
} | ||
|
||
enum E<T extends Dynamic> { | ||
e0; | ||
test(T t) { | ||
t.whatever; | ||
} | ||
} | ||
|
||
class C {} | ||
|
||
extension Ext<T extends dynamic> on C { | ||
test(T t) { | ||
t.whatever; | ||
} | ||
} | ||
|
||
extension type ET<T extends Dynamic>(int _) { | ||
test(T t) { | ||
t.whatever; | ||
} | ||
} | ||
|
||
main() { | ||
print(f1); | ||
print(f2); | ||
print(A); | ||
print(M); | ||
print(E); | ||
print(C); | ||
print(ET); | ||
} |