-
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.
Merge 0da6318 into dev
- Loading branch information
Showing
17 changed files
with
738 additions
and
14 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
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
76 changes: 76 additions & 0 deletions
76
pkg/front_end/testcases/null_aware_elements/flow_analysis_null_aware_map_entires.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,76 @@ | ||
// 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. | ||
|
||
test1(String a, num x) { | ||
<String, dynamic>{?a: (x as int)}; | ||
x..expectStaticType<Exactly<int>>(); | ||
} | ||
|
||
test2(String? a, num x) { | ||
<String, dynamic>{?a: (x as int)}; | ||
x..expectStaticType<Exactly<num>>(); | ||
} | ||
|
||
test3(String a, bool b, num x) { | ||
if (b) { | ||
x as int; | ||
} else { | ||
<String, dynamic>{?a: (throw 0)}; | ||
// Unreachable. | ||
} | ||
x..expectStaticType<Exactly<int>>(); | ||
} | ||
|
||
test4(String? a, bool b, num x) { | ||
if (b) { | ||
x as int; | ||
} else { | ||
<String, dynamic>{?a: (throw 0)}; | ||
// Reachable. | ||
} | ||
x..expectStaticType<Exactly<num>>(); | ||
} | ||
|
||
test5(String? a) { | ||
return {?a: a..expectStaticType<Exactly<String>>()}; | ||
} | ||
|
||
test6(String? a) { | ||
return {a: a..expectStaticType<Exactly<String?>>()}; | ||
} | ||
|
||
extension E<X> on X { | ||
void expectStaticType<Y extends Exactly<X>>() {} | ||
} | ||
|
||
typedef Exactly<X> = X Function(X); | ||
|
||
void expectThrows(void Function() f) { | ||
bool hasThrown; | ||
try { | ||
f(); | ||
hasThrown = false; | ||
} catch (e) { | ||
hasThrown = true; | ||
} | ||
|
||
if (!hasThrown) { | ||
throw "Expected the function to throw an exception."; | ||
} | ||
} | ||
|
||
main() { | ||
test1("", 0); | ||
|
||
test2("", 0); | ||
test2(null, 0); | ||
|
||
test3("", true, 0); | ||
expectThrows(() => test3("", false, 0)); | ||
|
||
test4("", true, 0); | ||
expectThrows(() => test4("", false, 0)); | ||
test4(null, true, 0); | ||
test4(null, false, 0); | ||
} |
Oops, something went wrong.