Skip to content

Commit fda4238

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
During linking, resolve initializers of constant variables with flow analysis.
Change-Id: I6189cdf86f0e285883da769ceb0b36d6ee85588c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151086 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 2485242 commit fda4238

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/analyzer/lib/src/summary2/top_level_inference.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ConstantInitializersResolver {
9999
InferenceContext.setType(variable.initializer, typeNode.type);
100100
return variable.initializer;
101101
},
102+
isTopLevelVariableInitializer: true,
102103
);
103104
}
104105
}

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,6 +3996,24 @@ const Symbol vSymbol = #aaa.bbb.ccc;
39963996
''');
39973997
}
39983998

3999+
test_const_topLevel_nullSafe_nullAware_propertyAccess() async {
4000+
featureSet = enableNnbd;
4001+
var library = await checkLibrary(r'''
4002+
const String? a = '';
4003+
4004+
const List<int?> b = [
4005+
a?.length,
4006+
];
4007+
''');
4008+
// TODO(scheglov) include fully resolved AST, when types with suffixes
4009+
checkElementText(library, r'''
4010+
const String a = '';
4011+
const List<int> b = [
4012+
a/*location: test.dart;a?*/.
4013+
length/*location: dart:core;String;length?*/];
4014+
''');
4015+
}
4016+
39994017
test_const_topLevel_parenthesis() async {
40004018
var library = await checkLibrary(r'''
40014019
const int v1 = (1 + 2) * 3;

0 commit comments

Comments
 (0)