From b955d6a628eacb56ad5b8f63dbab03708ddaf244 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Wed, 14 Feb 2024 22:29:33 +0000 Subject: [PATCH] [ddc] Delete variance tests for old DDC types - These tests rely on the internals of the old type system. - Copy some expectations to the language suite when it looks like there isn't already coverage for the same test. Change-Id: I63bfa2bc94fb29b4e4f90c3c02cf0943d19764b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352463 Commit-Queue: Nicholas Shahan Reviewed-by: Kallen Tu --- tests/dartdevc/variance_subtype_test.dart | 190 ------------------ tests/dartdevc/variance_test.dart | 51 ----- .../variance/variance_in_subtyping_test.dart | 14 ++ .../variance_inout_subtyping_test.dart | 20 ++ .../variance/variance_out_subtyping_test.dart | 14 ++ 5 files changed, 48 insertions(+), 241 deletions(-) delete mode 100644 tests/dartdevc/variance_subtype_test.dart delete mode 100644 tests/dartdevc/variance_test.dart diff --git a/tests/dartdevc/variance_subtype_test.dart b/tests/dartdevc/variance_subtype_test.dart deleted file mode 100644 index f4a12a6368c..00000000000 --- a/tests/dartdevc/variance_subtype_test.dart +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (c) 2019, 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. - -// SharedOptions=--enable-experiment=variance - -// Tests runtime subtyping with explicit variance modifiers. - -import 'dart:_foreign_helper' show TYPE_REF; -import 'dart:async' show FutureOr; - -import 'runtime_utils.dart'; - -class Upper {} - -class Middle extends Upper {} - -class Lower extends Middle {} - -class Covariant {} - -class Contravariant {} - -class Invariant {} - -class LegacyCovariant {} - -void main() { - // Covariant <: Covariant - checkProperSubtype( - TYPE_REF>(), TYPE_REF>()); - - // Covariant <: Covariant - checkSubtype(TYPE_REF>(), TYPE_REF>()); - - // Contravariant <: Contravariant - checkProperSubtype( - TYPE_REF>(), TYPE_REF>()); - - // Contravariant <: Contravariant - checkSubtype( - TYPE_REF>(), TYPE_REF>()); - - // Invariant <: Invariant - checkSubtype(TYPE_REF>(), TYPE_REF>()); - - // Invariant <:> Invariant - checkMutualSubtype( - TYPE_REF>(), TYPE_REF>()); - - // Invariant> <:> Invariant - checkMutualSubtype( - TYPE_REF>>(), TYPE_REF>()); - - // Invariant> <:> Invariant?> - checkMutualSubtype(TYPE_REF>>(), - TYPE_REF?>>()); - - // LegacyCovariant <: LegacyCovariant - checkProperSubtype( - TYPE_REF>(), TYPE_REF>()); - - // List> <: Iterable> - checkProperSubtype(TYPE_REF>>(), - TYPE_REF>>()); - - // List> <: Iterable> - checkProperSubtype(TYPE_REF>>(), - TYPE_REF>>()); - - // List> <: Iterable> - checkProperSubtype(TYPE_REF>>(), - TYPE_REF>>()); - - // List> <: Iterable> - checkProperSubtype(TYPE_REF>>(), - TYPE_REF>>()); - - // String -> Covariant <: String -> Covariant - checkProperSubtype(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // Covariant -> String <: Covariant -> String - checkProperSubtype(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> Contravariant <: String -> Contravariant - checkProperSubtype(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // Contravariant -> String <: Contravariant -> String - checkProperSubtype(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> Invariant <: String -> Invariant - checkSubtype(TYPE_REF)>(), - TYPE_REF)>()); - - // Invariant -> String <: Invariant -> String - checkSubtype(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> LegacyCovariant <: String -> LegacyCovariant - checkProperSubtype(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // LegacyCovariant -> String <: LegacyCovariant -> String - checkProperSubtype(TYPE_REF)>(), - TYPE_REF)>()); - - // Covariant - checkSubtypeFailure( - TYPE_REF>(), TYPE_REF>()); - - // Contravariant - checkSubtypeFailure( - TYPE_REF>(), TYPE_REF>()); - - // Invariant - checkSubtypeFailure( - TYPE_REF>(), TYPE_REF>()); - - // Invariant - checkSubtypeFailure( - TYPE_REF>(), TYPE_REF>()); - - // LegacyCovariant - checkSubtypeFailure( - TYPE_REF>(), TYPE_REF>()); - - // List> > - checkSubtypeFailure(TYPE_REF>>(), - TYPE_REF>>()); - - // List> > - checkSubtypeFailure(TYPE_REF>>(), - TYPE_REF>>()); - - // List> > - checkSubtypeFailure(TYPE_REF>>(), - TYPE_REF>>()); - - // List> > - checkSubtypeFailure(TYPE_REF>>(), - TYPE_REF>>()); - - // List> > - checkSubtypeFailure(TYPE_REF>>(), - TYPE_REF>>()); - - // String -> Covariant Covariant - checkSubtypeFailure(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // Covariant -> String -> String - checkSubtypeFailure(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> Contravariant Contravariant - checkSubtypeFailure(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // Contravariant -> String -> String - checkSubtypeFailure(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> Invariant Invariant - checkSubtypeFailure(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // Invariant -> String -> String - checkSubtypeFailure(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> Invariant Invariant - checkSubtypeFailure(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // Invariant -> String <: Invariant -> String - checkSubtypeFailure(TYPE_REF)>(), - TYPE_REF)>()); - - // String -> LegacyCovariant LegacyCovariant - checkSubtypeFailure(TYPE_REF Function(String)>(), - TYPE_REF Function(String)>()); - - // LegacyCovariant -> String -> String - checkSubtypeFailure(TYPE_REF)>(), - TYPE_REF)>()); -} diff --git a/tests/dartdevc/variance_test.dart b/tests/dartdevc/variance_test.dart deleted file mode 100644 index dcc70885ef5..00000000000 --- a/tests/dartdevc/variance_test.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2019, 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. - -// SharedOptions=--enable-experiment=variance - -// Tests the emission of explicit variance modifiers. - -import 'dart:_foreign_helper' show TYPE_REF; -import 'dart:_runtime' show getGenericArgVariances, Variance; - -import 'package:expect/expect.dart'; - -class A {} - -class B {} - -class C {} - -class D {} - -class E {} - -mixin F {} - -class G = Object with F; - -List? getVariances(Object type) { - // TODO(nshahan) Revisit when we decide if getGenericArgVariances will handle - // legacy and nullable wrappers. - return getGenericArgVariances(type); -} - -main() { - Expect.listEquals([Variance.contravariant], getVariances(TYPE_REF())!); - - Expect.listEquals([Variance.covariant], getVariances(TYPE_REF())!); - - Expect.listEquals([Variance.invariant], getVariances(TYPE_REF())!); - - // Implicit variance is not emitted into the generated code. - Expect.isNull(getVariances(TYPE_REF())); - - Expect.listEquals( - [Variance.invariant, Variance.covariant, Variance.contravariant], - getVariances(TYPE_REF())!); - - Expect.listEquals([Variance.contravariant], getVariances(TYPE_REF())!); - - Expect.listEquals([Variance.invariant], getVariances(TYPE_REF())!); -} diff --git a/tests/language/variance/variance_in_subtyping_test.dart b/tests/language/variance/variance_in_subtyping_test.dart index df89b2ba2b4..842d6cb587b 100644 --- a/tests/language/variance/variance_in_subtyping_test.dart +++ b/tests/language/variance/variance_in_subtyping_test.dart @@ -95,8 +95,22 @@ main() { iterableLower = listMiddle; testCall(listMiddle); + Expect.subtype>, Iterable>>(); + Expect.notSubtype>, + List>>(); + Expect.notSubtype>, + Iterable>>(); Expect.subtype, Contravariant>(); Expect.subtype, Contravariant>(); Expect.notSubtype, Contravariant>(); + + Expect.subtype Function(String), + Contravariant Function(String)>(); + Expect.notSubtype Function(String), + Contravariant Function(String)>(); + Expect.subtype), + String Function(Contravariant)>(); + Expect.notSubtype), + String Function(Contravariant)>(); } diff --git a/tests/language/variance/variance_inout_subtyping_test.dart b/tests/language/variance/variance_inout_subtyping_test.dart index e4252f49a1a..1c4758ae788 100644 --- a/tests/language/variance/variance_inout_subtyping_test.dart +++ b/tests/language/variance/variance_inout_subtyping_test.dart @@ -154,6 +154,10 @@ main() { iterableMiddle = listMiddle; testCall(listMiddle); + Expect.subtype>, Iterable>>(); + Expect.notSubtype>, List>>(); + Expect.notSubtype>, Iterable>>(); + Expect.notSubtype>, Iterable>>(); Expect.subtype, Invariant>(); Expect.notSubtype, Invariant>(); @@ -167,4 +171,20 @@ main() { Expect.subtype>, Invariant>>(); Expect.subtype>, Invariant>>(); + + Expect.subtype>, Invariant?>>(); + Expect.subtype?>, Invariant>>(); + + Expect.subtype), + String Function(Invariant)>(); + Expect.subtype Function(String), + Invariant Function(String)>(); + Expect.notSubtype Function(String), + Invariant Function(String)>(); + Expect.notSubtype), + String Function(Invariant)>(); + Expect.notSubtype Function(String), + Invariant Function(String)>(); + Expect.notSubtype), + String Function(Invariant)>(); } diff --git a/tests/language/variance/variance_out_subtyping_test.dart b/tests/language/variance/variance_out_subtyping_test.dart index 00f5ed3cf92..edad25e7acc 100644 --- a/tests/language/variance/variance_out_subtyping_test.dart +++ b/tests/language/variance/variance_out_subtyping_test.dart @@ -95,8 +95,22 @@ main() { iterableMiddle = listLower; testCall(listLower); + Expect.subtype>, Iterable>>(); + Expect.notSubtype>, List>>(); + Expect.notSubtype>, Iterable>>(); Expect.subtype, Covariant>(); Expect.subtype, Covariant>(); Expect.notSubtype, Covariant>(); + + Expect.subtype Function(String), + Covariant Function(String)>(); + Expect.notSubtype Function(String), + Covariant Function(String)>(); + Expect.subtype), + String Function(Covariant)>(); + Expect.notSubtype), + String Function(Covariant)>(); + Expect.notSubtype Function(String), + Covariant Function(String)>(); }