From fa243e700a07280535e327fb71c5ecf41bcbd41b Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 30 Mar 2021 16:50:11 +0000 Subject: [PATCH] Issue 45492. Report TYPE_ARGUMENT_NOT_MATCHING_BOUNDS for not regular bounded type as a type alias body. Bug: https://github.com/dart-lang/sdk/issues/45492 Change-Id: I303a7066c356e645d549960f66c1d7b8d50f307a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193452 Reviewed-by: Brian Wilkerson Reviewed-by: Samuel Rawlins Commit-Queue: Konstantin Shcheglov --- .../src/error/type_arguments_verifier.dart | 1 + ...ype_argument_not_matching_bounds_test.dart | 64 ++++++++++++++++--- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart index eb3b8eccc78..a14d9f47046 100644 --- a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart +++ b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart @@ -444,6 +444,7 @@ class TypeArgumentsVerifier { if (parent is WithClause) return false; if (parent is ConstructorName) return false; if (parent is ImplementsClause) return false; + if (parent is GenericTypeAlias) return false; return true; } diff --git a/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart b/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart index b8c2b5c5161..9d407aa94c2 100644 --- a/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_argument_not_matching_bounds_test.dart @@ -495,6 +495,60 @@ void g() { ]); } + test_nonFunctionTypeAlias_body_typeArgument_mismatch() async { + await assertErrorsInCode(r''' +class A {} +class B {} +class G {} +typedef X = G; +''', [ + error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1), + ]); + } + + test_nonFunctionTypeAlias_body_typeArgument_regularBounded() async { + await assertNoErrorsInCode(r''' +class A {} +class B extends A {} +class G {} +typedef X = G; +'''); + } + + test_nonFunctionTypeAlias_body_typeArgument_superBounded() async { + await assertNoErrorsInCode(r''' +class A> {} +typedef X = List; +'''); + } + + test_nonFunctionTypeAlias_interfaceType_body_mismatch() async { + await assertErrorsInCode(r''' +class A {} +class B {} +class G {} +typedef X = G; +''', [ + error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 60, 1), + ]); + } + + test_nonFunctionTypeAlias_interfaceType_body_regularBounded() async { + await assertNoErrorsInCode(r''' +class A {} +typedef X = A; +'''); + } + + test_nonFunctionTypeAlias_interfaceType_body_superBounded() async { + await assertErrorsInCode(r''' +class A> {} +typedef X = A; +''', [ + error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 42, 1), + ]); + } + test_nonFunctionTypeAlias_interfaceType_parameter() async { await assertErrorsInCode(r''' class A {} @@ -514,15 +568,7 @@ void f(X a) {} '''); } - test_nonFunctionTypeAlias_interfaceType_parameter_superBounded() async { - await assertNoErrorsInCode(r''' -class A {} -typedef X = Map; -void f(X a) {} -'''); - } - - test_notRegularBounded_notSuperBounded_invariant() async { + test_notRegularBounded_notSuperBounded_parameter_invariant() async { await assertErrorsInCode(r''' typedef A = X Function(X); typedef G> = void Function();