Skip to content

Commit fff71ee

Browse files
leafpetersencommit-bot@chromium.org
authored andcommitted
Make USES_DYNAMIC_AS_BOTTOM (fuzzy arrows) a warning
Fixes #31874 . Change-Id: I75b43f52692f5860d8c4e78acb15b9c9281754a5 Reviewed-on: https://dart-review.googlesource.com/34506 Commit-Queue: Leaf Petersen <[email protected]> Reviewed-by: Jenny Messerly <[email protected]>
1 parent 72355d5 commit fff71ee

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

pkg/analyzer/lib/error/error.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ const List<ErrorCode> errorCodeValues = const [
299299
HintCode.UNUSED_IMPORT,
300300
HintCode.UNUSED_LOCAL_VARIABLE,
301301
HintCode.UNUSED_SHOWN_NAME,
302-
HintCode.USES_DYNAMIC_AS_BOTTOM,
303302
HintCode.USE_OF_VOID_RESULT,
304303
HintCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD,
305304
HtmlErrorCode.PARSE_ERROR,
@@ -669,6 +668,7 @@ const List<ErrorCode> errorCodeValues = const [
669668
StrongModeCode.TOP_LEVEL_INSTANCE_GETTER,
670669
StrongModeCode.TOP_LEVEL_TYPE_ARGUMENTS,
671670
StrongModeCode.TOP_LEVEL_UNSUPPORTED,
671+
StrongModeCode.USES_DYNAMIC_AS_BOTTOM,
672672
TodoCode.TODO,
673673
];
674674

pkg/analyzer/lib/src/dart/error/hint_codes.dart

-12
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ class HintCode extends ErrorCode {
3737
'ARGUMENT_TYPE_NOT_ASSIGNABLE',
3838
"The argument type '{0}' can't be assigned to the parameter type '{1}'.");
3939

40-
/**
41-
* This hint is generated when a function type is assigned to a function
42-
* typed location, and the assignment will be invalid after fuzzy arrows
43-
* (the treatment of dynamic as bottom in certain locations) is removed.
44-
*
45-
*/
46-
static const HintCode USES_DYNAMIC_AS_BOTTOM = const HintCode(
47-
'USES_DYNAMIC_AS_BOTTOM',
48-
"A function of type '{0}' can't be assigned to a variable of type '{1}'.",
49-
"Try changing the type of the function, or "
50-
"casting the right-hand type to '{1}'.");
51-
5240
/**
5341
* When the target expression uses '?.' operator, it can be `null`, so all the
5442
* subsequent invocations should also use '?.' operator.

pkg/analyzer/lib/src/error/codes.dart

+13
Original file line numberDiff line numberDiff line change
@@ -5069,6 +5069,19 @@ class StrongModeCode extends ErrorCode {
50695069
"The type of '{0}' can't be inferred because {1} expressions aren't supported.",
50705070
"Try adding an explicit type for '{0}'.");
50715071

5072+
/**
5073+
* This warning is generated when a function type is assigned to a function
5074+
* typed location, and the assignment will be invalid after fuzzy arrows
5075+
* (the treatment of dynamic as bottom in certain locations) is removed.
5076+
*
5077+
*/
5078+
static const StrongModeCode USES_DYNAMIC_AS_BOTTOM = const StrongModeCode(
5079+
ErrorType.STATIC_TYPE_WARNING,
5080+
'USES_DYNAMIC_AS_BOTTOM',
5081+
"A function of type '{0}' can't be assigned to a location of type '{1}'.",
5082+
"Try changing the parameter types of the function or of the "
5083+
" receiving location.");
5084+
50725085
@override
50735086
final ErrorType type;
50745087

pkg/analyzer/lib/src/task/strong/checker.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ class CodeChecker extends RecursiveAstVisitor {
11231123
var cTo = rules.typeToConcreteType(to);
11241124
// If still true, no warning needed
11251125
if (rules.isSubtypeOf(cFrom, cTo)) return;
1126-
_recordMessage(expr, HintCode.USES_DYNAMIC_AS_BOTTOM, [from, to]);
1126+
_recordMessage(expr, StrongModeCode.USES_DYNAMIC_AS_BOTTOM, [from, to]);
11271127
}
11281128
}
11291129

@@ -1276,9 +1276,7 @@ class CodeChecker extends RecursiveAstVisitor {
12761276
errorCode.name.startsWith('STRONG_MODE_TOP_LEVEL_')) {
12771277
severity = ErrorSeverity.ERROR;
12781278
}
1279-
if (severity != ErrorSeverity.INFO ||
1280-
_options.strongModeHints ||
1281-
errorCode == HintCode.USES_DYNAMIC_AS_BOTTOM) {
1279+
if (severity != ErrorSeverity.INFO || _options.strongModeHints) {
12821280
int begin = node is AnnotatedNode
12831281
? node.firstTokenAfterCommentAndMetadata.offset
12841282
: node.offset;

pkg/analyzer/test/src/task/options_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class ErrorCodeValuesTest {
270270
removeCode(StrongModeCode.TOP_LEVEL_INSTANCE_GETTER);
271271
removeCode(StrongModeCode.TOP_LEVEL_TYPE_ARGUMENTS);
272272
removeCode(StrongModeCode.TOP_LEVEL_UNSUPPORTED);
273+
removeCode(StrongModeCode.USES_DYNAMIC_AS_BOTTOM);
273274
} else if (errorType == TodoCode) {
274275
declaredNames.remove('TODO_REGEX');
275276
}

pkg/analyzer/test/src/task/strong/checker_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ void main() {
489489
f1("hello");
490490
dynamic f2 = foo;
491491
(/*info:DYNAMIC_INVOKE*/f2("hello"));
492-
DynFun f3 = /*info:USES_DYNAMIC_AS_BOTTOM*/foo;
492+
DynFun f3 = /*warning:USES_DYNAMIC_AS_BOTTOM*/foo;
493493
(/*info:DYNAMIC_INVOKE*/f3("hello"));
494494
(/*info:DYNAMIC_INVOKE*/f3(42));
495495
StrFun f4 = foo;
@@ -673,7 +673,7 @@ void main() {
673673
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/col(3);
674674
}
675675
{
676-
A f = /*info:USES_DYNAMIC_AS_BOTTOM*/new B();
676+
A f = /*warning:USES_DYNAMIC_AS_BOTTOM*/new B();
677677
int x;
678678
double y;
679679
x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
@@ -686,7 +686,7 @@ void main() {
686686
/*info:DYNAMIC_INVOKE*/g.col(42.0);
687687
/*info:DYNAMIC_INVOKE*/g.foo(42.0);
688688
/*info:DYNAMIC_INVOKE*/g.x;
689-
A f = /*info:USES_DYNAMIC_AS_BOTTOM*/new B();
689+
A f = /*warning:USES_DYNAMIC_AS_BOTTOM*/new B();
690690
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/col(42.0);
691691
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/foo(42.0);
692692
/*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_GETTER*/x;
@@ -3091,7 +3091,7 @@ void main() {
30913091
TakesA<int> f;
30923092
TakesA<dynamic> g;
30933093
TakesA<String> h;
3094-
g = /*info:USES_DYNAMIC_AS_BOTTOM*/h;
3094+
g = /*warning:USES_DYNAMIC_AS_BOTTOM*/h;
30953095
f = /*info:DOWN_CAST_COMPOSITE*/f ?? g;
30963096
}
30973097
''');

0 commit comments

Comments
 (0)