Version 2.12.0-226.0.dev
Merge commit 'cfe510ade8c7beb6bee9259ce8588c9ed2e78773' into 'dev'
diff --git a/DEPS b/DEPS
index 2c9ef02..cc4a62a 100644
--- a/DEPS
+++ b/DEPS
@@ -101,7 +101,7 @@
"dart_style_tag": "1.3.11", # Please see the note above before updating.
"chromedriver_tag": "83.0.4103.39",
- "dartdoc_rev" : "a1d86f2c992f4660ddcc09b27733396e92765d2a",
+ "dartdoc_rev" : "9e61a4f11091aaa8998525a2692b14148dc24ab5",
"ffi_rev": "31352979f261f7c6ea88fa0a2cfb0fdd004c38fb",
"fixnum_rev": "16d3890c6dc82ca629659da1934e412292508bba",
"file_rev": "0e09370f581ab6388d46fda4cdab66638c0171a1",
diff --git a/pkg/analysis_server/lib/src/services/search/search_engine_internal.dart b/pkg/analysis_server/lib/src/services/search/search_engine_internal.dart
index 3260c5d..ddc1c22 100644
--- a/pkg/analysis_server/lib/src/services/search/search_engine_internal.dart
+++ b/pkg/analysis_server/lib/src/services/search/search_engine_internal.dart
@@ -127,7 +127,7 @@
SearchedFiles _createSearchedFiles(List<AnalysisDriver> drivers) {
var searchedFiles = SearchedFiles();
for (var driver in drivers) {
- searchedFiles.ownAdded(driver.search);
+ searchedFiles.ownAnalyzed(driver.search);
}
return searchedFiles;
}
diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart
index 14990fd..9676017 100644
--- a/pkg/analysis_server/test/abstract_context.dart
+++ b/pkg/analysis_server/test/abstract_context.dart
@@ -278,6 +278,21 @@
}
}
+mixin WithNonFunctionTypeAliasesMixin on AbstractContextTest {
+ @override
+ String get testPackageLanguageVersion => null;
+
+ @nonVirtual
+ @override
+ void setUp() {
+ super.setUp();
+
+ createAnalysisOptionsFile(
+ experiments: [EnableString.nonfunction_type_aliases],
+ );
+ }
+}
+
mixin WithNullSafetyMixin on AbstractContextTest {
@override
String get testPackageLanguageVersion => '2.12';
diff --git a/pkg/analysis_server/test/abstract_single_unit.dart b/pkg/analysis_server/test/abstract_single_unit.dart
index 006b6c1..1dca4d3 100644
--- a/pkg/analysis_server/test/abstract_single_unit.dart
+++ b/pkg/analysis_server/test/abstract_single_unit.dart
@@ -7,7 +7,6 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/file_system.dart';
-import 'package:analyzer/src/dart/ast/element_locator.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/error/hint_codes.dart';
import 'package:analyzer/src/generated/java_engine.dart';
@@ -53,11 +52,6 @@
return findOffset(search) + search.length;
}
- /// Returns the [SimpleIdentifier] at the given search pattern.
- SimpleIdentifier findIdentifier(String search) {
- return findNodeAtString(search, (node) => node is SimpleIdentifier);
- }
-
AstNode findNodeAtOffset(int offset, [Predicate<AstNode> predicate]) {
var result = NodeLocator(offset).searchWithin(testUnit);
if (result != null && predicate != null) {
@@ -71,42 +65,12 @@
return findNodeAtOffset(offset, predicate);
}
- Element findNodeElementAtString(String search,
- [Predicate<AstNode> predicate]) {
- var node = findNodeAtString(search, predicate);
- if (node == null) {
- return null;
- }
- return ElementLocator.locate(node);
- }
-
int findOffset(String search) {
var offset = testCode.indexOf(search);
expect(offset, isNonNegative, reason: "Not found '$search' in\n$testCode");
return offset;
}
- int getLeadingIdentifierLength(String search) {
- var length = 0;
- while (length < search.length) {
- var c = search.codeUnitAt(length);
- if (c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0)) {
- length++;
- continue;
- }
- if (c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0)) {
- length++;
- continue;
- }
- if (c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0)) {
- length++;
- continue;
- }
- break;
- }
- return length;
- }
-
@override
File newFile(String path, {String content = ''}) {
if (useLineEndingsForPlatform) {
@@ -122,6 +86,7 @@
Future<void> resolveTestFile() async {
testAnalysisResult = await session.getResolvedUnit(testFile);
+ testCode = testAnalysisResult.content;
testUnit = testAnalysisResult.unit;
if (verifyNoTestUnitErrors) {
expect(testAnalysisResult.errors.where((AnalysisError error) {
diff --git a/pkg/analysis_server/test/services/refactoring/abstract_rename.dart b/pkg/analysis_server/test/services/refactoring/abstract_rename.dart
index 7de0635..3a3c7aa 100644
--- a/pkg/analysis_server/test/services/refactoring/abstract_rename.dart
+++ b/pkg/analysis_server/test/services/refactoring/abstract_rename.dart
@@ -40,7 +40,7 @@
/// Creates a new [RenameRefactoring] in [refactoring] for the [Element] of
/// the [SimpleIdentifier] at the given [search] pattern.
void createRenameRefactoringAtString(String search) {
- var identifier = findIdentifier(search);
+ var identifier = findNode.simple(search);
var element = identifier.writeOrReadElement;
if (element is PrefixElement) {
element = getImportElement(identifier);
diff --git a/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart b/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart
index 5f334d4..aa6c028 100644
--- a/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/convert_getter_to_method_test.dart
@@ -63,7 +63,8 @@
var vd = d.test;
}
''');
- _createRefactoringForString('test => 2');
+ var element = findElement.getter('test', of: 'B');
+ _createRefactoringForElement(element);
// apply refactoring
return _assertSuccessfulRefactoring('''
class A {
@@ -103,7 +104,8 @@
b.test;
}
''');
- _createRefactoringForString('test => 2');
+ var element = findElement.getter('test', of: 'B');
+ _createRefactoringForElement(element);
// apply refactoring
return _assertSuccessfulRefactoring('''
import 'other.dart';
@@ -149,9 +151,4 @@
refactoring = ConvertGetterToMethodRefactoring(
searchEngine, testAnalysisResult.session, element);
}
-
- void _createRefactoringForString(String search) {
- ExecutableElement element = findNodeElementAtString(search);
- _createRefactoringForElement(element);
- }
}
diff --git a/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart b/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart
index e80bb98..4683949 100644
--- a/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/convert_method_to_getter_test.dart
@@ -63,7 +63,8 @@
var vd = d.test();
}
''');
- _createRefactoringForString('test() => 2');
+ var element = findElement.method('test', of: 'B');
+ _createRefactoringForElement(element);
// apply refactoring
return _assertSuccessfulRefactoring('''
class A {
@@ -103,7 +104,8 @@
b.test();
}
''');
- _createRefactoringForString('test() => 2');
+ var element = findElement.method('test', of: 'B');
+ _createRefactoringForElement(element);
// apply refactoring
return _assertSuccessfulRefactoring('''
import 'other.dart';
@@ -203,9 +205,4 @@
refactoring = ConvertMethodToGetterRefactoring(
searchEngine, testAnalysisResult.session, element);
}
-
- void _createRefactoringForString(String search) {
- ExecutableElement element = findNodeElementAtString(search);
- _createRefactoringForElement(element);
- }
}
diff --git a/pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart b/pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart
index 045a97a..52da455 100644
--- a/pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/rename_constructor_test.dart
@@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
-import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -236,14 +234,13 @@
}
void _createConstructorDeclarationRefactoring(String search) {
- ConstructorElement element = findNodeElementAtString(
- search, (node) => node is ConstructorDeclaration);
+ var element = findNode.constructor(search).declaredElement;
createRenameRefactoringForElement(element);
}
void _createConstructorInvocationRefactoring(String search) {
- ConstructorElement element = findNodeElementAtString(
- search, (node) => node is InstanceCreationExpression);
+ var instanceCreation = findNode.instanceCreation(search);
+ var element = instanceCreation.constructorName.staticElement;
createRenameRefactoringForElement(element);
}
}
diff --git a/pkg/analysis_server/test/services/refactoring/rename_local_test.dart b/pkg/analysis_server/test/services/refactoring/rename_local_test.dart
index 31993ea..e13ea89 100644
--- a/pkg/analysis_server/test/services/refactoring/rename_local_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/rename_local_test.dart
@@ -465,10 +465,8 @@
''');
await analyzeTestPackageFiles();
- testAnalysisResult = await resolveFile(a);
- testFile = testAnalysisResult.path;
- testCode = testAnalysisResult.content;
- testUnit = testAnalysisResult.unit;
+ testFile = a;
+ await resolveTestFile();
createRenameRefactoringAtString('test});');
expect(refactoring.refactoringName, 'Rename Parameter');
diff --git a/pkg/analysis_server/test/services/search/search_engine_test.dart b/pkg/analysis_server/test/services/search/search_engine_test.dart
index f090ec9..9e59c61 100644
--- a/pkg/analysis_server/test/services/search/search_engine_test.dart
+++ b/pkg/analysis_server/test/services/search/search_engine_test.dart
@@ -17,6 +17,7 @@
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(SearchEngineImplTest);
+ defineReflectiveTests(SearchEngineImplWithNonFunctionTypeAliasesTest);
});
}
@@ -61,22 +62,6 @@
return SearchEngineImpl(allDrivers);
}
- @override
- void setUp() {
- super.setUp();
-
- // TODO(scheglov) This is not ideal.
- // We write into the root because we choose the workspace root to
- // index `aaa/lib/a.dart`. But ideally we should use the context root
- // that contains it (i.e. `root/aaa`), or a context root where it is a
- // package (e.g. `root/test`).
- writePackageConfig(
- '$workspaceRootPath/.dart_tool/package_config.json',
- PackageConfigFileBuilder()
- ..add(name: 'test', rootPath: testPackageRootPath),
- );
- }
-
Future<void> test_membersOfSubtypes_hasMembers() async {
newFile('$testPackageLibPath/a.dart', content: '''
class A {
@@ -424,22 +409,16 @@
String _configureForPackage_aaa() {
var aaaRootPath = '$workspaceRootPath/aaa';
+ writePackageConfig(
+ '$aaaRootPath/.dart_tool/package_config.json',
+ PackageConfigFileBuilder()..add(name: 'aaa', rootPath: aaaRootPath),
+ );
+
writeTestPackageConfig(
config: PackageConfigFileBuilder()
..add(name: 'aaa', rootPath: aaaRootPath),
);
- // TODO(scheglov) This is not ideal.
- // We write into the root because we choose the workspace root to
- // index `aaa/lib/a.dart`. But ideally we should use the context root
- // that contains it (i.e. `root/aaa`), or a context root where it is a
- // package (e.g. `root/test`).
- writePackageConfig(
- '$workspaceRootPath/.dart_tool/package_config.json',
- PackageConfigFileBuilder()
- ..add(name: 'aaa', rootPath: aaaRootPath)
- ..add(name: 'test', rootPath: testPackageRootPath),
- );
return aaaRootPath;
}
@@ -447,7 +426,9 @@
for (var driver in allDrivers) {
var contextRoot = driver.analysisContext.contextRoot;
for (var file in contextRoot.analyzedFiles()) {
- await driver.getUnitElement(file);
+ if (file.endsWith('.dart')) {
+ await driver.getUnitElement(file);
+ }
}
}
}
@@ -456,3 +437,33 @@
expect(subtypes, contains(predicate((ClassElement e) => e.name == name)));
}
}
+
+@reflectiveTest
+class SearchEngineImplWithNonFunctionTypeAliasesTest
+ extends SearchEngineImplTest with WithNonFunctionTypeAliasesMixin {
+ Future<void> test_searchReferences_typeAlias_interfaceType() async {
+ await resolveTestCode('''
+typedef A<T> = Map<T, String>;
+
+void f(A<int> a, A<double> b) {}
+''');
+
+ var element = findElement.typeAlias('A');
+ var matches = await searchEngine.searchReferences(element);
+
+ Matcher hasOne(Element element, String search) {
+ return predicate((SearchMatch match) {
+ return match.element == element &&
+ match.sourceRange.offset == findNode.offset(search);
+ });
+ }
+
+ expect(
+ matches,
+ unorderedMatches([
+ hasOne(findElement.parameter('a'), 'A<int>'),
+ hasOne(findElement.parameter('b'), 'A<double>'),
+ ]),
+ );
+ }
+}
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index cf8be4e..dc113ba 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -248,9 +248,8 @@
void _computeConstantErrors(
ErrorReporter errorReporter, CompilationUnit unit) {
- ConstantVerifier constantVerifier = ConstantVerifier(
- errorReporter, _libraryElement, _declaredVariables,
- featureSet: unit.featureSet);
+ ConstantVerifier constantVerifier =
+ ConstantVerifier(errorReporter, _libraryElement, _declaredVariables);
unit.accept(constantVerifier);
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index d9cf7b5..4207727 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -249,7 +249,7 @@
}
} else {
files = await _driver.getFilesReferencingName(name);
- if (!files.contains(path)) {
+ if (searchedFiles.add(path, this) && !files.contains(path)) {
files.add(path);
}
}
@@ -500,9 +500,12 @@
return identical(pathOwner, search) && identical(uriOwner, search);
}
- void ownAdded(Search search) {
- for (var path in search._driver.addedFiles) {
- add(path, search);
+ void ownAnalyzed(Search search) {
+ var contextRoot = search._driver.analysisContext.contextRoot;
+ for (var path in contextRoot.analyzedFiles()) {
+ if (path.endsWith('.dart')) {
+ add(path, search);
+ }
}
}
}
diff --git a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
index ad1100b..e517f1d 100644
--- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
+++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/declared_variables.dart';
-import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
@@ -46,38 +45,30 @@
/// The current library that is being analyzed.
final LibraryElement _currentLibrary;
- final bool _constantUpdate2018Enabled;
-
final ConstantEvaluationEngine _evaluationEngine;
final DiagnosticFactory _diagnosticFactory = DiagnosticFactory();
/// Initialize a newly created constant verifier.
- ConstantVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary,
- DeclaredVariables declaredVariables,
- {
- // TODO(paulberry): make [featureSet] a required parameter.
- FeatureSet featureSet})
- : this._(
- errorReporter,
- currentLibrary,
- currentLibrary.typeSystem,
- currentLibrary.typeProvider,
- declaredVariables,
- featureSet ??
- (currentLibrary.context.analysisOptions as AnalysisOptionsImpl)
- .contextFeatures);
+ ConstantVerifier(
+ ErrorReporter errorReporter,
+ LibraryElement currentLibrary,
+ DeclaredVariables declaredVariables,
+ ) : this._(
+ errorReporter,
+ currentLibrary,
+ currentLibrary.typeSystem,
+ currentLibrary.typeProvider,
+ declaredVariables,
+ );
ConstantVerifier._(
- this._errorReporter,
- this._currentLibrary,
- this._typeSystem,
- this._typeProvider,
- this.declaredVariables,
- FeatureSet featureSet)
- : _constantUpdate2018Enabled =
- featureSet.isEnabled(Feature.constant_update_2018),
- _intType = _typeProvider.intType,
+ this._errorReporter,
+ this._currentLibrary,
+ this._typeSystem,
+ this._typeProvider,
+ this.declaredVariables,
+ ) : _intType = _typeProvider.intType,
_evaluationEngine = ConstantEvaluationEngine(declaredVariables);
bool get _isNonNullableByDefault => _currentLibrary.isNonNullableByDefault;
@@ -704,10 +695,6 @@
verifier._errorReporter.reportErrorForNode(errorCode, element);
return false;
} else if (element is IfElement) {
- if (!verifier._constantUpdate2018Enabled) {
- verifier._errorReporter.reportErrorForNode(errorCode, element);
- return false;
- }
var conditionValue = verifier._validate(element.condition, errorCode);
var conditionBool = conditionValue?.toBoolValue();
@@ -735,10 +722,6 @@
} else if (element is MapLiteralEntry) {
return _validateMapLiteralEntry(element);
} else if (element is SpreadElement) {
- if (!verifier._constantUpdate2018Enabled) {
- verifier._errorReporter.reportErrorForNode(errorCode, element);
- return false;
- }
var value = verifier._validate(element.expression, errorCode);
if (value == null) return false;
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 8ca926c..329422d 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -5,7 +5,6 @@
import 'dart:collection';
import 'package:analyzer/dart/analysis/declared_variables.dart';
-import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/standard_ast_factory.dart';
import 'package:analyzer/dart/ast/token.dart';
@@ -979,10 +978,6 @@
/// Convenience getter to gain access to the [evaluationEngine]'s type system.
TypeSystemImpl get typeSystem => _library.typeSystem;
- bool get _isEnabledConstantUpdate2018 {
- return _library.featureSet.isEnabled(Feature.constant_update_2018);
- }
-
bool get _isNonNullableByDefault => typeSystem.isNonNullableByDefault;
/// Convenience getter to gain access to the [evaluationEngine]'s type
@@ -1005,14 +1000,9 @@
@override
DartObjectImpl visitAsExpression(AsExpression node) {
- if (_isEnabledConstantUpdate2018) {
- DartObjectImpl expressionResult = node.expression.accept(this);
- DartObjectImpl typeResult = node.type.accept(this);
- return _dartObjectComputer.castToType(node, expressionResult, typeResult);
- }
- // TODO(brianwilkerson) Figure out which error to report.
- _error(node, null);
- return null;
+ DartObjectImpl expressionResult = node.expression.accept(this);
+ DartObjectImpl typeResult = node.type.accept(this);
+ return _dartObjectComputer.castToType(node, expressionResult, typeResult);
}
@override
@@ -1027,33 +1017,21 @@
return _dartObjectComputer.lazyOr(
node, leftResult, () => node.rightOperand.accept(this));
} else if (operatorType == TokenType.QUESTION_QUESTION) {
- if (_isEnabledConstantUpdate2018) {
- return _dartObjectComputer.lazyQuestionQuestion(
- node, leftResult, () => node.rightOperand.accept(this));
- } else {
- return _dartObjectComputer.eagerQuestionQuestion(
- node, leftResult, node.rightOperand.accept(this));
- }
+ return _dartObjectComputer.lazyQuestionQuestion(
+ node, leftResult, () => node.rightOperand.accept(this));
}
// evaluate eager operators
DartObjectImpl rightResult = node.rightOperand.accept(this);
if (operatorType == TokenType.AMPERSAND) {
- return _dartObjectComputer.eagerAnd(
- node, leftResult, rightResult, _isEnabledConstantUpdate2018);
+ return _dartObjectComputer.eagerAnd(node, leftResult, rightResult);
} else if (operatorType == TokenType.BANG_EQ) {
return _dartObjectComputer.notEqual(node, leftResult, rightResult);
} else if (operatorType == TokenType.BAR) {
- return _dartObjectComputer.eagerOr(
- node, leftResult, rightResult, _isEnabledConstantUpdate2018);
+ return _dartObjectComputer.eagerOr(node, leftResult, rightResult);
} else if (operatorType == TokenType.CARET) {
- return _dartObjectComputer.eagerXor(
- node, leftResult, rightResult, _isEnabledConstantUpdate2018);
+ return _dartObjectComputer.eagerXor(node, leftResult, rightResult);
} else if (operatorType == TokenType.EQ_EQ) {
- if (_isEnabledConstantUpdate2018) {
- return _dartObjectComputer.lazyEqualEqual(
- node, leftResult, rightResult);
- }
- return _dartObjectComputer.equalEqual(node, leftResult, rightResult);
+ return _dartObjectComputer.lazyEqualEqual(node, leftResult, rightResult);
} else if (operatorType == TokenType.GT) {
return _dartObjectComputer.greaterThan(node, leftResult, rightResult);
} else if (operatorType == TokenType.GT_EQ) {
@@ -1102,44 +1080,13 @@
DartObjectImpl visitConditionalExpression(ConditionalExpression node) {
Expression condition = node.condition;
DartObjectImpl conditionResult = condition.accept(this);
- if (_isEnabledConstantUpdate2018) {
- if (conditionResult == null) {
- return conditionResult;
- } else if (!conditionResult.isBool) {
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, condition);
- return null;
- }
- conditionResult = _dartObjectComputer.applyBooleanConversion(
- condition, conditionResult);
- if (conditionResult == null) {
- return conditionResult;
- }
- if (conditionResult.toBoolValue() == true) {
- _reportNotPotentialConstants(node.elseExpression);
- return node.thenExpression.accept(this);
- } else if (conditionResult.toBoolValue() == false) {
- _reportNotPotentialConstants(node.thenExpression);
- return node.elseExpression.accept(this);
- }
- // We used to return an object with a known type and an unknown value, but
- // we can't do that without evaluating both the 'then' and 'else'
- // expressions, and we're not suppose to do that under lazy semantics. I'm
- // not sure which failure mode is worse.
- return null;
- }
- DartObjectImpl thenResult = node.thenExpression.accept(this);
- DartObjectImpl elseResult = node.elseExpression.accept(this);
+
if (conditionResult == null) {
return conditionResult;
} else if (!conditionResult.isBool) {
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, condition);
return null;
- } else if (thenResult == null) {
- return thenResult;
- } else if (elseResult == null) {
- return elseResult;
}
conditionResult =
_dartObjectComputer.applyBooleanConversion(condition, conditionResult);
@@ -1147,16 +1094,18 @@
return conditionResult;
}
if (conditionResult.toBoolValue() == true) {
- return thenResult;
+ _reportNotPotentialConstants(node.elseExpression);
+ return node.thenExpression.accept(this);
} else if (conditionResult.toBoolValue() == false) {
- return elseResult;
+ _reportNotPotentialConstants(node.thenExpression);
+ return node.elseExpression.accept(this);
}
- ParameterizedType thenType = thenResult.type;
- ParameterizedType elseType = elseResult.type;
- return DartObjectImpl.validWithUnknownValue(
- typeSystem,
- typeSystem.getLeastUpperBound(thenType, elseType) as ParameterizedType,
- );
+
+ // We used to return an object with a known type and an unknown value, but
+ // we can't do that without evaluating both the 'then' and 'else'
+ // expressions, and we're not suppose to do that under lazy semantics. I'm
+ // not sure which failure mode is worse.
+ return null;
}
@override
@@ -1224,14 +1173,9 @@
@override
DartObjectImpl visitIsExpression(IsExpression node) {
- if (_isEnabledConstantUpdate2018) {
- DartObjectImpl expressionResult = node.expression.accept(this);
- DartObjectImpl typeResult = node.type.accept(this);
- return _dartObjectComputer.typeTest(node, expressionResult, typeResult);
- }
- // TODO(brianwilkerson) Figure out which error to report.
- _error(node, null);
- return null;
+ DartObjectImpl expressionResult = node.expression.accept(this);
+ DartObjectImpl typeResult = node.type.accept(this);
+ return _dartObjectComputer.typeTest(node, expressionResult, typeResult);
}
@override
@@ -1839,10 +1783,10 @@
}
DartObjectImpl eagerAnd(BinaryExpression node, DartObjectImpl leftOperand,
- DartObjectImpl rightOperand, bool allowBool) {
+ DartObjectImpl rightOperand) {
if (leftOperand != null && rightOperand != null) {
try {
- return leftOperand.eagerAnd(_typeSystem, rightOperand, allowBool);
+ return leftOperand.eagerAnd(_typeSystem, rightOperand);
} on EvaluationException catch (exception) {
_errorReporter.reportErrorForNode(exception.errorCode, node);
}
@@ -1851,10 +1795,10 @@
}
DartObjectImpl eagerOr(BinaryExpression node, DartObjectImpl leftOperand,
- DartObjectImpl rightOperand, bool allowBool) {
+ DartObjectImpl rightOperand) {
if (leftOperand != null && rightOperand != null) {
try {
- return leftOperand.eagerOr(_typeSystem, rightOperand, allowBool);
+ return leftOperand.eagerOr(_typeSystem, rightOperand);
} on EvaluationException catch (exception) {
_errorReporter.reportErrorForNode(exception.errorCode, node);
}
@@ -1874,10 +1818,10 @@
}
DartObjectImpl eagerXor(BinaryExpression node, DartObjectImpl leftOperand,
- DartObjectImpl rightOperand, bool allowBool) {
+ DartObjectImpl rightOperand) {
if (leftOperand != null && rightOperand != null) {
try {
- return leftOperand.eagerXor(_typeSystem, rightOperand, allowBool);
+ return leftOperand.eagerXor(_typeSystem, rightOperand);
} on EvaluationException catch (exception) {
_errorReporter.reportErrorForNode(exception.errorCode, node);
}
diff --git a/pkg/analyzer/lib/src/dart/constant/value.dart b/pkg/analyzer/lib/src/dart/constant/value.dart
index ee72b09..af14481 100644
--- a/pkg/analyzer/lib/src/dart/constant/value.dart
+++ b/pkg/analyzer/lib/src/dart/constant/value.dart
@@ -327,8 +327,8 @@
/// Throws an [EvaluationException] if the operator is not appropriate for an
/// object of this kind.
DartObjectImpl eagerAnd(
- TypeSystemImpl typeSystem, DartObjectImpl rightOperand, bool allowBool) {
- if (allowBool && isBool && rightOperand.isBool) {
+ TypeSystemImpl typeSystem, DartObjectImpl rightOperand) {
+ if (isBool && rightOperand.isBool) {
return DartObjectImpl(
typeSystem,
typeSystem.typeProvider.boolType,
@@ -350,8 +350,8 @@
/// Throws an [EvaluationException] if the operator is not appropriate for an
/// object of this kind.
DartObjectImpl eagerOr(
- TypeSystemImpl typeSystem, DartObjectImpl rightOperand, bool allowBool) {
- if (allowBool && isBool && rightOperand.isBool) {
+ TypeSystemImpl typeSystem, DartObjectImpl rightOperand) {
+ if (isBool && rightOperand.isBool) {
return DartObjectImpl(
typeSystem,
typeSystem.typeProvider.boolType,
@@ -373,8 +373,8 @@
/// Throws an [EvaluationException] if the operator is not appropriate for an
/// object of this kind.
DartObjectImpl eagerXor(
- TypeSystemImpl typeSystem, DartObjectImpl rightOperand, bool allowBool) {
- if (allowBool && isBool && rightOperand.isBool) {
+ TypeSystemImpl typeSystem, DartObjectImpl rightOperand) {
+ if (isBool && rightOperand.isBool) {
return DartObjectImpl(
typeSystem,
typeSystem.typeProvider.boolType,
diff --git a/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart b/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
index 44ab5b5..12a7a75 100644
--- a/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
@@ -193,9 +193,8 @@
void _computeConstantErrors(
ErrorReporter errorReporter, CompilationUnit unit) {
- ConstantVerifier constantVerifier = ConstantVerifier(
- errorReporter, _libraryElement, _declaredVariables,
- featureSet: unit.featureSet);
+ ConstantVerifier constantVerifier =
+ ConstantVerifier(errorReporter, _libraryElement, _declaredVariables);
unit.accept(constantVerifier);
}
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index d28ca62..bf67b7b 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -469,7 +469,6 @@
errorReporter,
libraryElement,
declaredVariables,
- featureSet: currentUnit.unit.featureSet,
),
);
return listener.hasConstError;
diff --git a/pkg/analyzer/test/src/dart/constant/value_test.dart b/pkg/analyzer/test/src/dart/constant/value_test.dart
index 0a47069..df77b25 100644
--- a/pkg/analyzer/test/src/dart/constant/value_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/value_test.dart
@@ -261,6 +261,87 @@
_assertDivide(_doubleValue(null), _intValue(null), _intValue(2));
}
+ void test_eagerAnd_knownBool_knownBool() {
+ void check(bool left, bool right, bool expected) {
+ _assertEagerAnd(
+ _boolValue(expected),
+ _boolValue(left),
+ _boolValue(right),
+ );
+ }
+
+ check(false, false, false);
+ check(true, false, false);
+ check(false, true, false);
+ check(true, true, true);
+ }
+
+ void test_eagerAnd_knownBool_knownInt() {
+ _assertEagerAnd(null, _boolValue(true), _intValue(0));
+ }
+
+ void test_eagerAnd_knownBool_unknownBool() {
+ _assertEagerAnd(_boolValue(null), _boolValue(true), _boolValue(null));
+ }
+
+ void test_eagerAnd_unknownBool_knownBool() {
+ _assertEagerAnd(_boolValue(null), _boolValue(null), _boolValue(true));
+ }
+
+ void test_eagerOr_knownBool_knownBool() {
+ void check(bool left, bool right, bool expected) {
+ _assertEagerOr(
+ _boolValue(expected),
+ _boolValue(left),
+ _boolValue(right),
+ );
+ }
+
+ check(false, false, false);
+ check(true, false, true);
+ check(false, true, true);
+ check(true, true, true);
+ }
+
+ void test_eagerOr_knownBool_knownInt() {
+ _assertEagerOr(null, _boolValue(true), _intValue(0));
+ }
+
+ void test_eagerOr_knownBool_unknownBool() {
+ _assertEagerOr(_boolValue(null), _boolValue(true), _boolValue(null));
+ }
+
+ void test_eagerOr_unknownBool_knownBool() {
+ _assertEagerOr(_boolValue(null), _boolValue(null), _boolValue(true));
+ }
+
+ void test_eagerXor_knownBool_knownBool() {
+ void check(bool left, bool right, bool expected) {
+ _assertEagerXor(
+ _boolValue(expected),
+ _boolValue(left),
+ _boolValue(right),
+ );
+ }
+
+ check(false, false, false);
+ check(true, false, true);
+ check(false, true, true);
+ check(true, true, false);
+ }
+
+ void test_eagerXor_knownBool_knownInt() {
+ _assertEagerXor(null, _boolValue(true), _intValue(0));
+ }
+
+ void test_eagerXor_knownBool_unknownBool() {
+ _assertEagerXor(_boolValue(null), _boolValue(true), _boolValue(null));
+ }
+
+ void test_eagerXor_unknownBool_knownBool() {
+ _assertEagerXor(_boolValue(null), _boolValue(null), _boolValue(true));
+ }
+
void test_equalEqual_bool_false() {
_assertEqualEqual(_boolValue(false), _boolValue(false), _boolValue(true));
}
@@ -1716,10 +1797,10 @@
DartObjectImpl expected, DartObjectImpl left, DartObjectImpl right) {
if (expected == null) {
expect(() {
- left.eagerAnd(_typeSystem, right, false);
+ left.eagerAnd(_typeSystem, right);
}, throwsEvaluationException);
} else {
- DartObjectImpl result = left.eagerAnd(_typeSystem, right, false);
+ DartObjectImpl result = left.eagerAnd(_typeSystem, right);
expect(result, isNotNull);
expect(result, expected);
}
@@ -1732,10 +1813,10 @@
DartObjectImpl expected, DartObjectImpl left, DartObjectImpl right) {
if (expected == null) {
expect(() {
- left.eagerOr(_typeSystem, right, false);
+ left.eagerOr(_typeSystem, right);
}, throwsEvaluationException);
} else {
- DartObjectImpl result = left.eagerOr(_typeSystem, right, false);
+ DartObjectImpl result = left.eagerOr(_typeSystem, right);
expect(result, isNotNull);
expect(result, expected);
}
@@ -1748,10 +1829,10 @@
DartObjectImpl expected, DartObjectImpl left, DartObjectImpl right) {
if (expected == null) {
expect(() {
- left.eagerXor(_typeSystem, right, false);
+ left.eagerXor(_typeSystem, right);
}, throwsEvaluationException);
} else {
- DartObjectImpl result = left.eagerXor(_typeSystem, right, false);
+ DartObjectImpl result = left.eagerXor(_typeSystem, right);
expect(result, isNotNull);
expect(result, expected);
}
diff --git a/runtime/tests/vm/dart/regress_37382_test.dart b/runtime/tests/vm/dart/regress_37382_test.dart
index e0d818c..0a25345 100644
--- a/runtime/tests/vm/dart/regress_37382_test.dart
+++ b/runtime/tests/vm/dart/regress_37382_test.dart
@@ -4,11 +4,23 @@
import 'package:expect/expect.dart';
+void expectType(Type type, Pattern text) {
+ var typeString = "$type";
+ if (typeString.contains("minified:")) {
+ return; // No checks for minimized types.
+ }
+ var match = text.matchAsPrefix(typeString);
+ if (match != null && match.end == typeString.length) return;
+ Expect.fail(
+ "$typeString was not matched by $text${match == null ? "" : ", match: ${match[0]}"}");
+}
+
class A<X, Y> {
R f<R>(R Function<S, T>(A<S, T>) t) => t<X, Y>(this);
}
main() {
A<num, num> a = A<int, int>();
- Expect.equals(a.f.runtimeType.toString(), '<R>(<S, T>(A<S, T>) => R) => R');
+ expectType(a.f.runtimeType,
+ RegExp(r"<(\w+)>\(<(\w+), (\w+)>\(A<\2, \3>\) => \1\) => \1$"));
}
diff --git a/runtime/tests/vm/dart_2/regress_37382_test.dart b/runtime/tests/vm/dart_2/regress_37382_test.dart
index e0d818c..0a25345 100644
--- a/runtime/tests/vm/dart_2/regress_37382_test.dart
+++ b/runtime/tests/vm/dart_2/regress_37382_test.dart
@@ -4,11 +4,23 @@
import 'package:expect/expect.dart';
+void expectType(Type type, Pattern text) {
+ var typeString = "$type";
+ if (typeString.contains("minified:")) {
+ return; // No checks for minimized types.
+ }
+ var match = text.matchAsPrefix(typeString);
+ if (match != null && match.end == typeString.length) return;
+ Expect.fail(
+ "$typeString was not matched by $text${match == null ? "" : ", match: ${match[0]}"}");
+}
+
class A<X, Y> {
R f<R>(R Function<S, T>(A<S, T>) t) => t<X, Y>(this);
}
main() {
A<num, num> a = A<int, int>();
- Expect.equals(a.f.runtimeType.toString(), '<R>(<S, T>(A<S, T>) => R) => R');
+ expectType(a.f.runtimeType,
+ RegExp(r"<(\w+)>\(<(\w+), (\w+)>\(A<\2, \3>\) => \1\) => \1$"));
}
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index e8fdaa4..c59eb92 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -3134,6 +3134,8 @@
Class& klass = Class::ZoneHandle(
Z, H.LookupClassByKernelClass(H.EnclosingName(kernel_name)));
+ const auto& error = klass.EnsureIsFinalized(H.thread());
+ ASSERT(error == Error::null());
Fragment instructions;
diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.cc b/runtime/vm/compiler/frontend/kernel_translation_helper.cc
index ae03f6e..c3c6bc6 100644
--- a/runtime/vm/compiler/frontend/kernel_translation_helper.cc
+++ b/runtime/vm/compiler/frontend/kernel_translation_helper.cc
@@ -3348,12 +3348,18 @@
const Library& lib = Library::Handle(Z, active_class->klass->library());
{
AlternativeReadingScope alt(&helper_->reader_);
+ String& name = String::Handle(Z);
for (intptr_t i = 0; i < type_parameter_count; i++) {
TypeParameterHelper helper(helper_);
helper.Finish();
+ if (parameterized_class.IsNull() && function.IsNull()) {
+ // Erase provided name and use a canonical one instead.
+ name = Symbols::NewFormatted(H.thread(), "X%" Pd, offset + i);
+ } else {
+ name = H.DartIdentifier(lib, helper.name_index_).raw();
+ }
parameter = TypeParameter::New(
- parameterized_class, offset, offset + i,
- H.DartIdentifier(lib, helper.name_index_), null_bound,
+ parameterized_class, offset, offset + i, name, null_bound,
helper.IsGenericCovariantImpl(), nullability);
type_parameters.SetTypeAt(i, parameter);
}
diff --git a/runtime/vm/cpu_arm64.cc b/runtime/vm/cpu_arm64.cc
index 0d6b8b3..df0f48b 100644
--- a/runtime/vm/cpu_arm64.cc
+++ b/runtime/vm/cpu_arm64.cc
@@ -20,7 +20,7 @@
#include <unistd.h>
#endif
-#if defined(HOST_OS_IOS)
+#if defined(HOST_OS_MACOS) || defined(HOST_OS_IOS)
#include <libkern/OSCacheControl.h>
#endif
@@ -42,7 +42,7 @@
// On iOS we use sys_icache_invalidate from Darwin. See:
//
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sys_icache_invalidate.3.html
-#if defined(HOST_OS_IOS)
+#if defined(HOST_OS_MACOS) || defined(HOST_OS_IOS)
sys_icache_invalidate(reinterpret_cast<void*>(start), size);
#elif defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX)
extern void __clear_cache(char*, char*);
@@ -54,7 +54,7 @@
size, ZX_CACHE_FLUSH_INSN);
ASSERT(result == ZX_OK);
#else
-#error FlushICache only tested/supported on Android, Fuchsia, Linux and iOS
+#error FlushICache not implemented for this OS
#endif
#endif
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 129d71f..cea08ae 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -5423,6 +5423,7 @@
ASSERT(!IsNull());
Thread* thread = Thread::Current();
RELEASE_ASSERT(is_finalized());
+ SafepointReadRwLocker ml(thread, thread->isolate_group()->program_lock());
REUSABLE_ARRAY_HANDLESCOPE(thread);
REUSABLE_FUNCTION_HANDLESCOPE(thread);
REUSABLE_STRING_HANDLESCOPE(thread);
diff --git a/runtime/vm/simulator_arm64.cc b/runtime/vm/simulator_arm64.cc
index 1e3c5f6..a055948 100644
--- a/runtime/vm/simulator_arm64.cc
+++ b/runtime/vm/simulator_arm64.cc
@@ -598,7 +598,8 @@
if (IsolateGroup::Current()->heap()->Contains(value)) {
OS::PrintErr("%s: \n", arg1);
#if defined(DEBUG)
- const Object& obj = Object::Handle(static_cast<ObjectPtr>(value));
+ const Object& obj = Object::Handle(
+ static_cast<ObjectPtr>(static_cast<uword>(value)));
obj.Print();
#endif // defined(DEBUG)
} else {
diff --git a/tools/VERSION b/tools/VERSION
index f98a1fa..3cd2a88 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 12
PATCH 0
-PRERELEASE 225
+PRERELEASE 226
PRERELEASE_PATCH 0
\ No newline at end of file