-
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 extension type tests for union types
- Loading branch information
Showing
20 changed files
with
1,573 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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 An extension type `V` is a proper subtype of `Object?`. It is | ||
/// potentially non-nullable, unless it implements `Object` or a subtype thereof | ||
/// | ||
/// @description Checks that an extension type is assignable to a type `T?` when | ||
/// it implements `T` | ||
/// @author sgrekhov22@gmail.com | ||
import "../../Utils/expect.dart"; | ||
|
||
extension type ET(int _) implements int {} | ||
|
||
main() { | ||
int? et = null; | ||
if (2 > 1) { | ||
et = ET(1); | ||
} | ||
int x = et is int ? et : 2; | ||
Expect.equals(1, x); | ||
} |
121 changes: 121 additions & 0 deletions
121
TypeSystem/subtyping/dynamic/generated/extension_type_arguments_binding_A11_t01.dart
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,121 @@ | ||
// Copyright (c) 2023, 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 We say that a type T0 is a subtype of a type T1 (written | ||
/// T0 <: T1) when: | ||
/// Assume that DV declares an extension type declaration named Name with type | ||
/// parameters X1 .. Xs, and V1 is a superinterface of DV. Then Name<T1, .. Ts> | ||
/// is a subtype of [T1/X1 .. Ts/Xs]V1 for all T1, .. Ts. | ||
/// | ||
/// @description Check that an extension type `ET` that implements `S` is a | ||
/// subtype of `FutureOr<S>`. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 55578 | ||
/// | ||
/// @description Check that if type T0 is a subtype of a type T1, then instance | ||
/// of T0 can be used as an argument of type T1 | ||
/// @author sgrekhov@unipro.ru | ||
/// | ||
/// This test is generated from test_types/extension_type_A11.dart and | ||
/// test_cases/arguments_binding_x01.dart. Don't modify it! | ||
/// If you need to change this test, then change one of the files above and then | ||
/// run generator/generator.dart to regenerate the tests. | ||
import '../../utils/common.dart'; | ||
|
||
import "dart:async"; | ||
|
||
extension type ET(Future<int> _) implements Future<int> {} | ||
|
||
ET t0Instance = ET(Future<int>(() => 2)); | ||
|
||
const t1Default = 42; | ||
|
||
namedArgumentsFunc1(FutureOr<int> t1, {FutureOr<int> t2 = t1Default}) {} | ||
positionalArgumentsFunc1(FutureOr<int> t1, [FutureOr<int> t2 = t1Default]) {} | ||
|
||
namedArgumentsFunc2<X>(X t1, {required X t2}) {} | ||
|
||
class ArgumentsBindingClass { | ||
ArgumentsBindingClass(FutureOr<int> t1) {} | ||
|
||
ArgumentsBindingClass.named(FutureOr<int> t1, {FutureOr<int> t2 = t1Default}) {} | ||
ArgumentsBindingClass.positional(FutureOr<int> t1, [FutureOr<int> t2 = t1Default]) {} | ||
|
||
factory ArgumentsBindingClass.fNamed(FutureOr<int> t1, {FutureOr<int> t2 = t1Default}) { | ||
return new ArgumentsBindingClass.named(t1, t2: t2); | ||
} | ||
factory ArgumentsBindingClass.fPositional(FutureOr<int> t1, [FutureOr<int> t2 = t1Default]) { | ||
return new ArgumentsBindingClass.positional(t1, t2); | ||
} | ||
|
||
static namedArgumentsStaticMethod(FutureOr<int> t1, {FutureOr<int> t2 = t1Default}) {} | ||
static positionalArgumentsStaticMethod(FutureOr<int> t1, [FutureOr<int> t2 = t1Default]) {} | ||
|
||
namedArgumentsMethod(FutureOr<int> t1, {FutureOr<int> t2 = t1Default}) {} | ||
positionalArgumentsMethod(FutureOr<int> t1, [FutureOr<int> t2 = t1Default]) {} | ||
|
||
set testSetter(FutureOr<int> val) {} | ||
} | ||
|
||
class ArgumentsBindingGen<X> { | ||
ArgumentsBindingGen(X t1) {} | ||
|
||
ArgumentsBindingGen.named(X t1, {required X t2}) {} | ||
|
||
factory ArgumentsBindingGen.fNamed(X t1, {required X t2}) { | ||
return new ArgumentsBindingGen.named(t1, t2: t2); | ||
} | ||
|
||
namedArgumentsMethod(X t1, {required X t2}) {} | ||
|
||
set testSetter(X val) {} | ||
} | ||
|
||
main() { | ||
// test functions | ||
namedArgumentsFunc1(forgetType(t0Instance), t2: forgetType(t0Instance)); | ||
positionalArgumentsFunc1(forgetType(t0Instance), forgetType(t0Instance)); | ||
|
||
// test class constructors | ||
ArgumentsBindingClass instance1 = | ||
new ArgumentsBindingClass(forgetType(t0Instance)); | ||
instance1 = new ArgumentsBindingClass.fNamed(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
instance1 = new ArgumentsBindingClass.named(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
instance1 = new ArgumentsBindingClass.positional(forgetType(t0Instance), | ||
forgetType(t0Instance)); | ||
|
||
// tests methods and setters | ||
instance1.namedArgumentsMethod(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
instance1.positionalArgumentsMethod(forgetType(t0Instance), | ||
forgetType(t0Instance)); | ||
instance1.testSetter = forgetType(t0Instance); | ||
|
||
// test static methods | ||
ArgumentsBindingClass.namedArgumentsStaticMethod(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
ArgumentsBindingClass.positionalArgumentsStaticMethod( | ||
forgetType(t0Instance), forgetType(t0Instance)); | ||
|
||
// Test type parameters | ||
|
||
// test generic functions | ||
namedArgumentsFunc2<FutureOr<int>>(forgetType(t0Instance), t2: forgetType(t0Instance)); | ||
|
||
// test generic class constructors | ||
ArgumentsBindingGen<FutureOr<int>> instance2 = | ||
new ArgumentsBindingGen<FutureOr<int>>(forgetType(t0Instance)); | ||
instance2 = new ArgumentsBindingGen<FutureOr<int>>.fNamed(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
instance2 = new ArgumentsBindingGen<FutureOr<int>>.named(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
|
||
// test generic class methods and setters | ||
instance2.namedArgumentsMethod(forgetType(t0Instance), | ||
t2: forgetType(t0Instance)); | ||
instance2.testSetter = forgetType(t0Instance); | ||
} |
125 changes: 125 additions & 0 deletions
125
TypeSystem/subtyping/dynamic/generated/extension_type_arguments_binding_A11_t02.dart
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,125 @@ | ||
// Copyright (c) 2023, 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 We say that a type T0 is a subtype of a type T1 (written | ||
/// T0 <: T1) when: | ||
/// Assume that DV declares an extension type declaration named Name with type | ||
/// parameters X1 .. Xs, and V1 is a superinterface of DV. Then Name<T1, .. Ts> | ||
/// is a subtype of [T1/X1 .. Ts/Xs]V1 for all T1, .. Ts. | ||
/// | ||
/// @description Check that an extension type `ET` that implements `S` is a | ||
/// subtype of `FutureOr<S>`. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 55578 | ||
/// | ||
/// @description Check that if type T0 is a subtype of a type T1, then instance | ||
/// of T0 can be used as an argument of type T1. Test superclass members | ||
/// @author sgrekhov@unipro.ru | ||
/// | ||
/// This test is generated from test_types/extension_type_A11.dart and | ||
/// test_cases/arguments_binding_x02.dart. Don't modify it! | ||
/// If you need to change this test, then change one of the files above and then | ||
/// run generator/generator.dart to regenerate the tests. | ||
import '../../utils/common.dart'; | ||
|
||
import "dart:async"; | ||
|
||
extension type ET(Future<int> _) implements Future<int> {} | ||
|
||
FutureOr<int> t1Instance = Future<int>(() => 1); | ||
ET t0Instance = ET(Future<int>(() => 2)); | ||
|
||
const t1Default = 42; | ||
|
||
class ArgumentsBindingSuper1_t02 { | ||
FutureOr<int> m; | ||
|
||
ArgumentsBindingSuper1_t02(FutureOr<int> value): m = value {} | ||
ArgumentsBindingSuper1_t02.named(FutureOr<int> value, {FutureOr<int> val2 = t1Default}): m = value {} | ||
ArgumentsBindingSuper1_t02.positional(FutureOr<int> value, [FutureOr<int> val2 = t1Default]): m = value {} | ||
ArgumentsBindingSuper1_t02.short(this.m); | ||
|
||
void superTest(FutureOr<int> val) {} | ||
void superTestPositioned(FutureOr<int> val, [FutureOr<int> val2 = t1Default]) {} | ||
void superTestNamed(FutureOr<int> val, {FutureOr<int> val2 = t1Default}) {} | ||
FutureOr<int> get superGetter => m; | ||
void set superSetter(FutureOr<int> val) {} | ||
} | ||
|
||
class ArgumentsBinding1_t02 extends ArgumentsBindingSuper1_t02 { | ||
ArgumentsBinding1_t02(dynamic t1) : super(t1) {} | ||
ArgumentsBinding1_t02.c2(dynamic t1, dynamic t2) : super.named(t1, val2: t2) {} | ||
ArgumentsBinding1_t02.c3(dynamic t1) : super.positional(t1) {} | ||
ArgumentsBinding1_t02.c4(dynamic t1, dynamic t2) : super.positional(t1, t2) {} | ||
ArgumentsBinding1_t02.c5(dynamic t1) : super.short(t1) {} | ||
|
||
test(dynamic t1, dynamic t2) { | ||
superTest(t1); | ||
superTestPositioned(t1); | ||
superTestPositioned(t2, t1); | ||
superTestNamed(t1); | ||
superTestNamed(t2, val2: t1); | ||
superSetter = t1; | ||
m = t1; | ||
superGetter; | ||
} | ||
} | ||
|
||
class ArgumentsBindingSuper2_t02<X> { | ||
X m; | ||
|
||
ArgumentsBindingSuper2_t02(X value) : m = value {} | ||
ArgumentsBindingSuper2_t02.named(X value, {required X val2}) : m = value {} | ||
ArgumentsBindingSuper2_t02.short(this.m); | ||
|
||
void superTest(X val) {} | ||
void superTestNamed(X val, {required X val2}) {} | ||
X get superGetter => m; | ||
void set superSetter(X val) {} | ||
} | ||
|
||
class ArgumentsBinding2_t02<X> extends ArgumentsBindingSuper2_t02<X> { | ||
ArgumentsBinding2_t02(X t1) : super(t1) {} | ||
ArgumentsBinding2_t02.c2(X t1, X t2) : super.named(t1, val2: t2) {} | ||
ArgumentsBinding2_t02.c5(X t1) : super.short(t1) {} | ||
|
||
test(X t1, X t2) { | ||
superTest(t1); | ||
superTestNamed(t2, val2: t1); | ||
superSetter = t1; | ||
m = t1; | ||
superGetter; | ||
} | ||
} | ||
|
||
main() { | ||
ArgumentsBinding1_t02 c1 = new ArgumentsBinding1_t02(t0Instance); | ||
c1 = new ArgumentsBinding1_t02.c2(t1Instance, t0Instance); | ||
c1 = new ArgumentsBinding1_t02.c3(t0Instance); | ||
c1 = new ArgumentsBinding1_t02.c4(t1Instance, t0Instance); | ||
c1 = new ArgumentsBinding1_t02.c5(t0Instance); | ||
|
||
c1.test(t0Instance, t1Instance); | ||
c1.superTest(forgetType(t0Instance)); | ||
c1.superTestPositioned(forgetType(t0Instance)); | ||
c1.superTestPositioned(t1Instance, forgetType(t0Instance)); | ||
c1.superTestNamed(forgetType(t0Instance)); | ||
c1.superTestNamed(t1Instance, val2: forgetType(t0Instance)); | ||
c1.superSetter = forgetType(t0Instance); | ||
c1.superGetter; | ||
|
||
// Test type parameters | ||
|
||
ArgumentsBinding2_t02<FutureOr<int>> c2 = | ||
new ArgumentsBinding2_t02<FutureOr<int>>(forgetType(t0Instance)); | ||
c2 = new ArgumentsBinding2_t02<FutureOr<int>>.c2(t1Instance, forgetType(t0Instance)); | ||
c2 = new ArgumentsBinding2_t02<FutureOr<int>>.c5(forgetType(t0Instance)); | ||
|
||
c2.test(forgetType(t0Instance), t1Instance); | ||
c2.superTest(forgetType(t0Instance)); | ||
c2.superTestNamed(t1Instance, val2: forgetType(t0Instance)); | ||
c2.superSetter = forgetType(t0Instance); | ||
c2.superGetter; | ||
} |
93 changes: 93 additions & 0 deletions
93
TypeSystem/subtyping/dynamic/generated/extension_type_arguments_binding_A11_t03.dart
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) 2023, 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 We say that a type T0 is a subtype of a type T1 (written | ||
/// T0 <: T1) when: | ||
/// Assume that DV declares an extension type declaration named Name with type | ||
/// parameters X1 .. Xs, and V1 is a superinterface of DV. Then Name<T1, .. Ts> | ||
/// is a subtype of [T1/X1 .. Ts/Xs]V1 for all T1, .. Ts. | ||
/// | ||
/// @description Check that an extension type `ET` that implements `S` is a | ||
/// subtype of `FutureOr<S>`. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 55578 | ||
/// | ||
/// @description Check that if type T0 is a subtype of a type T1, then instance | ||
/// of T0 can be used as an argument of type T1. Test mixin members | ||
/// @author sgrekhov@unipro.ru | ||
/// | ||
/// This test is generated from test_types/extension_type_A11.dart and | ||
/// test_cases/arguments_binding_x03.dart. Don't modify it! | ||
/// If you need to change this test, then change one of the files above and then | ||
/// run generator/generator.dart to regenerate the tests. | ||
import '../../utils/common.dart'; | ||
|
||
import "dart:async"; | ||
|
||
extension type ET(Future<int> _) implements Future<int> {} | ||
|
||
FutureOr<int> t1Instance = Future<int>(() => 1); | ||
ET t0Instance = ET(Future<int>(() => 2)); | ||
|
||
const t1Default = 42; | ||
|
||
mixin class ArgumentsBindingMixin1_t03 { | ||
FutureOr<int> m = t1Default; | ||
|
||
void superTest(FutureOr<int> val) {} | ||
void superTestPositioned(FutureOr<int> val, [FutureOr<int> val2 = t1Default]) {} | ||
void superTestNamed(FutureOr<int> val, {FutureOr<int> val2 = t1Default}) {} | ||
FutureOr<int> get superGetter => m; | ||
void set superSetter(FutureOr<int> val) {} | ||
} | ||
|
||
class ArgumentsBinding1_t03 extends Object with ArgumentsBindingMixin1_t03 { | ||
|
||
test(dynamic t1, dynamic t2) { | ||
superTest(t1); | ||
superTestPositioned(t1); | ||
superTestPositioned(t2, t1); | ||
superTestNamed(t1); | ||
superTestNamed(t2, val2: t1); | ||
superSetter = t1; | ||
m = t1; | ||
superGetter; | ||
} | ||
} | ||
|
||
mixin class ArgumentsBindingMixin2_t03<X> { | ||
void superTest(X val) {} | ||
void superTestNamed(X val, {required X val2}) {} | ||
void set superSetter(X val) {} | ||
} | ||
|
||
class ArgumentsBinding2_t03<X> extends Object with ArgumentsBindingMixin2_t03<X> { | ||
|
||
test(dynamic t1, dynamic t2) { | ||
superTest(t1); | ||
superTestNamed(t2, val2: t1); | ||
superSetter = t1; | ||
} | ||
} | ||
|
||
main() { | ||
ArgumentsBinding1_t03 c1 = new ArgumentsBinding1_t03(); | ||
|
||
c1.test(forgetType(t0Instance), t1Instance); | ||
c1.superTest(forgetType(t0Instance)); | ||
c1.superTestPositioned(forgetType(t0Instance)); | ||
c1.superTestPositioned(t1Instance, forgetType(t0Instance)); | ||
c1.superTestNamed(forgetType(t0Instance)); | ||
c1.superTestNamed(t1Instance, val2: forgetType(t0Instance)); | ||
c1.superSetter = forgetType(t0Instance); | ||
c1.superGetter; | ||
|
||
// Test type parameters | ||
ArgumentsBinding2_t03<FutureOr<int>> c2 = new ArgumentsBinding2_t03<FutureOr<int>>(); | ||
c2.test(forgetType(t0Instance), t1Instance); | ||
c2.superTest(forgetType(t0Instance)); | ||
c2.superTestNamed(t1Instance, val2: forgetType(t0Instance)); | ||
c2.superSetter = forgetType(t0Instance); | ||
} |
Oops, something went wrong.