-
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.
[analyzer] Report warnings on expressions with non-nullable types
Part of #56836 Change-Id: I3fcdceff667f371fcf4b66c12bd16e2f34e6446c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391621 Reviewed-by: Keerti Parthasarathy <[email protected]> Reviewed-by: Erik Ernst <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
- Loading branch information
1 parent
b7aa0fa
commit 253e715
Showing
14 changed files
with
343 additions
and
76 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
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
53 changes: 53 additions & 0 deletions
53
pkg/analyzer/test/src/diagnostics/invalid_null_aware_elements_error_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,53 @@ | ||
// Copyright (c) 2024, 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/context_collection_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(InvalidNullAwareElementsErrorTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class InvalidNullAwareElementsErrorTest extends PubPackageResolutionTest { | ||
test_invalid_null_aware_element_in_list() async { | ||
await assertErrorsInCode(''' | ||
const stringConst = ""; | ||
const list = [0, ?stringConst]; | ||
''', [ | ||
error(StaticWarningCode.INVALID_NULL_AWARE_ELEMENT, 41, 1), | ||
]); | ||
} | ||
|
||
test_invalid_null_aware_element_in_set() async { | ||
await assertErrorsInCode(''' | ||
const stringConst = ""; | ||
const set = {0, ?stringConst}; | ||
''', [ | ||
error(StaticWarningCode.INVALID_NULL_AWARE_ELEMENT, 40, 1), | ||
]); | ||
} | ||
|
||
test_invalid_null_aware_key_in_map() async { | ||
await assertErrorsInCode(''' | ||
const intConst = 0; | ||
const map = {?0: intConst}; | ||
''', [ | ||
error(StaticWarningCode.INVALID_NULL_AWARE_MAP_ENTRY_KEY, 33, 1), | ||
]); | ||
} | ||
|
||
test_invalid_null_aware_value_in_map() async { | ||
await assertErrorsInCode(''' | ||
const intConst = 0; | ||
const map = {0: ?intConst}; | ||
''', [ | ||
error(StaticWarningCode.INVALID_NULL_AWARE_MAP_ENTRY_VALUE, 36, 1), | ||
]); | ||
} | ||
} |
Oops, something went wrong.