Make USES_DYNAMIC_AS_BOTTOM (fuzzy arrows) a warning

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

Change-Id: I75b43f52692f5860d8c4e78acb15b9c9281754a5
Reviewed-on: https://dart-review.googlesource.com/34506
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Jenny Messerly <jmesserly@google.com>
This commit is contained in:
Leaf Petersen 2018-01-17 17:15:18 +00:00 committed by commit-bot@chromium.org
parent 72355d515b
commit fff71ee60f
6 changed files with 21 additions and 21 deletions

View file

@ -299,7 +299,6 @@ const List<ErrorCode> errorCodeValues = const [
HintCode.UNUSED_IMPORT,
HintCode.UNUSED_LOCAL_VARIABLE,
HintCode.UNUSED_SHOWN_NAME,
HintCode.USES_DYNAMIC_AS_BOTTOM,
HintCode.USE_OF_VOID_RESULT,
HintCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD,
HtmlErrorCode.PARSE_ERROR,
@ -669,6 +668,7 @@ const List<ErrorCode> errorCodeValues = const [
StrongModeCode.TOP_LEVEL_INSTANCE_GETTER,
StrongModeCode.TOP_LEVEL_TYPE_ARGUMENTS,
StrongModeCode.TOP_LEVEL_UNSUPPORTED,
StrongModeCode.USES_DYNAMIC_AS_BOTTOM,
TodoCode.TODO,
];

View file

@ -37,18 +37,6 @@ class HintCode extends ErrorCode {
'ARGUMENT_TYPE_NOT_ASSIGNABLE',
"The argument type '{0}' can't be assigned to the parameter type '{1}'.");
/**
* This hint is generated when a function type is assigned to a function
* typed location, and the assignment will be invalid after fuzzy arrows
* (the treatment of dynamic as bottom in certain locations) is removed.
*
*/
static const HintCode USES_DYNAMIC_AS_BOTTOM = const HintCode(
'USES_DYNAMIC_AS_BOTTOM',
"A function of type '{0}' can't be assigned to a variable of type '{1}'.",
"Try changing the type of the function, or "
"casting the right-hand type to '{1}'.");
/**
* When the target expression uses '?.' operator, it can be `null`, so all the
* subsequent invocations should also use '?.' operator.

View file

@ -5069,6 +5069,19 @@ class StrongModeCode extends ErrorCode {
"The type of '{0}' can't be inferred because {1} expressions aren't supported.",
"Try adding an explicit type for '{0}'.");
/**
* This warning is generated when a function type is assigned to a function
* typed location, and the assignment will be invalid after fuzzy arrows
* (the treatment of dynamic as bottom in certain locations) is removed.
*
*/
static const StrongModeCode USES_DYNAMIC_AS_BOTTOM = const StrongModeCode(
ErrorType.STATIC_TYPE_WARNING,
'USES_DYNAMIC_AS_BOTTOM',
"A function of type '{0}' can't be assigned to a location of type '{1}'.",
"Try changing the parameter types of the function or of the "
" receiving location.");
@override
final ErrorType type;

View file

@ -1123,7 +1123,7 @@ class CodeChecker extends RecursiveAstVisitor {
var cTo = rules.typeToConcreteType(to);
// If still true, no warning needed
if (rules.isSubtypeOf(cFrom, cTo)) return;
_recordMessage(expr, HintCode.USES_DYNAMIC_AS_BOTTOM, [from, to]);
_recordMessage(expr, StrongModeCode.USES_DYNAMIC_AS_BOTTOM, [from, to]);
}
}
@ -1276,9 +1276,7 @@ class CodeChecker extends RecursiveAstVisitor {
errorCode.name.startsWith('STRONG_MODE_TOP_LEVEL_')) {
severity = ErrorSeverity.ERROR;
}
if (severity != ErrorSeverity.INFO ||
_options.strongModeHints ||
errorCode == HintCode.USES_DYNAMIC_AS_BOTTOM) {
if (severity != ErrorSeverity.INFO || _options.strongModeHints) {
int begin = node is AnnotatedNode
? node.firstTokenAfterCommentAndMetadata.offset
: node.offset;

View file

@ -270,6 +270,7 @@ class ErrorCodeValuesTest {
removeCode(StrongModeCode.TOP_LEVEL_INSTANCE_GETTER);
removeCode(StrongModeCode.TOP_LEVEL_TYPE_ARGUMENTS);
removeCode(StrongModeCode.TOP_LEVEL_UNSUPPORTED);
removeCode(StrongModeCode.USES_DYNAMIC_AS_BOTTOM);
} else if (errorType == TodoCode) {
declaredNames.remove('TODO_REGEX');
}

View file

@ -489,7 +489,7 @@ void main() {
f1("hello");
dynamic f2 = foo;
(/*info:DYNAMIC_INVOKE*/f2("hello"));
DynFun f3 = /*info:USES_DYNAMIC_AS_BOTTOM*/foo;
DynFun f3 = /*warning:USES_DYNAMIC_AS_BOTTOM*/foo;
(/*info:DYNAMIC_INVOKE*/f3("hello"));
(/*info:DYNAMIC_INVOKE*/f3(42));
StrFun f4 = foo;
@ -673,7 +673,7 @@ void main() {
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/col(3);
}
{
A f = /*info:USES_DYNAMIC_AS_BOTTOM*/new B();
A f = /*warning:USES_DYNAMIC_AS_BOTTOM*/new B();
int x;
double y;
x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
@ -686,7 +686,7 @@ void main() {
/*info:DYNAMIC_INVOKE*/g.col(42.0);
/*info:DYNAMIC_INVOKE*/g.foo(42.0);
/*info:DYNAMIC_INVOKE*/g.x;
A f = /*info:USES_DYNAMIC_AS_BOTTOM*/new B();
A f = /*warning:USES_DYNAMIC_AS_BOTTOM*/new B();
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/col(42.0);
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/foo(42.0);
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_GETTER*/x;
@ -3091,7 +3091,7 @@ void main() {
TakesA<int> f;
TakesA<dynamic> g;
TakesA<String> h;
g = /*info:USES_DYNAMIC_AS_BOTTOM*/h;
g = /*warning:USES_DYNAMIC_AS_BOTTOM*/h;
f = /*info:DOWN_CAST_COMPOSITE*/f ?? g;
}
''');