-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue an error if a prefix in a type name is shadowed by a local vari…
…able. See #42620. Change-Id: Ifd18c939082935390df0c2aa0bd724cf6f76c27c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153705 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
- Loading branch information
1 parent
fe9596b
commit 9f8aaf6
Showing
10 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
pkg/analyzer/test/src/diagnostics/prefix_shadowed_by_local_declaration_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(PrefixShadowedByLocalDeclarationTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class PrefixShadowedByLocalDeclarationTest extends DriverResolutionTest { | ||
test_function_return_type_not_shadowed_by_parameter() async { | ||
await assertNoErrorsInCode(''' | ||
import 'dart:async' as a; | ||
a.Future f(int a) { | ||
return null; | ||
} | ||
'''); | ||
} | ||
|
||
test_local_variable_type_inside_function_with_shadowing_parameter() async { | ||
await assertErrorsInCode(''' | ||
import 'dart:async' as a; | ||
f(int a) { | ||
a.Future x = null; | ||
return x; | ||
} | ||
''', [ | ||
error(HintCode.UNUSED_IMPORT, 7, 12), | ||
error(CompileTimeErrorCode.PREFIX_SHADOWED_BY_LOCAL_DECLARATION, 39, 1), | ||
]); | ||
} | ||
|
||
test_local_variable_type_inside_function_with_shadowing_variable_after() async { | ||
await assertErrorsInCode(''' | ||
import 'dart:async' as a; | ||
f() { | ||
a.Future x = null; | ||
int a = 0; | ||
return [x, a]; | ||
} | ||
''', [ | ||
error(HintCode.UNUSED_IMPORT, 7, 12), | ||
error(CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION, 34, 1, | ||
contextMessages: [message('/test/lib/test.dart', 59, 1)]), | ||
error(CompileTimeErrorCode.PREFIX_SHADOWED_BY_LOCAL_DECLARATION, 34, 1), | ||
]); | ||
} | ||
|
||
test_local_variable_type_inside_function_with_shadowing_variable_before() async { | ||
await assertErrorsInCode(''' | ||
import 'dart:async' as a; | ||
f() { | ||
int a = 0; | ||
a.Future x = null; | ||
return [x, a]; | ||
} | ||
''', [ | ||
error(HintCode.UNUSED_IMPORT, 7, 12), | ||
error(CompileTimeErrorCode.PREFIX_SHADOWED_BY_LOCAL_DECLARATION, 47, 1), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters