Skip to content

Commit

Permalink
#2956. Add more type void and dynamic tests (#2987)
Browse files Browse the repository at this point in the history
Add more type `void` and `dynamic` tests
  • Loading branch information
sgrekhov authored Nov 20, 2024
1 parent ab5502e commit abb9d2b
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Language/Types/Type_Void/type_void_A04_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
void f<T extends void>() {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified>
// [cfe] unspecified

class A<T extends void> {}
// ^^^^
Expand All @@ -23,11 +23,11 @@ class B {
static void foo<T extends void>() {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified>
// [cfe] unspecified
void bar<T extends void>() {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified>
// [cfe] unspecified
}

mixin M<T extends void> {}
Expand Down
94 changes: 94 additions & 0 deletions Language/Types/Type_Void/type_void_A04_t03.dart
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);
}
93 changes: 93 additions & 0 deletions Language/Types/Type_dynamic/generic_A01_t01.dart
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);
}
78 changes: 78 additions & 0 deletions Language/Types/Type_dynamic/generic_A02_t01.dart
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);
}

0 comments on commit abb9d2b

Please sign in to comment.