Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5bcb191

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Add documentation saying that String.fromEnvironment etc. must behave consistently.
AAll calls to those constructors must behave as if there is a single consistent environment backing them. This will force compilers to reject programs where that wouldn't be the case, which is possible if doing modular compilation with different settings. If a library doesn't check the environment, it doesn't matter whether the environment was declared differently, the requirement is only that when actually checking, the values must be consistent. Bug: dart-lang/language#304 Change-Id: Ie52ecc3ea49ed87297fab92e5e7bb6d9f96a495d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184467 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Reviewed-by: Leaf Petersen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent e5732b1 commit 5bcb191

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

sdk/lib/core/bool.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class bool {
3636
/// ```dart
3737
/// const isLoggingOn = (const String.fromEnvironment("logging") == "on");
3838
/// ```
39+
///
40+
/// The string value, or lack of a value, associated with a [name]
41+
/// must be consistent across all calls to [String.fromEnvironment],
42+
/// [int.fromEnvironment], `bool.fromEnvironment` and [bool.hasEnvironment]
43+
/// in a single program.
3944
// The .fromEnvironment() constructors are special in that we do not want
4045
// users to call them using "new". We prohibit that by giving them bodies
4146
// that throw, even though const constructors are not allowed to have bodies.
@@ -66,6 +71,11 @@ class bool {
6671
/// ? String.fromEnvironment("logging")
6772
/// : null;
6873
/// ```
74+
///
75+
/// The string value, or lack of a value, associated with a [name]
76+
/// must be consistent across all calls to [String.fromEnvironment],
77+
/// [int.fromEnvironment], [bool.fromEnvironment] and `bool.hasEnvironment`
78+
/// in a single program.
6979
// The .hasEnvironment() constructor is special in that we do not want
7080
// users to call them using "new". We prohibit that by giving them bodies
7181
// that throw, even though const constructors are not allowed to have bodies.

sdk/lib/core/int.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ abstract class int extends num {
3232
/// ```
3333
/// const int.fromEnvironment("defaultPort", defaultValue: 80)
3434
/// ```
35+
///
36+
/// The string value, or lack of a value, associated with a [name]
37+
/// must be consistent across all calls to [String.fromEnvironment],
38+
/// `int.fromEnvironment`, [bool.fromEnvironment] and [bool.hasEnvironment]
39+
/// in a single program.
3540
// The .fromEnvironment() constructors are special in that we do not want
3641
// users to call them using "new". We prohibit that by giving them bodies
3742
// that throw, even though const constructors are not allowed to have bodies.

sdk/lib/core/string.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ abstract class String implements Comparable<String>, Pattern {
146146
/// ? String.fromEnvironment("maybeDeclared")
147147
/// : null;
148148
/// ```
149+
///
150+
/// The string value, or lack of a value, associated with a [name]
151+
/// must be consistent across all calls to `String.fromEnvironment`,
152+
/// [int.fromEnvironment], [bool.fromEnvironment] and [bool.hasEnvironment]
153+
/// in a single program.
149154
// The .fromEnvironment() constructors are special in that we do not want
150155
// users to call them using "new". We prohibit that by giving them bodies
151156
// that throw, even though const constructors are not allowed to have bodies.

0 commit comments

Comments
 (0)