From d3c7e183e9ecdadc714f2cb314d880ffd393282f Mon Sep 17 00:00:00 2001 From: Emmanuel Pellereau Date: Thu, 11 May 2023 14:00:06 +0000 Subject: [PATCH] Revert "Issue 35828. Don't report COULD_NOT_INFER when InvalidType, make it a subtype of everything." This reverts commit 838c926f648f06e4d3140d592f1cdff0d4e07b96. Reason for revert: breaks google3. See b/281948666 Original change's description: > Issue 35828. Don't report COULD_NOT_INFER when InvalidType, make it a subtype of everything. > > Bug: https://github.com/dart-lang/sdk/issues/35828 > Change-Id: Ie7757cb2e0cbc0cfdd1530b75f34ffb3dd3156dd > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302680 > Commit-Queue: Konstantin Shcheglov > Reviewed-by: Samuel Rawlins Bug: https://github.com/dart-lang/sdk/issues/35828 Change-Id: I05ddcf7657069b1e889b5b0019faaf7301f6643b No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302781 Bot-Commit: Rubber Stamper Commit-Queue: Emmanuel Pellereau Reviewed-by: Samuel Rawlins Reviewed-by: Brian Wilkerson --- .../postfix/postfix_completion_test.dart | 16 ++-------------- pkg/analyzer/lib/src/dart/element/subtype.dart | 6 ------ .../lib/src/error/best_practices_verifier.dart | 8 +------- .../test/src/dart/element/string_types.dart | 1 - .../test/src/dart/element/subtype_test.dart | 5 ----- .../dart/resolution/binary_expression_test.dart | 2 +- .../dart/resolution/top_level_variable_test.dart | 4 ++-- .../src/diagnostics/could_not_infer_test.dart | 12 ------------ .../diagnostics/unnecessary_type_check_test.dart | 10 ---------- .../generic/instantiate_type_variable_test.dart | 2 ++ 10 files changed, 8 insertions(+), 58 deletions(-) diff --git a/pkg/analysis_server/test/services/completion/postfix/postfix_completion_test.dart b/pkg/analysis_server/test/services/completion/postfix/postfix_completion_test.dart index ee7f40d7546..1e47e9d8a10 100644 --- a/pkg/analysis_server/test/services/completion/postfix/postfix_completion_test.dart +++ b/pkg/analysis_server/test/services/completion/postfix/postfix_completion_test.dart @@ -374,26 +374,14 @@ f(int expr) { Future test_negateCascade() async { await _prepareCompletion('.not', ''' -void f(bool expr) { +f(bool expr) { if (expr..a..b..c.not) } - -extension on bool { - void a() {} - void b() {} - void c() {} -} '''); _assertHasChange('Expand .not', ''' -void f(bool expr) { +f(bool expr) { if (!expr..a..b..c) } - -extension on bool { - void a() {} - void b() {} - void c() {} -} '''); } diff --git a/pkg/analyzer/lib/src/dart/element/subtype.dart b/pkg/analyzer/lib/src/dart/element/subtype.dart index 1138b13e730..f4e0e7c08d9 100644 --- a/pkg/analyzer/lib/src/dart/element/subtype.dart +++ b/pkg/analyzer/lib/src/dart/element/subtype.dart @@ -45,12 +45,6 @@ class SubtypeHelper { return true; } - // `InvalidType` is treated as a top and a bottom type. - if (identical(T0_, InvalidTypeImpl.instance) || - identical(T1_, InvalidTypeImpl.instance)) { - return true; - } - var T0 = T0_ as TypeImpl; var T1 = T1_ as TypeImpl; diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart index a19ce81c509..5dc360db91b 100644 --- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart +++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart @@ -739,8 +739,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor { /// [WarningCode.UNNECESSARY_TYPE_CHECK_FALSE]. bool _checkAllTypeChecks(IsExpression node) { var leftNode = node.expression; - var leftType = leftNode.typeOrThrow; - var rightNode = node.type; var rightType = rightNode.type as TypeImpl; @@ -753,11 +751,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor { ); } - // `cannotResolve is X` or `cannotResolve is! X` - if (leftType is InvalidType) { - return false; - } - // `is dynamic` or `is! dynamic` if (rightType is DynamicType) { report(); @@ -785,6 +778,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { } if (_isNonNullableByDefault) { + var leftType = leftNode.typeOrThrow; if (_typeSystem.isSubtypeOf(leftType, rightType)) { report(); return true; diff --git a/pkg/analyzer/test/src/dart/element/string_types.dart b/pkg/analyzer/test/src/dart/element/string_types.dart index 3f9f516d739..3e208503f61 100644 --- a/pkg/analyzer/test/src/dart/element/string_types.dart +++ b/pkg/analyzer/test/src/dart/element/string_types.dart @@ -22,7 +22,6 @@ mixin StringTypes on AbstractTypeSystemTest { void defineStringTypes() { _defineType('dynamic', dynamicType); - _defineType('InvalidType', invalidType); _defineType('void', voidNone); _defineType('Never', neverNone); diff --git a/pkg/analyzer/test/src/dart/element/subtype_test.dart b/pkg/analyzer/test/src/dart/element/subtype_test.dart index ecf33afc51c..35ef55dca75 100644 --- a/pkg/analyzer/test/src/dart/element/subtype_test.dart +++ b/pkg/analyzer/test/src/dart/element/subtype_test.dart @@ -2677,11 +2677,6 @@ class SubtypeTest extends _SubtypingTestBase with StringTypes { isNotSubtype(A_num, A_int, strT0: "A", strT1: "A"); } - test_invalidType() { - isSubtype2('InvalidType', 'int'); - isSubtype2('int', 'InvalidType'); - } - test_multi_function_nonGeneric_oneArgument() { isSubtype2('num* Function(num*)*', 'num* Function(int*)*'); isSubtype2('int* Function(num*)*', 'num* Function(num*)*'); diff --git a/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart index bd8a2db708d..060f8fa01cb 100644 --- a/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart @@ -527,7 +527,7 @@ BinaryExpression staticType: InvalidType staticElement: dart:core::@class::num::@method::* staticInvokeType: num Function(num) - staticType: double + staticType: num '''); } diff --git a/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart b/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart index ce86151b5ef..36119f6edab 100644 --- a/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart @@ -72,11 +72,11 @@ VariableDeclaration staticElement: staticType: InvalidType declaredElement: @99 - type: InvalidType Function(Object?) + type: int Function(Object?) parameter: ParameterMember base: root::@parameter::b substitution: {T: String} - staticType: InvalidType Function(Object?) + staticType: int Function(Object?) rightParenthesis: ) staticInvokeType: String? Function(String Function(), int Function(String)) staticType: String? diff --git a/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart b/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart index 092648f6063..36597defe6c 100644 --- a/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/could_not_infer_test.dart @@ -37,18 +37,6 @@ void f(dynamic a) { '''); } - test_function_argument_invalidType() async { - await assertErrorsInCode(r''' -void foo(T t) {} - -void f(X x) { - foo(x); -} -''', [ - error(CompileTimeErrorCode.UNDEFINED_CLASS, 40, 1), - ]); - } - test_functionType() async { await assertNoErrorsInCode(''' void f() {} diff --git a/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart b/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart index 544af871987..5756efd1a3c 100644 --- a/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart +++ b/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart @@ -152,16 +152,6 @@ class UnnecessaryTypeCheckFalseWithoutNullSafetyTest @reflectiveTest class UnnecessaryTypeCheckTrueTest extends PubPackageResolutionTest with UnnecessaryTypeCheckTrueTestCases { - test_expressionInvalidType() async { - await assertErrorsInCode(r''' -void f(A a) { - a is num; -} -''', [ - error(CompileTimeErrorCode.UNDEFINED_CLASS, 7, 1), - ]); - } - test_typeNonNullable_is_same() async { await assertErrorsInCode(r''' void f(int a) { diff --git a/tests/language_2/generic/instantiate_type_variable_test.dart b/tests/language_2/generic/instantiate_type_variable_test.dart index 1b9bee1fdb0..2c73da8badf 100644 --- a/tests/language_2/generic/instantiate_type_variable_test.dart +++ b/tests/language_2/generic/instantiate_type_variable_test.dart @@ -10,6 +10,8 @@ class Foo { Foo() {} T make() { return new T(); + // ^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.INVALID_CAST_NEW_EXPR // ^ // [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE // [cfe] Couldn't find constructor 'T'.