Remove warning for "is" checks with generic type parameters.

The analyzer used to emit a warning when a type parameter to a generic
method was used in an "is" check.  This warning was there to help
users write code that worked correctly on both Dart 1.0 and 2.0.  Now
that 2.0 generic methods are being more broadly supported and used,
this warning is blocking further library work, and is being removed.

Fixes https://github.com/dart-lang/sdk/issues/30530

Bug:
Change-Id: I70395305ad082aee3072b5beeb0b1b7f7883391b
Reviewed-on: https://dart-review.googlesource.com/29821
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Leaf Petersen 2017-12-15 18:12:03 +00:00
parent 2822fbadea
commit 53908b0790
14 changed files with 13 additions and 129 deletions

View file

@ -111,6 +111,16 @@
### Tool Changes
* Analyzer
The analyzer will no longer issue a warning when a generic type parameter is
used as the type in an instance check. For example:
```dart
test<T>() {
print(3 is T); // No warning
}
```
* Pub
* Git dependencies may now include a `path` parameter, indicating that the

View file

@ -610,7 +610,6 @@ const List<ErrorCode> errorCodeValues = const [
StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER,
StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE,
StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS,
StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER,
StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC,
StaticWarningCode.TYPE_TEST_WITH_NON_TYPE,
StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME,

View file

@ -4533,19 +4533,6 @@ class StaticWarningCode extends ErrorCode {
"Try using a different type, or "
"changing the import to not be deferred.");
/**
* Not yet spec'd.
*
* Parameters:
* 0: the name of the generic function's type parameter that is being used in
* an `is` expression
*/
static const StaticWarningCode TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER =
const StaticWarningCode(
'TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER',
"The type parameter '{0}' can't be used in a type test.",
"Try using a different type.");
/**
* 12.31 Type Test: It is a static warning if <i>T</i> does not denote a type
* available in the current lexical scope.

View file

@ -919,7 +919,6 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
@override
Object visitIsExpression(IsExpression node) {
_checkForTypeAnnotationDeferredClass(node.type);
_checkForTypeAnnotationGenericFunctionParameter(node.type);
return super.visitIsExpression(node);
}
@ -5766,28 +5765,6 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
}
/**
* Verify that the given type [name] is not a type parameter in a generic
* method.
*
* See [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER].
*/
void _checkForTypeAnnotationGenericFunctionParameter(TypeAnnotation type) {
if (type is TypeName) {
Identifier name = type.name;
if (name is SimpleIdentifier) {
Element element = name.staticElement;
if (element is TypeParameterElement &&
element.enclosingElement is ExecutableElement) {
_errorReporter.reportErrorForNode(
StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER,
name,
[name.name]);
}
}
}
}
/**
* Verify that the type arguments in the given [typeName] are all within
* their bounds.

View file

@ -1737,27 +1737,6 @@ class StaticWarningCodeTest_Kernel extends StaticWarningCodeTest_Driver {
return super.test_typeAnnotationDeferredClass_variableDeclarationList();
}
@override
@failingTest
@potentialAnalyzerProblem
test_typeAnnotationGenericFunctionParameter_localFunction() async {
return super.test_typeAnnotationGenericFunctionParameter_localFunction();
}
@override
@failingTest
@potentialAnalyzerProblem
test_typeAnnotationGenericFunctionParameter_method() async {
return super.test_typeAnnotationGenericFunctionParameter_method();
}
@override
@failingTest
@potentialAnalyzerProblem
test_typeAnnotationGenericFunctionParameter_topLevelFunction() async {
return super.test_typeAnnotationGenericFunctionParameter_topLevelFunction();
}
@override
@failingTest
@potentialAnalyzerProblem

View file

@ -3389,45 +3389,6 @@ a.A v;'''
]);
}
test_typeAnnotationGenericFunctionParameter_localFunction() async {
Source source = addSource(r'''
class A {
void method() {
T local<T>(Object t) {
return (t is T) ? t : null;
}
}
}''');
await computeAnalysisResult(source);
assertErrors(
source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]);
verify([source]);
}
test_typeAnnotationGenericFunctionParameter_method() async {
Source source = addSource(r'''
class A {
T method<T>(Object t) {
return (t is T) ? t : null;
}
}''');
await computeAnalysisResult(source);
assertErrors(
source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]);
verify([source]);
}
test_typeAnnotationGenericFunctionParameter_topLevelFunction() async {
Source source = addSource(r'''
T function<T>(Object t) {
return (t is T) ? t : null;
}''');
await computeAnalysisResult(source);
assertErrors(
source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]);
verify([source]);
}
test_typeParameterReferencedByStatic_field() async {
Source source = addSource(r'''
class A<K> {

View file

@ -2796,12 +2796,9 @@ main() {
await resolveTestUnit(code);
}
@failingTest
test_futureOr_promotion3() async {
// Test that promotion from FutureOr<T> to T works for type
// parameters T
// TODO(leafp): When the restriction on is checks for generic methods
// goes away this should pass.
String code = r'''
import "dart:async";
dynamic test<T extends num>(FutureOr<T> x) => (x is T) &&

View file

@ -105,6 +105,7 @@ generic_closure_test: StaticWarning
generic_list_checked_test: StaticWarning
generic_local_functions_test: CompileTimeError # Issue 28515
generic_methods_generic_function_parameter_test: CompileTimeError # Issue 28515
generic_methods_type_expression_test: Skip # This tests now unsupported Dart 1.0 behavior (is check warnings)
generic_test: StaticWarning
generics_test: StaticWarning
get_set_syntax_test/none: Fail # Issue 11575

View file

@ -54,10 +54,9 @@ main() {
Expect.equals(f8<int>(), new TypeValue<List<int>>().value);
Expect.isTrue(f9<int>(<int, String>{}));
Expect
.isTrue(f9<int>(<bool, String>{})); // `is Map<dynamic, String>` is true.
Expect.isFalse(f9<int>(<bool, String>{}));
Expect.isFalse(f9<int>(<int, int>{}));
Expect.isTrue(new IsMap<int>().check<String>(<int, String>{}));
Expect.isTrue(new IsMap<int>().check<int>(<int, String>{}));
Expect.isFalse(new IsMap<int>().check<int>(<int, String>{}));
}

View file

@ -325,16 +325,12 @@ function_type_call_getter2_test/04: MissingCompileTimeError
function_type_call_getter2_test/05: MissingCompileTimeError
generic_list_checked_test: CompileTimeError
generic_methods_bounds_test/01: MissingCompileTimeError
generic_methods_closure_test: StaticWarning
generic_methods_dynamic_test/01: MissingCompileTimeError
generic_methods_dynamic_test/03: MissingCompileTimeError
generic_methods_local_variable_declaration_test: StaticWarning
generic_methods_overriding_test/01: MissingCompileTimeError
generic_methods_overriding_test/03: MissingCompileTimeError
generic_methods_overriding_test/06: StaticWarning
generic_methods_recursive_bound_test/02: MissingCompileTimeError
generic_methods_shadowing_test: StaticWarning
generic_methods_simple_is_expression_test: StaticWarning
generic_no_such_method_dispatcher_test: StaticWarning
generic_tearoff_test: CompileTimeError
generic_test: CompileTimeError
@ -741,16 +737,12 @@ function_type_call_getter2_test/03: MissingCompileTimeError
function_type_call_getter2_test/04: MissingCompileTimeError
function_type_call_getter2_test/05: MissingCompileTimeError
generic_methods_bounds_test/01: MissingCompileTimeError
generic_methods_closure_test: StaticWarning
generic_methods_dynamic_test/01: MissingCompileTimeError
generic_methods_dynamic_test/03: MissingCompileTimeError
generic_methods_local_variable_declaration_test: StaticWarning
generic_methods_overriding_test/01: MissingCompileTimeError
generic_methods_overriding_test/03: MissingCompileTimeError
generic_methods_overriding_test/06: StaticWarning
generic_methods_recursive_bound_test/02: MissingCompileTimeError
generic_methods_shadowing_test: StaticWarning
generic_methods_simple_is_expression_test: StaticWarning
generic_no_such_method_dispatcher_test: StaticWarning
generic_tearoff_test: CompileTimeError
getter_no_setter2_test/00: MissingCompileTimeError
@ -1053,14 +1045,9 @@ error_stacktrace_test/00: Pass
field3a_negative_test: StaticWarning # Issue 28823
forwarding_stub_tearoff_test: CompileTimeError
generic_list_checked_test: CompileTimeError
generic_methods_closure_test: CompileTimeError # Issue 29070
generic_methods_generic_function_result_test/none: CompileTimeError # Issue #30207
generic_methods_local_variable_declaration_test: CompileTimeError # Issue 29070
generic_methods_overriding_test/01: MissingCompileTimeError # Issue 29070
generic_methods_overriding_test/03: MissingCompileTimeError # Issue 29070
generic_methods_shadowing_test: CompileTimeError # Issue 29070
generic_methods_simple_is_expression_test: CompileTimeError # Issue 29070
generic_methods_type_expression_test: CompileTimeError # Incorrectly disallows type parameter in "is" test.
generic_no_such_method_dispatcher_test: CompileTimeError
generic_tearoff_test: CompileTimeError
generic_test: CompileTimeError
@ -1333,7 +1320,6 @@ generic_constructor_mixin_test/01: MissingCompileTimeError
generic_field_mixin6_test/01: MissingCompileTimeError
generic_function_typedef2_test/04: MissingCompileTimeError
generic_methods_generic_function_result_test/01: MissingCompileTimeError # Issue #30207
generic_methods_type_expression_test: StaticWarning # Issue 30530
identical_const_test/01: MissingCompileTimeError
identical_const_test/02: MissingCompileTimeError
identical_const_test/03: MissingCompileTimeError

View file

@ -48,13 +48,8 @@ final_syntax_test/04: MissingCompileTimeError
forwarding_stub_tearoff_test: CompileTimeError
fuzzy_arrows_test/01: MissingCompileTimeError
generic_local_functions_test: CompileTimeError
generic_methods_closure_test: CompileTimeError # Issue 29920
generic_methods_generic_function_parameter_test: CompileTimeError
generic_methods_generic_function_result_test/none: CompileTimeError # Issue #30208
generic_methods_local_variable_declaration_test: CompileTimeError # Issue 29920
generic_methods_shadowing_test: CompileTimeError # Issue 29920
generic_methods_simple_is_expression_test: CompileTimeError # Issue 29920
generic_methods_type_expression_test: CompileTimeError
generic_no_such_method_dispatcher_simple_test: Skip # This test is just for kernel.
generic_no_such_method_dispatcher_test: CompileTimeError
generic_test: CompileTimeError
@ -790,7 +785,6 @@ generic_closure_test/01: RuntimeError # ReferenceError: TToT is not defined
generic_closure_test/none: RuntimeError # ReferenceError: TToT is not defined
generic_list_checked_test: RuntimeError # Expect.throws fails: Did not throw
generic_method_types_test/02: RuntimeError
generic_methods_type_expression_test: RuntimeError # Expect.isTrue(false) fails.
generic_methods_unused_parameter_test: RuntimeError # Expect.isTrue(false) fails.
generic_test: RuntimeError # ReferenceError: BOfT is not defined
library_env_test/has_io_support: RuntimeError # Unsupported operation: bool.fromEnvironment can only be used as a const constructor

View file

@ -664,7 +664,6 @@ generic_methods_overriding_test/03: MissingCompileTimeError
generic_methods_recursive_bound_test/02: MissingCompileTimeError
generic_methods_tearoff_specialization_test: CompileTimeError # Issue 31402 (Variable declaration)
generic_methods_tearoff_specialization_test: RuntimeError
generic_methods_type_expression_test: RuntimeError # Issue 25869 / 27460
generic_methods_unused_parameter_test: CompileTimeError # Issue 31402 (Variable declaration)
generic_methods_unused_parameter_test: RuntimeError
generic_no_such_method_dispatcher_simple_test: CompileTimeError # Issue 31533
@ -1916,8 +1915,6 @@ generic_methods_recursive_bound_test/03: Crash, Pass
generic_methods_reuse_type_variables_test: Pass
generic_methods_tearoff_specialization_test: RuntimeError
generic_methods_tearoff_specialization_test: CompileTimeError # Issue 31402 (Variable declaration)
generic_methods_type_expression_test: Crash
generic_methods_type_expression_test: RuntimeError # Issue 25869 / 27460
generic_methods_unused_parameter_test: CompileTimeError # Issue 31402 (Variable declaration)
generic_methods_unused_parameter_test: RuntimeError
generic_no_such_method_dispatcher_simple_test: CompileTimeError # Issue 31533

View file

@ -405,7 +405,6 @@ generic_methods_recursive_bound_test/02: Crash
generic_methods_recursive_bound_test/02: MissingCompileTimeError
generic_methods_recursive_bound_test/03: Crash, Pass
generic_methods_tearoff_specialization_test: RuntimeError
generic_methods_type_expression_test: RuntimeError # Issue 25869 / 27460
generic_methods_unused_parameter_test: RuntimeError
generic_tearoff_test: RuntimeError
getter_no_setter2_test/00: MissingCompileTimeError

View file

@ -43,7 +43,6 @@ example_constructor_test: Fail, OK
export_ambiguous_main_negative_test: Fail # Issue 14763
field_initialization_order_test: Fail, OK
generalized_void_syntax_test: CompileTimeError # Issue #30176
generic_methods_type_expression_test: RuntimeError # Issue 25869 / 27460
hello_dart_test: Skip # Incompatible flag: --compile_all
language_2/least_upper_bound_expansive_test/none: CompileTimeError
library_env_test/has_html_support: RuntimeError, OK
@ -1185,7 +1184,6 @@ export_ambiguous_main_negative_test: Fail # Issue 14763
field_initialization_order_test: Fail, OK
generalized_void_syntax_test: CompileTimeError # Issue #30176
generic_methods_bounds_test/02: MissingRuntimeError
generic_methods_type_expression_test: RuntimeError # Issue 25869 / 27460
library_env_test/has_html_support: RuntimeError, OK
library_env_test/has_no_io_support: RuntimeError, OK
main_not_a_function_test: Skip