-
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.
[_fe_analyzer_shared] Avoid deconstruction of potentially nullable ty…
…pe variables The exhaustiveness model relies on null being extracted from nullable, for instance modeling `int?` as `int|Null`. This failed on type variable that are potentially nullable but not explicitly nullable. For these `Null` should be extract from their bound and not from themselves. The logic in the getStaticType method now uses `isNullable` to determine both when to extract and to combine, so to avoid extracting but not combining `Null` for type variables and also not combine but not extract for instance for `void`. Closes #56998 Change-Id: I47c2d0d6535ca66fe00e6344b11550c4308a7388 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392944 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
- Loading branch information
1 parent
297c90b
commit 58c336e
Showing
3 changed files
with
64 additions
and
17 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
38 changes: 38 additions & 0 deletions
38
pkg/_fe_analyzer_shared/test/exhaustiveness/data/issue56998.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,38 @@ | ||
// 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. | ||
|
||
int nonExhaustive1<T extends int?>(T value) => | ||
/* | ||
checkingOrder={int?,int,Null}, | ||
error=non-exhaustive:null, | ||
subtypes={int,Null}, | ||
type=int? | ||
*/switch (value) { int() /*space=int*/ => value }; | ||
|
||
int nonExhaustive2<T extends int?>( | ||
T? value) => /* | ||
checkingOrder={int?,int,Null}, | ||
error=non-exhaustive:null, | ||
subtypes={int,Null}, | ||
type=int? | ||
*/ | ||
switch (value) { | ||
int() /*space=int*/ => value | ||
}; | ||
|
||
int exhaustive<T extends int>(T value) => /*type=int*/ | ||
switch (value) { | ||
int() /*space=int*/ => value | ||
}; | ||
|
||
int nonExhaustive3<T extends int>( | ||
T? value) => /* | ||
checkingOrder={int?,int,Null}, | ||
error=non-exhaustive:null, | ||
subtypes={int,Null}, | ||
type=int? | ||
*/ | ||
switch (value) { | ||
int() /*space=int*/ => value | ||
}; |
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