Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/error/literal_element_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ class LiteralElementVerifier {
/// Verify that the type of the elements of the given [expression] can be
/// assigned to the [elementType] of the enclosing collection.
void _verifySpreadForListOrSet(bool isNullAware, Expression expression) {
if (_errorVerifier.checkForUseOfVoidResult(expression)) {
return;
}

var expressionType = expression.typeOrThrow;
if (expressionType is DynamicType) {
if (_errorVerifier.strictCasts) {
Expand Down Expand Up @@ -316,6 +320,10 @@ class LiteralElementVerifier {
/// Verify that the [expression] is a subtype of `Map<Object, Object>`, and
/// its key and values are assignable to [mapKeyType] and [mapValueType].
void _verifySpreadForMap(bool isNullAware, Expression expression) {
if (_errorVerifier.checkForUseOfVoidResult(expression)) {
return;
}

var expressionType = expression.typeOrThrow;
if (expressionType is DynamicType) {
if (_errorVerifier.strictCasts) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4153,7 +4153,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
);
popRewrite();

if (!node.isNullAware) {
if (!node.isNullAware && node.expression.typeOrThrow is! VoidType) {
nullableDereferenceVerifier.expression(
diag.uncheckedUseOfNullableValueInSpread,
node.expression,
Expand Down
66 changes: 66 additions & 0 deletions pkg/analyzer/test/src/diagnostics/use_of_void_result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,72 @@ class A {
);
}

test_void_spread_list() async {
await assertErrorsInCode(
'''
void f(void e) {
[...e];
}
''',
[error(diag.useOfVoidResult, 23, 1)],
);
}

test_void_spread_list_nullAware() async {
await assertErrorsInCode(
'''
void f(void e) {
[...?e];
}
''',
[error(diag.useOfVoidResult, 24, 1)],
);
}

test_void_spread_map() async {
await assertErrorsInCode(
'''
void f(void e) {
<String, int>{...e};
}
''',
[error(diag.useOfVoidResult, 36, 1)],
);
}

test_void_spread_map_nullAware() async {
await assertErrorsInCode(
'''
void f(void e) {
<String, int>{...?e};
}
''',
[error(diag.useOfVoidResult, 37, 1)],
);
}

test_void_spread_set() async {
await assertErrorsInCode(
'''
void f(void e) {
<Object?>{...e};
}
''',
[error(diag.useOfVoidResult, 32, 1)],
);
}

test_void_spread_set_nullAware() async {
await assertErrorsInCode(
'''
void f(void e) {
<Object?>{...?e};
}
''',
[error(diag.useOfVoidResult, 33, 1)],
);
}

test_yieldStarVoid_asyncStar() async {
await assertErrorsInCode(
'''
Expand Down