Skip to content

Commit 8d0a806

Browse files
committed
Version 1.23.0-dev.11.1
Cherry-pick 37330be to dev Cherry-pick ad54733 to dev Cherry-pick 4d4441a to dev Cherry-pick d9e7a36 to dev
2 parents d4bd756 + 33c75a6 commit 8d0a806

File tree

11 files changed

+151
-54
lines changed

11 files changed

+151
-54
lines changed

CHANGELOG.md

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,43 @@
44
* Allow using URI strings in `part of` declarations to refer to the
55
importing library.
66

7-
### Core library changes
7+
#### Strong Mode
88

9-
* `dart:core`
10-
* Added `Uri.isScheme` function to check the scheme of a URI.
11-
Example: `uri.isScheme("http")`. Ignores case when comparing.
12-
* Make `UriData.parse` validate its input better.
13-
If the data is base-64 encoded, the data is normalized wrt.
14-
alphabet and padding, and it contains invalid base-64 data,
15-
parsing fails. Also normalizes non-base-64 data.
16-
* `dart:io`
17-
* Added functions `File.lastAccessed`, `File.lastAccessedSync`,
18-
`File.setLastModified`, `File.setLastModifiedSync`, `File.setLastAccessed`,
19-
and `File.setLastAccessedSync`.
20-
* Added `{Stdin,Stdout}.supportsAnsiEscapes`.
9+
* Breaking change - it is now a strong mode error if a mixin causes a name
10+
conflict between two private members (field/getter/setter/method) from a
11+
different library. (SDK
12+
issue [28809](https://github.com/dart-lang/sdk/issues/28809)).
2113

22-
### Dart VM
14+
lib1.dart:
2315

24-
* Calls to `print()` and `Stdout.write*()` now correctly print unicode
25-
characters to the console on Windows. Calls to `Stdout.add*()` behave as
26-
before.
2716

28-
### Strong Mode
17+
```dart
18+
class A {
19+
int _x;
20+
}
21+
22+
class B {
23+
int _x;
24+
}
25+
```
26+
27+
lib2.dart:
28+
29+
30+
```dart
31+
import 'lib1.dart';
32+
33+
class C extends A with B {}
34+
```
35+
36+
```
37+
error • The private name _x, defined by B, conflicts with the same name defined by A at tmp/lib2.dart:3:24 • private_collision_in_mixin_application
38+
```
39+
2940

30-
* Strong mode will prefer the expected type to infer generic types,
31-
functions, and methods
32-
(SDK issue [27586](https://github.com/dart-lang/sdk/issues/27586)).
41+
* Breaking change - strong mode will prefer the expected type to infer generic
42+
types, functions, and methods (SDK
43+
issue [27586](https://github.com/dart-lang/sdk/issues/27586)).
3344

3445
```dart
3546
main() {
@@ -75,6 +86,49 @@
7586
}
7687
```
7788
89+
* Strong mode down cast composite warnings are no longer issued by default.
90+
(SDK issue [28588](https://github.com/dart-lang/sdk/issues/28588)).
91+
92+
```dart
93+
void test() {
94+
List untyped = [];
95+
List<int> typed = untyped; // No down cast composite warning
96+
}
97+
```
98+
99+
To opt back into the warnings, add the following to
100+
the
101+
[.analysis_options](https://www.dartlang.org/guides/language/analysis-options)
102+
file for your project.
103+
104+
```
105+
analyzer:
106+
errors:
107+
strong_mode_down_cast_composite: warning
108+
```
109+
110+
111+
### Core library changes
112+
113+
* `dart:core`
114+
* Added `Uri.isScheme` function to check the scheme of a URI.
115+
Example: `uri.isScheme("http")`. Ignores case when comparing.
116+
* Make `UriData.parse` validate its input better.
117+
If the data is base-64 encoded, the data is normalized wrt.
118+
alphabet and padding, and it contains invalid base-64 data,
119+
parsing fails. Also normalizes non-base-64 data.
120+
* `dart:io`
121+
* Added functions `File.lastAccessed`, `File.lastAccessedSync`,
122+
`File.setLastModified`, `File.setLastModifiedSync`, `File.setLastAccessed`,
123+
and `File.setLastAccessedSync`.
124+
* Added `{Stdin,Stdout}.supportsAnsiEscapes`.
125+
126+
### Dart VM
127+
128+
* Calls to `print()` and `Stdout.write*()` now correctly print unicode
129+
characters to the console on Windows. Calls to `Stdout.add*()` behave as
130+
before.
131+
78132
### Tool changes
79133

80134
* Analysis

pkg/analyzer/lib/dart/element/element.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,25 @@ abstract class FunctionTypedElement implements TypeParameterizedElement {
13291329

13301330
/**
13311331
* The pseudo-declaration that defines a generic function type.
1332+
*
1333+
* Clients may not extend, implement, or mix-in this class.
13321334
*/
13331335
abstract class GenericFunctionTypeElement implements FunctionTypedElement {}
13341336

1337+
/**
1338+
* A [FunctionTypeAliasElement] whose returned function type has a [type]
1339+
* parameter.
1340+
*
1341+
* Clients may not extend, implement, or mix-in this class.
1342+
*/
1343+
abstract class GenericTypeAliasElement implements FunctionTypeAliasElement {
1344+
/**
1345+
* Return the generic function type element representing the generic function
1346+
* type on the right side of the equals.
1347+
*/
1348+
GenericFunctionTypeElement get function;
1349+
}
1350+
13351351
/**
13361352
* A combinator that causes some of the names in a namespace to be hidden when
13371353
* being imported.

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5029,7 +5029,7 @@ class GenericFunctionTypeElementImpl extends ElementImpl
50295029
*/
50305030
class GenericTypeAliasElementImpl extends ElementImpl
50315031
with TypeParameterizedElementMixin
5032-
implements FunctionTypeAliasElement {
5032+
implements GenericTypeAliasElement {
50335033
/**
50345034
* The unlinked representation of the type in the summary.
50355035
*/
@@ -5097,10 +5097,7 @@ class GenericTypeAliasElementImpl extends ElementImpl
50975097
CompilationUnitElementImpl get enclosingUnit =>
50985098
_enclosingElement as CompilationUnitElementImpl;
50995099

5100-
/**
5101-
* Return the generic function type element representing the generic function
5102-
* type on the right side of the equals.
5103-
*/
5100+
@override
51045101
GenericFunctionTypeElement get function {
51055102
if (_function == null && _unlinkedTypedef != null) {
51065103
DartType type = enclosingUnit.resynthesizerContext.resolveTypeRef(

pkg/analyzer/lib/src/error/codes.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,46 +4951,51 @@ class StrongModeCode extends ErrorCode {
49514951
"Type parameter bound types must be instantiated.",
49524952
"Try adding type arguments.");
49534953

4954+
/*
4955+
* TODO(brianwilkerson) Make the TOP_LEVEL_ error codes be errors rather than
4956+
* hints and then clean up the function _errorSeverity in
4957+
* test/src/task/strong/strong_test_helper.dart.
4958+
*/
49544959
static const StrongModeCode TOP_LEVEL_CYCLE = const StrongModeCode(
4955-
ErrorType.COMPILE_TIME_ERROR,
4960+
ErrorType.HINT,
49564961
'TOP_LEVEL_CYCLE',
49574962
"The type of '{0}' can't be inferred because it depends on itself through the cycle: {1}.",
49584963
"Try adding an explicit type to one or more of the variables in the cycle in order to break the cycle.");
49594964

49604965
static const StrongModeCode TOP_LEVEL_FUNCTION_LITERAL_BLOCK =
49614966
const StrongModeCode(
4962-
ErrorType.COMPILE_TIME_ERROR,
4967+
ErrorType.HINT,
49634968
'TOP_LEVEL_FUNCTION_LITERAL_BLOCK',
49644969
"The type of the function literal can't be inferred because the literal has a block as its body.",
49654970
"Try adding an explicit type to the variable.");
49664971

49674972
static const StrongModeCode TOP_LEVEL_FUNCTION_LITERAL_PARAMETER =
49684973
const StrongModeCode(
4969-
ErrorType.COMPILE_TIME_ERROR,
4974+
ErrorType.HINT,
49704975
'TOP_LEVEL_FUNCTION_LITERAL_PARAMETER',
49714976
"The type of '{0}' can't be inferred because the parameter '{1}' does not have an explicit type.",
49724977
"Try adding an explicit type to the parameter '{1}', or add an explicit type for '{0}'.");
49734978

49744979
static const StrongModeCode TOP_LEVEL_IDENTIFIER_NO_TYPE = const StrongModeCode(
4975-
ErrorType.COMPILE_TIME_ERROR,
4980+
ErrorType.HINT,
49764981
'TOP_LEVEL_IDENTIFIER_NO_TYPE',
49774982
"The type of '{0}' can't be inferred because the type of '{1}' couldn't be inferred.",
49784983
"Try adding an explicit type to either the variable '{0}' or the variable '{1}'.");
49794984

49804985
static const StrongModeCode TOP_LEVEL_INSTANCE_GETTER = const StrongModeCode(
4981-
ErrorType.COMPILE_TIME_ERROR,
4986+
ErrorType.HINT,
49824987
'TOP_LEVEL_INSTANCE_GETTER',
49834988
"The type of '{0}' can't be inferred because of the use of the instance getter '{1}'.",
49844989
"Try removing the use of the instance getter {1}, or add an explicit type for '{0}'.");
49854990

49864991
static const StrongModeCode TOP_LEVEL_TYPE_ARGUMENTS = const StrongModeCode(
4987-
ErrorType.COMPILE_TIME_ERROR,
4992+
ErrorType.HINT,
49884993
'TOP_LEVEL_TYPE_ARGUMENTS',
49894994
"The type of '{0}' can't be inferred because type arguments were not given for '{1}'.",
49904995
"Try adding type arguments for '{1}', or add an explicit type for '{0}'.");
49914996

49924997
static const StrongModeCode TOP_LEVEL_UNSUPPORTED = const StrongModeCode(
4993-
ErrorType.COMPILE_TIME_ERROR,
4998+
ErrorType.HINT,
49944999
'TOP_LEVEL_UNSUPPORTED',
49955000
"The type of '{0}' can't be inferred because {1} expressions aren't supported.",
49965001
"Try adding an explicit type for '{0}'.");

pkg/analyzer/lib/src/task/strong/checker.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,13 @@ class CodeChecker extends RecursiveAstVisitor {
10471047
var severity =
10481048
(processor != null) ? processor.severity : errorCode.errorSeverity;
10491049

1050-
if (severity == ErrorSeverity.ERROR) _failure = true;
1050+
if (severity == ErrorSeverity.ERROR) {
1051+
_failure = true;
1052+
}
1053+
if (errorCode.type == ErrorType.HINT &&
1054+
errorCode.name.startsWith('STRONG_MODE_TOP_LEVEL_')) {
1055+
severity = ErrorSeverity.ERROR;
1056+
}
10511057
if (severity != ErrorSeverity.INFO || _options.strongModeHints) {
10521058
int begin = node is AnnotatedNode
10531059
? node.firstTokenAfterCommentAndMetadata.offset

pkg/analyzer/test/generated/hint_code_test.dart

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,10 +2499,10 @@ class C {
24992499
verify([source]);
25002500
}
25012501

2502-
test_strongMode_downCastCompositeNoHint() async {
2502+
test_strongMode_downCastCompositeHint() async {
25032503
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
25042504
options.strongMode = true;
2505-
options.strongModeHints = false;
2505+
options.strongModeHints = true;
25062506
resetWith(options: options);
25072507
Source source = addSource(r'''
25082508
main() {
@@ -2511,14 +2511,14 @@ main() {
25112511
print(list);
25122512
}''');
25132513
await computeAnalysisResult(source);
2514-
assertNoErrors(source);
2514+
assertErrors(source, [StrongModeCode.DOWN_CAST_COMPOSITE]);
25152515
verify([source]);
25162516
}
25172517

2518-
test_strongMode_downCastCompositeHint() async {
2518+
test_strongMode_downCastCompositeNoHint() async {
25192519
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
25202520
options.strongMode = true;
2521-
options.strongModeHints = true;
2521+
options.strongModeHints = false;
25222522
resetWith(options: options);
25232523
Source source = addSource(r'''
25242524
main() {
@@ -2527,7 +2527,7 @@ main() {
25272527
print(list);
25282528
}''');
25292529
await computeAnalysisResult(source);
2530-
assertErrors(source, [StrongModeCode.DOWN_CAST_COMPOSITE]);
2530+
assertNoErrors(source);
25312531
verify([source]);
25322532
}
25332533

@@ -2554,6 +2554,20 @@ main() {
25542554
verify([source]);
25552555
}
25562556

2557+
test_strongMode_topLevelInstanceGetter() async {
2558+
resetWith(options: new AnalysisOptionsImpl()..strongMode = true);
2559+
Source source = addSource(r'''
2560+
class A {
2561+
int get g => 0;
2562+
}
2563+
var a = new A();
2564+
var b = a.g;
2565+
''');
2566+
await computeAnalysisResult(source);
2567+
assertErrors(source, [StrongModeCode.TOP_LEVEL_INSTANCE_GETTER]);
2568+
verify([source]);
2569+
}
2570+
25572571
test_typeCheck_type_is_Null() async {
25582572
Source source = addSource(r'''
25592573
m(i) {

pkg/analyzer/test/src/task/strong/strong_test_helper.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ String _errorCodeName(ErrorCode errorCode) {
6767

6868
ErrorSeverity _errorSeverity(
6969
AnalysisOptions analysisOptions, AnalysisError error) {
70+
// TODO(brianwilkerson) Remove the if when top-level inference is made an
71+
// error again.
72+
if (error.errorCode.name.startsWith('STRONG_MODE_TOP_LEVEL_')) {
73+
return ErrorSeverity.ERROR;
74+
}
7075
return ErrorProcessor.getProcessor(analysisOptions, error)?.severity ??
7176
error.errorCode.errorSeverity;
7277
}

tests/corelib_strong/corelib_strong.status

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ uri_path_test: Skip
5656
uri_query_test: Skip
5757

5858
[ $compiler == dart2analyzer && $strong ]
59-
error_stack_trace2_test: CompileTimeError
59+
# error_stack_trace2_test: CompileTimeError

tests/language_strong/language_strong.status

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -682,20 +682,20 @@ void_type_test: Skip
682682
wrong_number_type_arguments_test: Skip
683683

684684
[ $compiler == dart2analyzer && $strong ]
685-
async_await_test/02: CompileTimeError # Issue 28823
686-
async_await_test/03: CompileTimeError # Issue 28823
687-
async_await_test/none: CompileTimeError # Issue 28823
688-
async_star_test/01: CompileTimeError # Issue 28823
689-
async_star_test/02: CompileTimeError # Issue 28823
690-
async_star_test/03: CompileTimeError # Issue 28823
691-
async_star_test/04: CompileTimeError # Issue 28823
692-
async_star_test/05: CompileTimeError # Issue 28823
693-
async_star_test/none: CompileTimeError # Issue 28823
685+
# async_await_test/02: CompileTimeError # Issue 28823
686+
# async_await_test/03: CompileTimeError # Issue 28823
687+
# async_await_test/none: CompileTimeError # Issue 28823
688+
# async_star_test/01: CompileTimeError # Issue 28823
689+
# async_star_test/02: CompileTimeError # Issue 28823
690+
# async_star_test/03: CompileTimeError # Issue 28823
691+
# async_star_test/04: CompileTimeError # Issue 28823
692+
# async_star_test/05: CompileTimeError # Issue 28823
693+
# async_star_test/none: CompileTimeError # Issue 28823
694694
bit_operations_test/01: MissingStaticWarning # Issue 28823
695695
bit_operations_test/02: MissingStaticWarning # Issue 28823
696696
bit_operations_test/03: MissingStaticWarning # Issue 28823
697697
bit_operations_test/04: MissingStaticWarning # Issue 28823
698-
closure_side_effect_test: CompileTimeError # Issue 28823
698+
# closure_side_effect_test: CompileTimeError # Issue 28823
699699
constant_type_literal_test/01: MissingCompileTimeError # Issue 28823
700700
field3a_negative_test: StaticWarning # Issue 28823
701701
generic_methods_overriding_test/01: MissingCompileTimeError # Issue 29070
@@ -704,7 +704,7 @@ generic_methods_shadowing_test: CompileTimeError # Issue 29070
704704
generic_methods_closure_test: CompileTimeError # Issue 29070
705705
generic_methods_simple_is_expression_test: CompileTimeError # Issue 29070
706706
generic_methods_local_variable_declaration_test: CompileTimeError # Issue 29070
707-
inferrer_constructor3_test: CompileTimeError
707+
# inferrer_constructor3_test: CompileTimeError
708708
interface_inherit_field_test: StaticWarning # Issue 28823
709709
internal_library_test/02: MissingStaticWarning # Issue 28823
710710
main_not_a_function_test/01: MissingStaticWarning # Issue 28823

tests/lib_strong/lib_strong.status

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ html/custom/document_register_basic_test: CompileTimeError # Issue 28969
138138
html/custom/document_register_type_extensions_test: CompileTimeError # Issue 28969
139139
html/custom/element_upgrade_test: CompileTimeError # Issue 28969
140140
html/debugger_test: CompileTimeError # Issue 28969
141-
html/input_element_test: CompileTimeError
141+
# html/input_element_test: CompileTimeError
142142
html/js_typed_interop_default_arg_test/default_value: MissingCompileTimeError # Issue 28969
143143
mirrors/deferred_mirrors_metadata_test: StaticWarning # Issue 28969

0 commit comments

Comments
 (0)