CQ. Remove result state from ResolutionTest.
Stop storing the most recently resolved unit in ResolutionTest. Make test helpers operate on explicit result objects instead, so each assertion uses the diagnostics, type provider, type system, and inheritance manager from the result it is checking. This makes the tests less order-dependent and easier to reason about. A test can now resolve more than one file or unit without later assertions implicitly depending on whichever result happened to be stored last. It also makes helper APIs more local: the data needed by an assertion is passed directly, rather than recovered from mutable test state. Update tests to keep the returned result when they need access to the resolved AST or result-derived utilities. Add convenience accessors on the result wrappers to preserve common lookup patterns without reintroducing shared mutable state. Change-Id: Ib45c52f8fd104b668f9fdd1ec6b1442927cd7e61 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505920 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
739826d041
commit
fc7c531253
@@ -473,7 +473,7 @@ class B {
|
||||
|
||||
Future<TestResolvedUnitResult> _assertCanBeAnalyzed(String text) async {
|
||||
var result = await resolveTestCode(text);
|
||||
assertHasTestErrors();
|
||||
assertHasTestErrors(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,7 +687,7 @@ void testNewSet(Set<C> setEls) {
|
||||
}
|
||||
|
||||
test_class_type_alias_documentationComment() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
/**
|
||||
* Documentation
|
||||
*/
|
||||
@@ -2079,7 +2079,7 @@ f(S s) async {
|
||||
}
|
||||
|
||||
test_issue_32394() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
var x = y.map((a) => a.toString());
|
||||
var y = [3];
|
||||
var z = x.toList();
|
||||
@@ -2770,7 +2770,7 @@ class B {
|
||||
final Bounded? bounded;
|
||||
}
|
||||
''');
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'b.dart';
|
||||
|
||||
@B.named1()
|
||||
|
||||
@@ -209,7 +209,7 @@ import 'package:somepackage/other.dart';
|
||||
List<ExpectedDiagnostic> expectedDiagnostics,
|
||||
) async {
|
||||
var file = newFile(path, content);
|
||||
result = await resolveFile(file);
|
||||
var result = await resolveFile(file);
|
||||
|
||||
var diagnosticListener = GatheringDiagnosticListener();
|
||||
diagnosticListener.addAll(result.diagnostics);
|
||||
|
||||
@@ -448,7 +448,7 @@ void f() {
|
||||
main() {}
|
||||
''');
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
export 'a.dart';
|
||||
''');
|
||||
|
||||
@@ -460,7 +460,7 @@ export 'a.dart';
|
||||
}
|
||||
|
||||
test_entryPoint_local() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
main() {}
|
||||
''');
|
||||
|
||||
@@ -472,7 +472,7 @@ main() {}
|
||||
}
|
||||
|
||||
test_entryPoint_none() async {
|
||||
await resolveTestCodeWithDiagnostics('');
|
||||
var result = await resolveTestCodeWithDiagnostics('');
|
||||
|
||||
var library = result.libraryElement;
|
||||
expect(library.entryPoint, isNull);
|
||||
@@ -1071,7 +1071,7 @@ Annotation
|
||||
}
|
||||
|
||||
test_metadata_libraryDirective() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
@A library lib;
|
||||
const A = null;''');
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ test() => 'a' 'b';
|
||||
''');
|
||||
expect(
|
||||
result.findNode.adjacentStrings("'a' 'b'").staticType,
|
||||
same(typeProvider.stringType),
|
||||
same(result.typeProvider.stringType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ late B b;
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
test(Future<Future<int>> e) async => await e;
|
||||
''');
|
||||
InterfaceType futureIntType = typeProvider.futureType(typeProvider.intType);
|
||||
InterfaceType futureIntType = result.typeProvider.futureType(
|
||||
result.typeProvider.intType,
|
||||
);
|
||||
expect(
|
||||
result.findNode.awaitExpression('await e').staticType,
|
||||
futureIntType,
|
||||
@@ -56,7 +58,7 @@ test(Future<Future<int>> e) async => await e;
|
||||
test(Future<int> e) async => await e;
|
||||
''');
|
||||
// await e, where e has type Future<int>
|
||||
InterfaceType intType = typeProvider.intType;
|
||||
InterfaceType intType = result.typeProvider.intType;
|
||||
expect(result.findNode.awaitExpression('await e').staticType, intType);
|
||||
}
|
||||
|
||||
@@ -66,7 +68,7 @@ test() => false;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.booleanLiteral('false').staticType,
|
||||
same(typeProvider.boolType),
|
||||
same(result.typeProvider.boolType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,7 +78,7 @@ test() => true;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.booleanLiteral('true').staticType,
|
||||
same(typeProvider.boolType),
|
||||
same(result.typeProvider.boolType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,7 +88,7 @@ test(String a) => a..length;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.cascade('a..length').staticType,
|
||||
typeProvider.stringType,
|
||||
result.typeProvider.stringType,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -96,7 +98,7 @@ test(bool b) => b ? 1.0 : 0;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.conditionalExpression('b ? 1.0 : 0').staticType,
|
||||
typeProvider.numType,
|
||||
result.typeProvider.numType,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ test(bool b) => b ? 1 : 0;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.conditionalExpression('b ? 1 : 0').staticType,
|
||||
same(typeProvider.intType),
|
||||
same(result.typeProvider.intType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ test() => 4.33;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.doubleLiteral('4.33').staticType,
|
||||
same(typeProvider.doubleType),
|
||||
same(result.typeProvider.doubleType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -163,7 +165,7 @@ late C c;
|
||||
test() => 42;
|
||||
''');
|
||||
var node = result.findNode.integerLiteral('42');
|
||||
expect(node.staticType, same(typeProvider.intType));
|
||||
expect(node.staticType, same(result.typeProvider.intType));
|
||||
}
|
||||
|
||||
test_visitIsExpression_negated() async {
|
||||
@@ -172,7 +174,7 @@ test(Object a) => a is! String;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.isExpression('a is! String').staticType,
|
||||
same(typeProvider.boolType),
|
||||
same(result.typeProvider.boolType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,7 +184,7 @@ test(Object a) => a is String;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.isExpression('a is String').staticType,
|
||||
same(typeProvider.boolType),
|
||||
same(result.typeProvider.boolType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,7 +201,7 @@ test() => null;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.nullLiteral('null').staticType,
|
||||
same(typeProvider.nullType),
|
||||
same(result.typeProvider.nullType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -209,7 +211,7 @@ test() => (0);
|
||||
''');
|
||||
expect(
|
||||
result.findNode.parenthesized('(0)').staticType,
|
||||
same(typeProvider.intType),
|
||||
same(result.typeProvider.intType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -219,7 +221,7 @@ test() => 'a';
|
||||
''');
|
||||
expect(
|
||||
result.findNode.stringLiteral("'a'").staticType,
|
||||
same(typeProvider.stringType),
|
||||
same(result.typeProvider.stringType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,7 +231,7 @@ test() => "a${'b'}c";
|
||||
''');
|
||||
expect(
|
||||
result.findNode.stringInterpolation(r'''"a${'b'}c"''').staticType,
|
||||
same(typeProvider.stringType),
|
||||
same(result.typeProvider.stringType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -253,7 +255,7 @@ test() => #a;
|
||||
''');
|
||||
expect(
|
||||
result.findNode.symbolLiteral('#a').staticType,
|
||||
same(typeProvider.symbolType),
|
||||
same(result.typeProvider.symbolType),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -274,6 +276,6 @@ late B b;
|
||||
test() => throw 0;
|
||||
''');
|
||||
var node = result.findNode.throw_('throw 0');
|
||||
expect(node.staticType, same(typeProvider.bottomType));
|
||||
expect(node.staticType, same(result.typeProvider.bottomType));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -311,8 +311,8 @@ void f() {
|
||||
''');
|
||||
|
||||
// We don't have any lints configured, so no errors.
|
||||
await resolveTestFile();
|
||||
assertErrorsInResult([]);
|
||||
var result = await resolveTestFile();
|
||||
assertErrorsInTestResult(result, []);
|
||||
|
||||
// The summary for the library was linked.
|
||||
_assertContainsLinkedCycle({testFile}, andClear: true);
|
||||
@@ -327,7 +327,7 @@ void f() {
|
||||
);
|
||||
|
||||
// Check that the lint was run, and reported.
|
||||
await resolveTestFile();
|
||||
result = await resolveTestFile();
|
||||
_assertHasLintReported(result.diagnostics, 'prefer_is_not_empty');
|
||||
|
||||
// Lints don't affect summaries, nothing should be linked.
|
||||
|
||||
@@ -33,7 +33,6 @@ import '../../../util/diff.dart';
|
||||
import '../../../util/element_printer.dart';
|
||||
import '../resolution/context_collection_resolution.dart';
|
||||
import '../resolution/node_text_expectations.dart';
|
||||
import '../resolution/resolution.dart';
|
||||
import 'result_printer.dart';
|
||||
|
||||
void main() {
|
||||
@@ -119,7 +118,7 @@ class AnalysisDriver_LintTest extends PubPackageResolutionTest
|
||||
|
||||
test_getResolvedUnit_lint_existingFile() async {
|
||||
addTestFile('');
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
|
||||
// Existing/empty file triggers the lint.
|
||||
_assertHasLintReported(
|
||||
@@ -129,10 +128,10 @@ class AnalysisDriver_LintTest extends PubPackageResolutionTest
|
||||
}
|
||||
|
||||
test_getResolvedUnit_lint_notExistingFile() async {
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
|
||||
// No errors for a file that doesn't exist.
|
||||
assertErrorsInResult([]);
|
||||
assertErrorsInTestResult(result, []);
|
||||
}
|
||||
|
||||
void _assertHasLintReported(List<Diagnostic> diagnostics, String name) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,7 +45,7 @@ class A {} // 2
|
||||
expect(node.namePart.typeName.lexeme, 'A');
|
||||
expect(
|
||||
node.namePart.typeName.offset,
|
||||
this.result.content.indexOf('A {} // 1'),
|
||||
unitResult.content.indexOf('A {} // 1'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class A {} // 2
|
||||
expect(node.namePart.typeName.lexeme, 'A');
|
||||
expect(
|
||||
node.namePart.typeName.offset,
|
||||
this.result.content.indexOf('A {} // 2'),
|
||||
unitResult.content.indexOf('A {} // 2'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class A {
|
||||
var result = await getFragmentDeclaration(element);
|
||||
var node = result!.node as ConstructorDeclaration;
|
||||
expect(node.name!.lexeme, 'named');
|
||||
expect(node.name!.offset, this.result.content.indexOf('named(); // 1'));
|
||||
expect(node.name!.offset, unitResult.content.indexOf('named(); // 1'));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -147,7 +147,7 @@ class A {
|
||||
var result = await getFragmentDeclaration(element);
|
||||
var node = result!.node as ConstructorDeclaration;
|
||||
expect(node.name!.lexeme, 'named');
|
||||
expect(node.name!.offset, this.result.content.indexOf('named(); // 2'));
|
||||
expect(node.name!.offset, unitResult.content.indexOf('named(); // 2'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ class A {
|
||||
var result = await getFragmentDeclaration(element);
|
||||
var node = result!.node as ConstructorDeclaration;
|
||||
expect(node.name, isNull);
|
||||
expect(node.typeName!.offset, this.result.content.indexOf('A(); // 1'));
|
||||
expect(node.typeName!.offset, unitResult.content.indexOf('A(); // 1'));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -175,7 +175,7 @@ class A {
|
||||
var result = await getFragmentDeclaration(element);
|
||||
var node = result!.node as ConstructorDeclaration;
|
||||
expect(node.name, isNull);
|
||||
expect(node.typeName!.offset, this.result.content.indexOf('A(); // 2'));
|
||||
expect(node.typeName!.offset, unitResult.content.indexOf('A(); // 2'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,8 +338,8 @@ int get x => 0;
|
||||
}
|
||||
|
||||
test_libraryFragment() async {
|
||||
await resolveTestCode('');
|
||||
var fragment = this.result.libraryFragment;
|
||||
var unitResult = await resolveTestCode('');
|
||||
var fragment = unitResult.libraryFragment;
|
||||
var result = await getFragmentDeclaration(fragment);
|
||||
expect(result, isNull);
|
||||
}
|
||||
|
||||
@@ -999,11 +999,11 @@ class B_q extends p.A {}
|
||||
}
|
||||
|
||||
test_scenario_ClassElement_hierarchy_class_extends_implicitObject() async {
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
class A {}
|
||||
''');
|
||||
includedLibraryUris = {Uri.parse(testUriStr)};
|
||||
var element = typeProvider.objectType.element;
|
||||
var element = result.typeProvider.objectType.element;
|
||||
await assertElementReferencesText(element, r'''''');
|
||||
await assertSubTypesText(element, '');
|
||||
}
|
||||
@@ -2389,7 +2389,7 @@ package:test/other.dart useConstructor@66
|
||||
}
|
||||
|
||||
test_searchReferences_ConstructorElement_classTypeAlias_cycle() async {
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
class M {}
|
||||
class A = B with M;
|
||||
class B = A with M;
|
||||
@@ -3344,7 +3344,7 @@ void useField(E e) {
|
||||
}
|
||||
|
||||
test_searchReferences_FieldElement_ofEnum_instance_index() async {
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
enum MyEnum {
|
||||
v1, v2, v3
|
||||
}
|
||||
@@ -3355,7 +3355,7 @@ main() {
|
||||
MyEnum.v2;
|
||||
}
|
||||
''');
|
||||
var index = typeProvider.enumElement!.getField('index')!;
|
||||
var index = result.typeProvider.enumElement!.getField('index')!;
|
||||
await assertElementReferencesText(index, r'''
|
||||
<testLibraryFragment> main@29
|
||||
50 5:13 |index| READ qualified
|
||||
@@ -4764,7 +4764,7 @@ label:
|
||||
|
||||
fileForContextSelection = testFile;
|
||||
|
||||
await resolveFileCode(libPath, '''
|
||||
var result = await resolveFileCode(libPath, '''
|
||||
library lib;
|
||||
part 'unitA.dart';
|
||||
part 'unitB.dart';
|
||||
@@ -4781,7 +4781,7 @@ part 'unitB.dart';
|
||||
test_searchReferences_LibraryElement_partOfName() async {
|
||||
newFile('$testPackageLibPath/unitA.dart', 'part of lib;');
|
||||
newFile('$testPackageLibPath/unitB.dart', 'part of lib;');
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
library lib;
|
||||
part 'unitA.dart';
|
||||
part 'unitB.dart';
|
||||
@@ -4804,7 +4804,7 @@ part of 'test.dart';
|
||||
part of 'test.dart';
|
||||
''');
|
||||
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
part 'unitA.dart';
|
||||
part 'unitB.dart';
|
||||
''');
|
||||
@@ -7353,7 +7353,7 @@ class NoMatchABCDEF {}
|
||||
}
|
||||
|
||||
String _getSearchResultsText(List<SearchResult> results) {
|
||||
var analysisSession = result.session;
|
||||
var analysisSession = driver.currentSession;
|
||||
|
||||
var groups = results
|
||||
.groupListsBy((result) => result.enclosingFragment)
|
||||
@@ -7423,7 +7423,7 @@ class NoMatchABCDEF {}
|
||||
}
|
||||
|
||||
String _getSearchResultsText2(List<LibraryFragmentSearchMatch> results) {
|
||||
var analysisSession = result.session;
|
||||
var analysisSession = driver.currentSession;
|
||||
|
||||
var groups = results
|
||||
.groupListsBy((result) => result.libraryFragment)
|
||||
|
||||
@@ -1343,7 +1343,7 @@ class IntegerLiteralImplTest {
|
||||
@reflectiveTest
|
||||
class NodeCoveringTest extends PubPackageResolutionTest {
|
||||
Future<AstNode> coveringNode(String sourceCode) async {
|
||||
var range = await _range(sourceCode);
|
||||
var (result, range) = await _range(sourceCode);
|
||||
var node = result.unit.nodeCovering(
|
||||
offset: range.offset,
|
||||
length: range.length,
|
||||
@@ -1352,7 +1352,7 @@ class NodeCoveringTest extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
void test_after_EOF() async {
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
library myLib;
|
||||
''');
|
||||
var node = result.unit.nodeCovering(offset: 100, length: 20);
|
||||
@@ -1747,7 +1747,9 @@ class C { void call() {} } Function f = C^();
|
||||
node as NamedType;
|
||||
}
|
||||
|
||||
Future<SourceRange> _range(String sourceCode) async {
|
||||
Future<(TestResolvedUnitResult, SourceRange)> _range(
|
||||
String sourceCode,
|
||||
) async {
|
||||
// TODO(brianwilkerson): Move TestCode to the analyzer package and make use
|
||||
// of it here.
|
||||
var offset = sourceCode.indexOf('^');
|
||||
@@ -1756,7 +1758,7 @@ class C { void call() {} } Function f = C^();
|
||||
}
|
||||
var testCode =
|
||||
sourceCode.substring(0, offset) + sourceCode.substring(offset + 1);
|
||||
await resolveTestCode(testCode);
|
||||
return SourceRange(offset, 0);
|
||||
var result = await resolveTestCode(testCode);
|
||||
return (result, SourceRange(offset, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_locate_LibraryElement() async {
|
||||
await resolveTestCode('// only comment');
|
||||
var result = await resolveTestCode('// only comment');
|
||||
|
||||
var element = ElementLocator.locate(result.unit);
|
||||
_assertElement(element, r'''
|
||||
|
||||
@@ -3878,7 +3878,7 @@ const v2 = -v1;
|
||||
String name,
|
||||
) {
|
||||
var value = _evaluateConstant(unitResult, name);
|
||||
var featureSet = result.libraryElement.featureSet;
|
||||
var featureSet = unitResult.libraryElement.featureSet;
|
||||
var has = value.hasPrimitiveEquality(featureSet);
|
||||
expect(has, isFalse);
|
||||
}
|
||||
@@ -3888,7 +3888,7 @@ const v2 = -v1;
|
||||
String name,
|
||||
) {
|
||||
var value = _evaluateConstant(unitResult, name);
|
||||
var featureSet = result.libraryElement.featureSet;
|
||||
var featureSet = unitResult.libraryElement.featureSet;
|
||||
var has = value.hasPrimitiveEquality(featureSet);
|
||||
expect(has, isTrue);
|
||||
}
|
||||
@@ -3901,7 +3901,10 @@ mixin ConstantVisitorTestCases on ConstantVisitorTestSupport {
|
||||
const c = [1, if (1 < 0) 2 else 3, 4];
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.listType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.listType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toListValue()!.map((e) => e.toIntValue()), [1, 3, 4]);
|
||||
}
|
||||
|
||||
@@ -3910,7 +3913,10 @@ const c = [1, if (1 < 0) 2 else 3, 4];
|
||||
const c = [1, if (1 < 0) 2, 3];
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.listType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.listType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toListValue()!.map((e) => e.toIntValue()), [1, 3]);
|
||||
}
|
||||
|
||||
@@ -3919,7 +3925,10 @@ const c = [1, if (1 < 0) 2, 3];
|
||||
const c = [1, if (1 > 0) 2 else 3, 4];
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.listType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.listType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toListValue()!.map((e) => e.toIntValue()), [1, 2, 4]);
|
||||
}
|
||||
|
||||
@@ -3928,7 +3937,10 @@ const c = [1, if (1 > 0) 2 else 3, 4];
|
||||
const c = [1, if (1 > 0) 2, 3];
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.listType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.listType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toListValue()!.map((e) => e.toIntValue()), [1, 2, 3]);
|
||||
}
|
||||
|
||||
@@ -3939,7 +3951,10 @@ const c = [1, if (1 > 0) if (2 > 1) 2, 3];
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
// The expected type ought to be `List<int>`, but type inference isn't yet
|
||||
// implemented.
|
||||
expect(result.type, typeProvider.listType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.listType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toListValue()!.map((e) => e.toIntValue()), [1, 2, 3]);
|
||||
}
|
||||
|
||||
@@ -3948,7 +3963,10 @@ const c = [1, if (1 > 0) if (2 > 1) 2, 3];
|
||||
const c = [1, ...[2, 3], 4];
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.listType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.listType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toListValue()!.map((e) => e.toIntValue()), [1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
@@ -3959,7 +3977,10 @@ const c = {'a' : 1, if (1 < 0) 'b' : 2 else 'c' : 3, 'd' : 4};
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(
|
||||
result.type,
|
||||
typeProvider.mapType(typeProvider.stringType, typeProvider.intType),
|
||||
unitResult.typeProvider.mapType(
|
||||
unitResult.typeProvider.stringType,
|
||||
unitResult.typeProvider.intType,
|
||||
),
|
||||
);
|
||||
Map<DartObject, DartObject> value = result.toMapValue()!;
|
||||
expect(
|
||||
@@ -3976,7 +3997,10 @@ const c = {'a' : 1, if (1 < 0) 'b' : 2, 'c' : 3};
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(
|
||||
result.type,
|
||||
typeProvider.mapType(typeProvider.stringType, typeProvider.intType),
|
||||
unitResult.typeProvider.mapType(
|
||||
unitResult.typeProvider.stringType,
|
||||
unitResult.typeProvider.intType,
|
||||
),
|
||||
);
|
||||
Map<DartObject, DartObject> value = result.toMapValue()!;
|
||||
expect(
|
||||
@@ -3993,7 +4017,10 @@ const c = {'a' : 1, if (1 > 0) 'b' : 2 else 'c' : 3, 'd' : 4};
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(
|
||||
result.type,
|
||||
typeProvider.mapType(typeProvider.stringType, typeProvider.intType),
|
||||
unitResult.typeProvider.mapType(
|
||||
unitResult.typeProvider.stringType,
|
||||
unitResult.typeProvider.intType,
|
||||
),
|
||||
);
|
||||
Map<DartObject, DartObject> value = result.toMapValue()!;
|
||||
expect(
|
||||
@@ -4010,7 +4037,10 @@ const c = {'a' : 1, if (1 > 0) 'b' : 2, 'c' : 3};
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(
|
||||
result.type,
|
||||
typeProvider.mapType(typeProvider.stringType, typeProvider.intType),
|
||||
unitResult.typeProvider.mapType(
|
||||
unitResult.typeProvider.stringType,
|
||||
unitResult.typeProvider.intType,
|
||||
),
|
||||
);
|
||||
Map<DartObject, DartObject> value = result.toMapValue()!;
|
||||
expect(
|
||||
@@ -4029,7 +4059,10 @@ const c = {'a' : 1, if (1 > 0) if (2 > 1) {'b' : 2}, 'c' : 3};
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(
|
||||
result.type,
|
||||
typeProvider.mapType(typeProvider.intType, typeProvider.intType),
|
||||
unitResult.typeProvider.mapType(
|
||||
unitResult.typeProvider.intType,
|
||||
unitResult.typeProvider.intType,
|
||||
),
|
||||
);
|
||||
Map<DartObject, DartObject> value = result.toMapValue()!;
|
||||
expect(
|
||||
@@ -4046,7 +4079,10 @@ const c = {'a' : 1, ...{'b' : 2, 'c' : 3}, 'd' : 4};
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(
|
||||
result.type,
|
||||
typeProvider.mapType(typeProvider.stringType, typeProvider.intType),
|
||||
unitResult.typeProvider.mapType(
|
||||
unitResult.typeProvider.stringType,
|
||||
unitResult.typeProvider.intType,
|
||||
),
|
||||
);
|
||||
Map<DartObject, DartObject> value = result.toMapValue()!;
|
||||
expect(
|
||||
@@ -4064,7 +4100,10 @@ const c = {'a' : 1, ...{'b' : 2, 'c' : 3}, 'd' : 4};
|
||||
const c = {1, if (1 < 0) 2 else 3, 4};
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.setType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.setType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toSetValue()!.map((e) => e.toIntValue()), [1, 3, 4]);
|
||||
}
|
||||
|
||||
@@ -4073,7 +4112,10 @@ const c = {1, if (1 < 0) 2 else 3, 4};
|
||||
const c = {1, if (1 < 0) 2, 3};
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.setType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.setType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toSetValue()!.map((e) => e.toIntValue()), [1, 3]);
|
||||
}
|
||||
|
||||
@@ -4082,7 +4124,10 @@ const c = {1, if (1 < 0) 2, 3};
|
||||
const c = {1, if (1 > 0) 2 else 3, 4};
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.setType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.setType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toSetValue()!.map((e) => e.toIntValue()), [1, 2, 4]);
|
||||
}
|
||||
|
||||
@@ -4091,7 +4136,10 @@ const c = {1, if (1 > 0) 2 else 3, 4};
|
||||
const c = {1, if (1 > 0) 2, 3};
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.setType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.setType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toSetValue()!.map((e) => e.toIntValue()), [1, 2, 3]);
|
||||
}
|
||||
|
||||
@@ -4100,7 +4148,10 @@ const c = {1, if (1 > 0) 2, 3};
|
||||
const c = {1, if (1 > 0) if (2 > 1) 2, 3};
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.setType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.setType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toSetValue()!.map((e) => e.toIntValue()), [1, 2, 3]);
|
||||
}
|
||||
|
||||
@@ -4109,7 +4160,10 @@ const c = {1, if (1 > 0) if (2 > 1) 2, 3};
|
||||
const c = {1, ...{2, 3}, 4};
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.setType(typeProvider.intType));
|
||||
expect(
|
||||
result.type,
|
||||
unitResult.typeProvider.setType(unitResult.typeProvider.intType),
|
||||
);
|
||||
expect(result.toSetValue()!.map((e) => e.toIntValue()), [1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
@@ -4293,7 +4347,7 @@ const c = a && true;
|
||||
const c = false & true;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_and_bool_known_unknown() async {
|
||||
@@ -4302,7 +4356,7 @@ const b = bool.fromEnvironment('y');
|
||||
const c = false & b;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_and_bool_true_invalid() async {
|
||||
@@ -4320,7 +4374,7 @@ const a = bool.fromEnvironment('x');
|
||||
const c = a & true;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_and_bool_unknown_unknown() async {
|
||||
@@ -4330,7 +4384,7 @@ const b = bool.fromEnvironment('y');
|
||||
const c = a & b;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_and_int() async {
|
||||
@@ -4533,7 +4587,7 @@ const c = a || true;
|
||||
const c = false | true;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_or_bool_known_unknown() async {
|
||||
@@ -4542,7 +4596,7 @@ const b = bool.fromEnvironment('y');
|
||||
const c = false | b;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_or_bool_true_invalid() async {
|
||||
@@ -4562,7 +4616,7 @@ const a = bool.fromEnvironment('x');
|
||||
const c = a | true;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_or_bool_unknown_unknown() async {
|
||||
@@ -4572,7 +4626,7 @@ const b = bool.fromEnvironment('y');
|
||||
const c = a | b;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_or_int() async {
|
||||
@@ -4580,7 +4634,7 @@ const c = a | b;
|
||||
const c = 3 | 5;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.intType);
|
||||
expect(result.type, unitResult.typeProvider.intType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_or_known_known() async {
|
||||
@@ -4611,7 +4665,7 @@ const c = 3 | false;
|
||||
const c = 'a' ?? 'b';
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.stringType);
|
||||
expect(result.type, unitResult.typeProvider.stringType);
|
||||
expect(result.toStringValue(), 'a');
|
||||
}
|
||||
|
||||
@@ -4629,7 +4683,7 @@ class C {}
|
||||
const c = null ?? 'b';
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.stringType);
|
||||
expect(result.type, unitResult.typeProvider.stringType);
|
||||
expect(result.toStringValue(), 'b');
|
||||
}
|
||||
|
||||
@@ -4646,7 +4700,7 @@ const c = null ?? null;
|
||||
const c = false ^ true;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_xor_bool_known_unknown() async {
|
||||
@@ -4655,7 +4709,7 @@ const b = bool.fromEnvironment('y');
|
||||
const c = false ^ b;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_xor_bool_unknown_known() async {
|
||||
@@ -4664,7 +4718,7 @@ const a = bool.fromEnvironment('x');
|
||||
const c = a ^ true;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_xor_bool_unknown_unknown() async {
|
||||
@@ -4674,7 +4728,7 @@ const b = bool.fromEnvironment('y');
|
||||
const c = a ^ b;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.boolType);
|
||||
expect(result.type, unitResult.typeProvider.boolType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_xor_int() async {
|
||||
@@ -4682,7 +4736,7 @@ const c = a ^ b;
|
||||
const c = 3 ^ 5;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'c');
|
||||
expect(result.type, typeProvider.intType);
|
||||
expect(result.type, unitResult.typeProvider.intType);
|
||||
}
|
||||
|
||||
test_visitBinaryExpression_xor_mixed() async {
|
||||
@@ -4878,7 +4932,7 @@ double 3.45
|
||||
const double d = 3;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'd');
|
||||
expect(result.type, typeProvider.doubleType);
|
||||
expect(result.type, unitResult.typeProvider.doubleType);
|
||||
expect(result.toDoubleValue(), 3.0);
|
||||
}
|
||||
|
||||
@@ -5131,8 +5185,8 @@ const y = B(x);
|
||||
const a = dynamic;
|
||||
''');
|
||||
DartObjectImpl result = _evaluateConstant(unitResult, 'a');
|
||||
expect(result.type, typeProvider.typeType);
|
||||
expect(result.toTypeValue(), typeProvider.dynamicType);
|
||||
expect(result.type, unitResult.typeProvider.typeType);
|
||||
expect(result.toTypeValue(), unitResult.typeProvider.dynamicType);
|
||||
}
|
||||
|
||||
test_visitSimpleIdentifier_variable() async {
|
||||
@@ -5227,6 +5281,7 @@ class ConstantVisitorTestSupport extends PubPackageResolutionTest {
|
||||
.topVariableDeclarationByName(name)
|
||||
.initializer!;
|
||||
return _evaluateExpression(
|
||||
unitResult,
|
||||
expression,
|
||||
diagnosticCodes: diagnosticCodes,
|
||||
declaredVariables: declaredVariables,
|
||||
@@ -5234,11 +5289,12 @@ class ConstantVisitorTestSupport extends PubPackageResolutionTest {
|
||||
}
|
||||
|
||||
DartObjectImpl? _evaluateExpression(
|
||||
TestResolvedUnitResult unitResult,
|
||||
Expression expression, {
|
||||
List<DiagnosticCode>? diagnosticCodes,
|
||||
Map<String, String> declaredVariables = const {},
|
||||
}) {
|
||||
var unit = this.result.unit;
|
||||
var unit = unitResult.unit;
|
||||
var source = unit.declaredFragment!.source;
|
||||
var errorListener = GatheringDiagnosticListener();
|
||||
var diagnosticReporter = DiagnosticReporter(errorListener, source);
|
||||
@@ -5247,7 +5303,7 @@ class ConstantVisitorTestSupport extends PubPackageResolutionTest {
|
||||
declaredVariables: DeclaredVariables.fromMap(declaredVariables),
|
||||
configuration: ConstantEvaluationConfiguration(),
|
||||
),
|
||||
this.result.libraryElement,
|
||||
unitResult.libraryElement,
|
||||
diagnosticReporter,
|
||||
);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ extension StringExtension on String {}
|
||||
}
|
||||
|
||||
test_extension_unnamed() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
extension on String {}
|
||||
''');
|
||||
|
||||
|
||||
@@ -1510,11 +1510,11 @@ mixin M on A {}
|
||||
}
|
||||
|
||||
test_getMember_super_forObject() async {
|
||||
await resolveTestCode('''
|
||||
var result = await resolveTestCode('''
|
||||
class A {}
|
||||
''');
|
||||
var member = manager.getMember(
|
||||
typeProvider.objectType.element,
|
||||
result.typeProvider.objectType.element,
|
||||
Name(null, 'hashCode'),
|
||||
forSuper: true,
|
||||
);
|
||||
|
||||
@@ -119,15 +119,13 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
|
||||
File file, {
|
||||
OperationPerformanceImpl? performance,
|
||||
}) async {
|
||||
result =
|
||||
await fileResolver.resolve(path: file.path, performance: performance)
|
||||
as ResolvedUnitResultImpl;
|
||||
return result;
|
||||
return await fileResolver.resolve(path: file.path, performance: performance)
|
||||
as ResolvedUnitResultImpl;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TestResolvedUnitResult> resolveTestFile() async {
|
||||
result = await resolveFile(testFile);
|
||||
var result = await resolveFile(testFile);
|
||||
return TestResolvedUnitResult(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ import 'a.dart';
|
||||
void f(A a, B b) {}
|
||||
''');
|
||||
|
||||
result = await resolveFile(b);
|
||||
var result = await resolveFile(b);
|
||||
assertErrorsInResolvedUnit(result, [error(diag.undefinedClass, 29, 1)]);
|
||||
|
||||
newFile(a.path, r'''
|
||||
@@ -455,7 +455,7 @@ void f(A a) {
|
||||
}
|
||||
''');
|
||||
|
||||
result = await resolveFile(b);
|
||||
var result = await resolveFile(b);
|
||||
assertErrorsInResolvedUnit(result, [error(diag.assignmentToFinal, 36, 3)]);
|
||||
|
||||
newFile(a.path, r'''
|
||||
@@ -480,7 +480,7 @@ var b = B(0);
|
||||
part of 'a.dart';
|
||||
''');
|
||||
|
||||
result = await resolveFile(a);
|
||||
var result = await resolveFile(a);
|
||||
assertErrorsInResolvedUnit(result, [error(diag.undefinedFunction, 24, 1)]);
|
||||
|
||||
// Update a.dart, and notify the resolver. We need this to have at least
|
||||
@@ -1449,7 +1449,7 @@ var a = 4.2;
|
||||
}
|
||||
|
||||
test_getFilesWithTopLevelDeclarations_cached() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
int a = 0;
|
||||
var b = 1 + 2;
|
||||
''');
|
||||
@@ -1511,8 +1511,8 @@ part of 'b.dart';
|
||||
var a = newFile('/workspace/third_party/dart/aaa/lib/a.dart', r'''
|
||||
import 'dart:math';
|
||||
''');
|
||||
await resolveFile(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile(a);
|
||||
assertErrorsInResolvedUnit(result, const []);
|
||||
}
|
||||
|
||||
test_linkLibraries() async {
|
||||
@@ -2455,8 +2455,8 @@ void func() {
|
||||
// No resolved files yet.
|
||||
_assertResolvedFiles([]);
|
||||
|
||||
await resolveFile2(testFile);
|
||||
var result1 = result;
|
||||
var result = await resolveFile2(testFile);
|
||||
var result1 = result.analysisResult;
|
||||
|
||||
// The file was resolved.
|
||||
_assertResolvedFiles([testFile]);
|
||||
@@ -2465,22 +2465,22 @@ void func() {
|
||||
expect(fileResolver.cachedResults, contains(testFile.path));
|
||||
|
||||
// Ask again, no changes, not resolved.
|
||||
await resolveFile2(testFile);
|
||||
result = await resolveFile2(testFile);
|
||||
_assertResolvedFiles([]);
|
||||
|
||||
// The same result was returned.
|
||||
expect(result, same(result1));
|
||||
expect(result.analysisResult, same(result1));
|
||||
|
||||
// Change a file.
|
||||
var a_path = convertPath('/workspace/dart/test/lib/a.dart');
|
||||
fileResolver.changeFiles([a_path]);
|
||||
|
||||
// The was a change to a file, no matter which, resolve again.
|
||||
await resolveFile2(testFile);
|
||||
result = await resolveFile2(testFile);
|
||||
_assertResolvedFiles([testFile]);
|
||||
|
||||
// Get should get a new result.
|
||||
expect(result, isNot(same(result1)));
|
||||
expect(result.analysisResult, isNot(same(result1)));
|
||||
}
|
||||
|
||||
test_resolveLibrary() async {
|
||||
|
||||
@@ -41,7 +41,8 @@ import 'resolution.dart';
|
||||
export 'package:analyzer_testing/src/analysis_rule/pub_package_resolution.dart'
|
||||
show ExpectedDiagnostic;
|
||||
|
||||
export 'resolution.dart' show TestResolvedUnitResult;
|
||||
export 'resolution.dart'
|
||||
show ResolvedUnitResultExtension, TestResolvedUnitResult;
|
||||
|
||||
class BlazeWorkspaceResolutionTest extends ContextResolutionTest {
|
||||
@override
|
||||
@@ -465,8 +466,8 @@ mixin WithStrictCastsMixin on PubPackageResolutionTest {
|
||||
String code,
|
||||
List<ExpectedError> expectedErrors,
|
||||
) async {
|
||||
await resolveTestCode(code);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveTestCode(code);
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
await disposeAnalysisContextCollection();
|
||||
|
||||
@@ -474,8 +475,8 @@ mixin WithStrictCastsMixin on PubPackageResolutionTest {
|
||||
analysisOptionsContent(experiments: experiments, strictCasts: true),
|
||||
);
|
||||
|
||||
await resolveTestFile();
|
||||
assertErrorsInResult(expectedErrors);
|
||||
result = await resolveTestFile();
|
||||
assertErrorsInTestResult(result, expectedErrors);
|
||||
}
|
||||
|
||||
/// Asserts that no errors are reported in [code], both when implicit casts
|
||||
|
||||
@@ -1396,7 +1396,7 @@ void f() {
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([]);
|
||||
assertErrorsInTestResult(result, []);
|
||||
|
||||
var node = result.findNode.singleMethodInvocation;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -25,11 +25,15 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
test_language205() async {
|
||||
writeTestPackageConfig(PackageConfigFileBuilder(), languageVersion: '2.5');
|
||||
|
||||
await resolveTestCode('');
|
||||
var result = await resolveTestCode('');
|
||||
|
||||
_assertLanguageVersion(package: Version.parse('2.5.0'), override: null);
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.5.0'),
|
||||
override: null,
|
||||
);
|
||||
|
||||
_assertFeatureSet([
|
||||
_assertFeatureSet(result, [
|
||||
Feature.constant_update_2018,
|
||||
Feature.control_flow_collections,
|
||||
Feature.set_literals,
|
||||
@@ -40,11 +44,15 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
test_language208() async {
|
||||
writeTestPackageConfig(PackageConfigFileBuilder(), languageVersion: '2.8');
|
||||
|
||||
await resolveTestCode('');
|
||||
var result = await resolveTestCode('');
|
||||
|
||||
_assertLanguageVersion(package: Version.parse('2.8.0'), override: null);
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.8.0'),
|
||||
override: null,
|
||||
);
|
||||
|
||||
_assertFeatureSet([
|
||||
_assertFeatureSet(result, [
|
||||
Feature.constant_update_2018,
|
||||
Feature.control_flow_collections,
|
||||
Feature.extension_methods,
|
||||
@@ -56,15 +64,16 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
test_language208_override205() async {
|
||||
writeTestPackageConfig(PackageConfigFileBuilder(), languageVersion: '2.8');
|
||||
|
||||
await resolveTestCode('// @dart = 2.5');
|
||||
var result = await resolveTestCode('// @dart = 2.5');
|
||||
|
||||
// Valid override, less than the latest supported language version.
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.8.0'),
|
||||
override: Version.parse('2.5.0'),
|
||||
);
|
||||
|
||||
_assertFeatureSet([
|
||||
_assertFeatureSet(result, [
|
||||
Feature.constant_update_2018,
|
||||
Feature.control_flow_collections,
|
||||
Feature.set_literals,
|
||||
@@ -75,11 +84,15 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
test_language209() async {
|
||||
writeTestPackageConfig(PackageConfigFileBuilder(), languageVersion: '2.9');
|
||||
|
||||
await resolveTestCode('');
|
||||
var result = await resolveTestCode('');
|
||||
|
||||
_assertLanguageVersion(package: Version.parse('2.9.0'), override: null);
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.9.0'),
|
||||
override: null,
|
||||
);
|
||||
|
||||
_assertFeatureSet([
|
||||
_assertFeatureSet(result, [
|
||||
Feature.constant_update_2018,
|
||||
Feature.control_flow_collections,
|
||||
Feature.extension_methods,
|
||||
@@ -91,12 +104,16 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
test_language212_override399() async {
|
||||
writeTestPackageConfig(PackageConfigFileBuilder(), languageVersion: '2.12');
|
||||
|
||||
await resolveTestCode('// @dart = 3.99');
|
||||
var result = await resolveTestCode('// @dart = 3.99');
|
||||
|
||||
// Invalid override: minor is greater than the latest minor.
|
||||
_assertLanguageVersion(package: Version.parse('2.12.0'), override: null);
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.12.0'),
|
||||
override: null,
|
||||
);
|
||||
|
||||
_assertFeatureSet([
|
||||
_assertFeatureSet(result, [
|
||||
Feature.constant_update_2018,
|
||||
Feature.control_flow_collections,
|
||||
Feature.extension_methods,
|
||||
@@ -109,12 +126,16 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
test_language212_override400() async {
|
||||
writeTestPackageConfig(PackageConfigFileBuilder(), languageVersion: '2.12');
|
||||
|
||||
await resolveTestCode('// @dart = 4.00');
|
||||
var result = await resolveTestCode('// @dart = 4.00');
|
||||
|
||||
// Invalid override: major is greater than the latest major.
|
||||
_assertLanguageVersion(package: Version.parse('2.12.0'), override: null);
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.12.0'),
|
||||
override: null,
|
||||
);
|
||||
|
||||
_assertFeatureSet([
|
||||
_assertFeatureSet(result, [
|
||||
Feature.constant_update_2018,
|
||||
Feature.control_flow_collections,
|
||||
Feature.extension_methods,
|
||||
@@ -124,7 +145,10 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
]);
|
||||
}
|
||||
|
||||
void _assertFeatureSet(List<Feature> expected) {
|
||||
void _assertFeatureSet(
|
||||
TestResolvedUnitResult result,
|
||||
List<Feature> expected,
|
||||
) {
|
||||
var featureSet = result.libraryElement.featureSet;
|
||||
|
||||
var actual = ExperimentStatus.knownFeatures.values
|
||||
@@ -134,7 +158,8 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
expect(actual, unorderedEquals(expected));
|
||||
}
|
||||
|
||||
void _assertLanguageVersion({
|
||||
void _assertLanguageVersion(
|
||||
TestResolvedUnitResult result, {
|
||||
required Version package,
|
||||
required Version? override,
|
||||
}) {
|
||||
@@ -147,7 +172,7 @@ class LibraryElementTest_featureSet extends PubPackageResolutionTest {
|
||||
@reflectiveTest
|
||||
class LibraryElementTest_toString extends PubPackageResolutionTest {
|
||||
test_hasLibraryDirective_hasName() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
library my.name;
|
||||
''');
|
||||
|
||||
@@ -155,7 +180,7 @@ library my.name;
|
||||
}
|
||||
|
||||
test_hasLibraryDirective_noName() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
library;
|
||||
''');
|
||||
|
||||
@@ -163,7 +188,7 @@ library;
|
||||
}
|
||||
|
||||
test_noLibraryDirective() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
|
||||
@@ -376,7 +376,7 @@ ExportDirective
|
||||
get f => null;
|
||||
set f(_) {}
|
||||
''');
|
||||
await resolveTestCode(r'''
|
||||
var result = await resolveTestCode(r'''
|
||||
export 'a.dart';
|
||||
''');
|
||||
var exportNamespace = result.libraryElement.exportNamespace;
|
||||
@@ -545,7 +545,7 @@ export 'c.dart';
|
||||
newFile('$testPackageLibPath/c.dart', '');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
var node = result.findNode.export('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -571,7 +571,7 @@ export 'c.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 25, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 25, 8)]);
|
||||
|
||||
var node = result.findNode.export('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -597,7 +597,7 @@ export ':net';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.invalidUri, 25, 6)]);
|
||||
assertErrorsInTestResult(result, [error(diag.invalidUri, 25, 6)]);
|
||||
|
||||
var node = result.findNode.export('export');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -623,7 +623,9 @@ export '${'foo'}.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriWithInterpolation, 25, 15)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.uriWithInterpolation, 25, 15),
|
||||
]);
|
||||
|
||||
var node = result.findNode.export('export');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -659,7 +661,7 @@ export 'foo:bar';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 25, 9)]);
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 25, 9)]);
|
||||
|
||||
var node = result.findNode.export('export');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -689,7 +691,7 @@ part of my.lib;
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.exportOfNonLibrary, 25, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.exportOfNonLibrary, 25, 8)]);
|
||||
|
||||
var node = result.findNode.export('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -719,7 +721,7 @@ part of 'b.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.exportOfNonLibrary, 25, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.exportOfNonLibrary, 25, 8)]);
|
||||
|
||||
var node = result.findNode.export('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -729,7 +729,7 @@ import 'c.dart';
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
// TODO(scheglov): update the hint.
|
||||
// assertErrorsInResult([
|
||||
// assertErrorsInTestResult(result, [
|
||||
// error(WarningCode.UNUSED_IMPORT, 33, 8),
|
||||
// ]);
|
||||
|
||||
@@ -757,7 +757,7 @@ import 'c.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 25, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 25, 8)]);
|
||||
|
||||
var node = result.findNode.import('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -783,7 +783,7 @@ import ':net';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.invalidUri, 25, 6)]);
|
||||
assertErrorsInTestResult(result, [error(diag.invalidUri, 25, 6)]);
|
||||
|
||||
var node = result.findNode.import('import');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -809,7 +809,9 @@ import '${'foo'}.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriWithInterpolation, 25, 15)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.uriWithInterpolation, 25, 15),
|
||||
]);
|
||||
|
||||
var node = result.findNode.import('import');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -845,7 +847,7 @@ import 'foo:bar';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 25, 9)]);
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 25, 9)]);
|
||||
|
||||
var node = result.findNode.import('import');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -875,7 +877,7 @@ part of my.lib;
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.importOfNonLibrary, 25, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.importOfNonLibrary, 25, 8)]);
|
||||
|
||||
var node = result.findNode.import('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -905,7 +907,7 @@ part of 'b.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.importOfNonLibrary, 25, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.importOfNonLibrary, 25, 8)]);
|
||||
|
||||
var node = result.findNode.import('c.dart');
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -355,7 +355,7 @@ part of 'test.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
_assertAtFoo42(result);
|
||||
}
|
||||
|
||||
@@ -144,11 +144,11 @@ part 'b.dart';
|
||||
part of my.lib;
|
||||
''');
|
||||
|
||||
await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
var bResult = await resolveFile2(b);
|
||||
assertErrorsInTestResult(bResult, const []);
|
||||
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -175,11 +175,11 @@ part 'b.dart';
|
||||
part of my.lib;
|
||||
''');
|
||||
|
||||
await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
var bResult = await resolveFile2(b);
|
||||
assertErrorsInTestResult(bResult, const []);
|
||||
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -206,11 +206,13 @@ part 'b.dart';
|
||||
part of bar;
|
||||
''');
|
||||
|
||||
await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
var bResult = await resolveFile2(b);
|
||||
assertErrorsInTestResult(bResult, const []);
|
||||
|
||||
var result = await resolveFile2(a);
|
||||
assertErrorsInResult([error(diag.partOfDifferentLibrary, 33, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.partOfDifferentLibrary, 33, 8),
|
||||
]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -334,7 +336,7 @@ part 'c.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 23, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 23, 8)]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -360,7 +362,7 @@ part ':net';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.invalidUri, 23, 6)]);
|
||||
assertErrorsInTestResult(result, [error(diag.invalidUri, 23, 6)]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -386,7 +388,9 @@ part '${'foo'}.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriWithInterpolation, 23, 15)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.uriWithInterpolation, 23, 15),
|
||||
]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -422,7 +426,7 @@ part 'foo:bar';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 23, 9)]);
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 23, 9)]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -451,12 +455,12 @@ part 'c.dart';
|
||||
part of my.lib;
|
||||
''');
|
||||
|
||||
await resolveFile2(c);
|
||||
assertErrorsInResult([error(diag.partOfName, 8, 6)]);
|
||||
var cResult = await resolveFile2(c);
|
||||
assertErrorsInTestResult(cResult, [error(diag.partOfName, 8, 6)]);
|
||||
|
||||
// We already reported an error above.
|
||||
var result = await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -486,7 +490,7 @@ part of 'b.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
assertErrorsInTestResult(result, const []);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -516,7 +520,9 @@ part of 'a.dart';
|
||||
''');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.partOfDifferentLibrary, 23, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.partOfDifferentLibrary, 23, 8),
|
||||
]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
@@ -544,7 +550,7 @@ part 'c.dart';
|
||||
newFile('$testPackageLibPath/c.dart', '');
|
||||
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.partOfNonPart, 23, 8)]);
|
||||
assertErrorsInTestResult(result, [error(diag.partOfNonPart, 23, 8)]);
|
||||
|
||||
var node = result.findNode.singlePartDirective;
|
||||
assertResolvedNodeText(node, r'''
|
||||
|
||||
@@ -47,28 +47,11 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
||||
final ResolvedNodeTextConfiguration nodeTextConfiguration =
|
||||
ResolvedNodeTextConfiguration();
|
||||
|
||||
late ResolvedUnitResultImpl result;
|
||||
|
||||
final DartObjectPrinterConfiguration dartObjectPrinterConfiguration =
|
||||
DartObjectPrinterConfiguration();
|
||||
|
||||
InheritanceManager3 get inheritanceManager {
|
||||
var library = result.libraryElement;
|
||||
return library.session.inheritanceManager;
|
||||
}
|
||||
|
||||
bool get strictCasts {
|
||||
var analysisOptions = result.session.analysisContext
|
||||
.getAnalysisOptionsForFile(result.file);
|
||||
return analysisOptions.strictCasts;
|
||||
}
|
||||
|
||||
File get testFile;
|
||||
|
||||
TypeProviderImpl get typeProvider => result.typeProvider;
|
||||
|
||||
TypeSystemImpl get typeSystem => result.typeSystem;
|
||||
|
||||
void addTestFile(String content) {
|
||||
newFile(testFile.path, content);
|
||||
}
|
||||
@@ -184,11 +167,21 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
||||
assertErrorsInList(result.diagnostics, expectedDiagnostics);
|
||||
}
|
||||
|
||||
void assertErrorsInResult(List<ExpectedDiagnostic> expectedDiagnostics) {
|
||||
void assertErrorsInResult(
|
||||
ResolvedUnitResult result,
|
||||
List<ExpectedDiagnostic> expectedDiagnostics,
|
||||
) {
|
||||
assertErrorsInResolvedUnit(result, expectedDiagnostics);
|
||||
}
|
||||
|
||||
void assertHasTestErrors() {
|
||||
void assertErrorsInTestResult(
|
||||
TestResolvedUnitResult result,
|
||||
List<ExpectedDiagnostic> expectedDiagnostics,
|
||||
) {
|
||||
assertErrorsInList(result.diagnostics, expectedDiagnostics);
|
||||
}
|
||||
|
||||
void assertHasTestErrors(TestResolvedUnitResult result) {
|
||||
expect(result.diagnostics, isNotEmpty);
|
||||
}
|
||||
|
||||
@@ -200,8 +193,12 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
||||
return result;
|
||||
}
|
||||
|
||||
void assertNoErrorsInResult() {
|
||||
assertErrorsInResult(const []);
|
||||
void assertNoErrorsInResult(ResolvedUnitResult result) {
|
||||
assertErrorsInResult(result, const []);
|
||||
}
|
||||
|
||||
void assertNoErrorsInTestResult(TestResolvedUnitResult result) {
|
||||
assertErrorsInTestResult(result, const []);
|
||||
}
|
||||
|
||||
void assertParsedNodeText(AstNode node, String expected) {
|
||||
@@ -405,14 +402,13 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
||||
|
||||
Future<ResolvedUnitResultImpl> resolveFile(File file);
|
||||
|
||||
/// Resolve [file] into [result] and return a test view of it.
|
||||
/// Resolve [file] and return a test view of it.
|
||||
Future<TestResolvedUnitResult> resolveFile2(File file) async {
|
||||
result = await resolveFile(file);
|
||||
|
||||
var result = await resolveFile(file);
|
||||
return TestResolvedUnitResult(result);
|
||||
}
|
||||
|
||||
/// Create a new file with the [path] and [content], resolve it into [result].
|
||||
/// Create a new file with the [path] and [content], and resolve it.
|
||||
Future<TestResolvedUnitResult> resolveFileCode(String path, String content) {
|
||||
var file = newFile(path, content);
|
||||
return resolveFile2(file);
|
||||
@@ -506,6 +502,10 @@ final class TestResolvedUnitResult {
|
||||
|
||||
File get file => analysisResult.file;
|
||||
|
||||
InheritanceManager3 get inheritanceManager {
|
||||
return libraryElement.session.inheritanceManager;
|
||||
}
|
||||
|
||||
bool get isLibrary => analysisResult.isLibrary;
|
||||
|
||||
bool get isPart => analysisResult.isPart;
|
||||
@@ -538,5 +538,10 @@ extension ResolvedUnitResultExtension on ResolvedUnitResult {
|
||||
return FindNode(content, unit);
|
||||
}
|
||||
|
||||
InheritanceManager3 get inheritanceManager {
|
||||
var library = libraryElement as LibraryElementImpl;
|
||||
return library.session.inheritanceManager;
|
||||
}
|
||||
|
||||
String get uriStr => '$uri';
|
||||
}
|
||||
|
||||
@@ -1217,7 +1217,7 @@ void f() sync* {
|
||||
}
|
||||
|
||||
Future<void> _assertHasReturn(String code, int n, bool expected) async {
|
||||
await resolveTestCode(code);
|
||||
var result = await resolveTestCode(code);
|
||||
|
||||
var function = result.unit.declarations.last as FunctionDeclaration;
|
||||
var body = function.functionExpression.body as BlockFunctionBody;
|
||||
|
||||
@@ -24,7 +24,7 @@ class ArgumentTypeNotAssignableTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/lib2.dart', '''
|
||||
class _A {}
|
||||
g(h(_A a)) {}''');
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'lib2.dart';
|
||||
class _A {}
|
||||
f() {
|
||||
|
||||
@@ -222,7 +222,9 @@ abstract class A {
|
||||
test_noHintsInTestDir() async {
|
||||
// Code that is in a test dir should not trigger the hint.
|
||||
// (See:https://github.com/dart-lang/sdk/issues/45594)
|
||||
await resolveFileCode('$testPackageRootPath/test/test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/test/test.dart',
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class A {
|
||||
@@ -233,8 +235,9 @@ class A {
|
||||
class B {
|
||||
String f = A().v;
|
||||
}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
''',
|
||||
);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_tearOff() async {
|
||||
|
||||
@@ -33,11 +33,11 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(testFile);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(testFile);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
@@ -58,11 +58,13 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(testFile);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(testFile);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(a);
|
||||
assertErrorsInResult([error(diag.duplicateConstructorDefault, 42, 1)]);
|
||||
result = await resolveFile2(a);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.duplicateConstructorDefault, 42, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_class_primary_unnamed_typeName_new() async {
|
||||
|
||||
@@ -33,11 +33,11 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(testFile);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(testFile);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
@@ -59,11 +59,11 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(testFile);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(testFile);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
@SkippedTest() // TODO(scheglov): implement augmentation
|
||||
@@ -84,11 +84,13 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(testFile);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(testFile);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(a);
|
||||
assertErrorsInResult([error(diag.duplicateConstructorName, 42, 7)]);
|
||||
result = await resolveFile2(a);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.duplicateConstructorName, 42, 7),
|
||||
]);
|
||||
}
|
||||
|
||||
test_class_newHead_named_newHead_named() async {
|
||||
|
||||
@@ -46,8 +46,8 @@ class A implements MapEntry<int, int> {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
|
||||
+2
-2
@@ -45,8 +45,8 @@ class A implements MapEntry<int, int> {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
|
||||
@@ -35,8 +35,8 @@ import 'dart:_internal';
|
||||
var file = newFile('$packageRootPath/lib/js.dart', '''
|
||||
import 'dart:_wasm';
|
||||
''');
|
||||
await resolveFile2(file);
|
||||
assertErrorsInResolvedUnit(result, [error(diag.unusedImport, 7, 12)]);
|
||||
var result = await resolveFile2(file);
|
||||
assertErrorsInTestResult(result, [error(diag.unusedImport, 7, 12)]);
|
||||
}
|
||||
|
||||
test_wasm_fromTest() async {
|
||||
@@ -53,8 +53,8 @@ import 'dart:_wasm';
|
||||
var file = newFile('$packageRootPath/lib/ui.dart', '''
|
||||
import 'dart:_wasm';
|
||||
''');
|
||||
await resolveFile2(file);
|
||||
assertErrorsInResolvedUnit(result, [error(diag.unusedImport, 7, 12)]);
|
||||
var result = await resolveFile2(file);
|
||||
assertErrorsInTestResult(result, [error(diag.unusedImport, 7, 12)]);
|
||||
}
|
||||
|
||||
String _newPackage(String packageName) {
|
||||
|
||||
@@ -47,11 +47,16 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageBlazeBinPath/lib/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageBlazeBinPath/lib/bar.dart',
|
||||
r'''
|
||||
export 'src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertErrorsInResult([error(diag.invalidExportOfInternalElement, 0, 22)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidExportOfInternalElement, 0, 22),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_exporterIsInBlazeBinLibSrc() async {
|
||||
@@ -60,11 +65,14 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageBlazeBinPath/lib/src/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageBlazeBinPath/lib/src/bar.dart',
|
||||
r'''
|
||||
export 'foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_exporterIsInGenfilesLib() async {
|
||||
@@ -73,11 +81,16 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageGenfilesPath/lib/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageGenfilesPath/lib/bar.dart',
|
||||
r'''
|
||||
export 'src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertErrorsInResult([error(diag.invalidExportOfInternalElement, 0, 22)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidExportOfInternalElement, 0, 22),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_exporterIsInGenfilesLibSrc() async {
|
||||
@@ -86,11 +99,14 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageGenfilesPath/lib/src/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageGenfilesPath/lib/src/bar.dart',
|
||||
r'''
|
||||
export 'foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_exporterIsInLib() async {
|
||||
@@ -99,11 +115,13 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageLibPath/bar.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/bar.dart', r'''
|
||||
export 'src/foo.dart';
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidExportOfInternalElement, 0, 22)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidExportOfInternalElement, 0, 22),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_exporterIsInLibSrc() async {
|
||||
@@ -112,11 +130,11 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageLibPath/src/bar.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/src/bar.dart', r'''
|
||||
export 'foo.dart';
|
||||
''');
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_exporterIsInTest() async {
|
||||
@@ -125,11 +143,14 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$myPackageRootPath/test/foo_test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$myPackageRootPath/test/foo_test.dart',
|
||||
r'''
|
||||
export 'package:dart.my/src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_internalIsInBlazeBin() async {
|
||||
@@ -187,11 +208,16 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageDartToolPath/lib/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageDartToolPath/lib/bar.dart',
|
||||
r'''
|
||||
export 'package:test/src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertErrorsInResult([error(diag.invalidExportOfInternalElement, 0, 35)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidExportOfInternalElement, 0, 35),
|
||||
]);
|
||||
}
|
||||
|
||||
@FailingTest(
|
||||
@@ -206,11 +232,14 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageDartToolPath/lib/src/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageDartToolPath/lib/src/bar.dart',
|
||||
r'''
|
||||
export 'package:test/src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_exporterInLib() async {
|
||||
@@ -219,11 +248,13 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageRootPath/lib/bar.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageRootPath/lib/bar.dart', r'''
|
||||
export 'package:test/src/foo.dart';
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidExportOfInternalElement, 0, 35)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidExportOfInternalElement, 0, 35),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_exporterInLibSrc() async {
|
||||
@@ -232,11 +263,14 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageRootPath/lib/src/bar.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/lib/src/bar.dart',
|
||||
r'''
|
||||
export 'package:test/src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_internalIsInGeneratedLibSrc() async {
|
||||
@@ -285,11 +319,13 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageLibPath/bar.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/bar.dart', r'''
|
||||
export 'src/foo.dart';
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidExportOfInternalElement, 0, 22)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidExportOfInternalElement, 0, 22),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_exporterIsInLibSrc() async {
|
||||
@@ -298,11 +334,11 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageLibPath/src/bar.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/src/bar.dart', r'''
|
||||
export 'foo.dart';
|
||||
''');
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_exporterIsInTest() async {
|
||||
@@ -311,11 +347,14 @@ import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageRootPath/test/foo_test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/test/foo_test.dart',
|
||||
r'''
|
||||
export 'package:test/src/foo.dart';
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_internalIsLibSrc() async {
|
||||
|
||||
@@ -43,8 +43,10 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(b);
|
||||
assertErrorsInResult([error(diag.invalidFactoryNameNotAClass, 47, 1)]);
|
||||
var result = await resolveFile2(b);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidFactoryNameNotAClass, 47, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notEnclosingClassName_withoutPrimaryConstructors() async {
|
||||
@@ -86,7 +88,7 @@ augment class A {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(b);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(b);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,99 +28,116 @@ version: 0.0.1
|
||||
}
|
||||
|
||||
void test_annotationInLib() async {
|
||||
await resolveFileCode('$testPackageLibPath/foo.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/foo.dart', r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidInternalAnnotation, 34, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_annotationInLib_onLibrary() async {
|
||||
await resolveFileCode('$testPackageLibPath/foo.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/foo.dart', r'''
|
||||
@internal
|
||||
library foo;
|
||||
import 'package:meta/meta.dart';
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidInternalAnnotation, 1, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 1, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_annotationInLibSrc() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_annotationInLibSrcSubdirectory() async {
|
||||
await resolveFileCode('$testPackageLibPath/src/foo/foo.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageLibPath/src/foo/foo.dart',
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_annotationInLibSubdirectory() async {
|
||||
await resolveFileCode('$testPackageLibPath/foo/foo.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/foo/foo.dart', r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidInternalAnnotation, 34, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_annotationInTest() async {
|
||||
await resolveFileCode('$testPackageRootPath/test/foo_test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/test/foo_test.dart',
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal class One {}
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_annotationInTest_extensionType() async {
|
||||
await resolveFileCode('$testPackageRootPath/test/foo_test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/test/foo_test.dart',
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal extension type E(int i) {}
|
||||
''');
|
||||
''',
|
||||
);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
void test_privateClass() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal class _One {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
error(diag.unusedElement, 49, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateConstructor() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
@internal C._f();
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidInternalAnnotation, 46, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 46, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateEnum() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal enum _E {one}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
error(diag.unusedElement, 48, 2),
|
||||
error(diag.unusedField, 52, 3),
|
||||
@@ -128,181 +145,185 @@ import 'package:meta/meta.dart';
|
||||
}
|
||||
|
||||
void test_privateEnumValue() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
enum E {@internal _one}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 42, 8),
|
||||
error(diag.unusedField, 51, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateExtension() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal extension _One on String {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidInternalAnnotation, 34, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateExtension_unnamed() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal extension on String {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.invalidInternalAnnotation, 34, 8)]);
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateExtensionType() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal extension type _E(int i) {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
error(diag.unusedElement, 58, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateField_instance() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
@internal int _i = 0;
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.unusedField, 59, 2),
|
||||
error(diag.invalidInternalAnnotation, 59, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateField_static() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
@internal static int _i = 0;
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.unusedField, 66, 2),
|
||||
error(diag.invalidInternalAnnotation, 66, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateGetter() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
@internal int get _i => 0;
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 46, 8),
|
||||
error(diag.unusedElement, 63, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateMethod_instance() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
@internal void _f() {}
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 46, 8),
|
||||
error(diag.unusedElement, 60, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateMethod_static() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class C {
|
||||
@internal static void _f() {}
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 46, 8),
|
||||
error(diag.unusedElement, 67, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateMixin() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal mixin _One {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
error(diag.unusedElement, 49, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateTopLevelFunction() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal void _f() {}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
error(diag.unusedElement, 48, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateTopLevelVariable() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal int _i = 1;
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 47, 6),
|
||||
error(diag.unusedElement, 47, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_privateTypedef() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@internal typedef _T = void Function();
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.invalidInternalAnnotation, 34, 8),
|
||||
error(diag.unusedElement, 51, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_publicConstructor_named_privateClass() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class _C {
|
||||
@internal _C.named();
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.unusedElement, 39, 2),
|
||||
error(diag.invalidInternalAnnotation, 47, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_publicConstructor_primary_privateClass() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class _C() {
|
||||
@internal
|
||||
@@ -310,59 +331,59 @@ class _C() {
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.unusedElement, 39, 2),
|
||||
error(diag.invalidInternalAnnotation, 49, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_publicConstructor_unnamed_privateClass() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class _C {
|
||||
@internal _C();
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.unusedElement, 39, 2),
|
||||
error(diag.invalidInternalAnnotation, 47, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_publicMethod_privateClass() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class _C {
|
||||
@internal void f() {}
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.unusedElement, 39, 2)]);
|
||||
assertErrorsInTestResult(result, [error(diag.unusedElement, 39, 2)]);
|
||||
}
|
||||
|
||||
void test_publicMethod_privateClass_static() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
class _C {
|
||||
@internal static void f() {}
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([
|
||||
assertErrorsInTestResult(result, [
|
||||
error(diag.unusedElement, 39, 2),
|
||||
error(diag.unusedElement, 68, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_publicMethod_privateExtensionType() async {
|
||||
await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
var result = await resolveFileCode(testPackageLibSrcFilePath, r'''
|
||||
import 'package:meta/meta.dart';
|
||||
extension type _E(int i) {
|
||||
@internal void f() {}
|
||||
}
|
||||
''');
|
||||
|
||||
assertErrorsInResult([error(diag.unusedElement, 48, 2)]);
|
||||
assertErrorsInTestResult(result, [error(diag.unusedElement, 48, 2)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,21 +23,22 @@ class InvalidLanguageOverrideGreaterTest extends PubPackageResolutionTest {
|
||||
|
||||
test_greaterThanLatest() async {
|
||||
var latestVersion = ExperimentStatus.currentVersion;
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
// @dart = ${latestVersion.major}.${latestVersion.minor + 1}
|
||||
// [diag.invalidLanguageVersionOverrideGreater][column 1][length 15] The language version override can't specify a version greater than the latest known language version: 3.13.
|
||||
class A {}
|
||||
''');
|
||||
_assertUnitLanguageVersion(package: latestVersion, override: null);
|
||||
_assertUnitLanguageVersion(result, package: latestVersion, override: null);
|
||||
}
|
||||
|
||||
test_greaterThanPackage() async {
|
||||
_configureTestPackageLanguageVersion('2.5');
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.12
|
||||
int? a;
|
||||
''');
|
||||
_assertUnitLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.5.0'),
|
||||
override: Version.parse('2.12.0'),
|
||||
);
|
||||
@@ -45,17 +46,19 @@ int? a;
|
||||
|
||||
test_lessThanPackage() async {
|
||||
_configureTestPackageLanguageVersion('2.19');
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
// @dart = 2.18
|
||||
class A {}
|
||||
''');
|
||||
_assertUnitLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('2.19.0'),
|
||||
override: Version.parse('2.18.0'),
|
||||
);
|
||||
}
|
||||
|
||||
void _assertUnitLanguageVersion({
|
||||
void _assertUnitLanguageVersion(
|
||||
TestResolvedUnitResult result, {
|
||||
required Version package,
|
||||
required Version? override,
|
||||
}) {
|
||||
|
||||
@@ -46,9 +46,9 @@ import 'src/a.dart';
|
||||
|
||||
A a = A();
|
||||
''');
|
||||
await resolveFile2(a);
|
||||
var result = await resolveFile2(a);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_insidePackage_extensionType() async {
|
||||
@@ -62,9 +62,9 @@ import 'src/a.dart';
|
||||
|
||||
E e = E(1);
|
||||
''');
|
||||
await resolveFile2(a);
|
||||
var result = await resolveFile2(a);
|
||||
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_outsidePackage_class() async {
|
||||
|
||||
+2
-2
@@ -293,7 +293,7 @@ part of 'test.dart';
|
||||
augment enum E with M {}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,11 +61,11 @@ import '../lib1.dart';
|
||||
mixin Bar on Foo {}
|
||||
''');
|
||||
|
||||
await resolveFile2(lib1);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(lib1);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(lib2);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(lib2);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_withinPackageTestDirectory_OK() async {
|
||||
@@ -79,11 +79,11 @@ import 'package:test/lib1.dart';
|
||||
mixin Bar on Foo {}
|
||||
''');
|
||||
|
||||
await resolveFile2(lib1);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(lib1);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(lib2);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(lib2);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_withinPart_OK() async {
|
||||
@@ -98,10 +98,10 @@ part of 'lib1.dart';
|
||||
mixin Bar on Foo {}
|
||||
''');
|
||||
|
||||
await resolveFile2(lib1);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(lib1);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(lib2);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(lib2);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ f() {
|
||||
{'a' : 0, 'b' : 1}.length;
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
expect(
|
||||
result.diagnostics[0].diagnosticCode,
|
||||
diag.nonConstMapAsExpressionStatement,
|
||||
@@ -43,7 +43,7 @@ f() {
|
||||
{'a' : 0, 'b' : 1};
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
expect(
|
||||
result.diagnostics[0].diagnosticCode,
|
||||
diag.nonConstMapAsExpressionStatement,
|
||||
|
||||
@@ -43,7 +43,9 @@ class A {
|
||||
test_noHintsInTestDir() async {
|
||||
// Code that is in a test dir should not trigger the hint.
|
||||
// (See:https://github.com/dart-lang/sdk/issues/45594)
|
||||
await resolveFileCode('$testPackageRootPath/test/test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/test/test.dart',
|
||||
r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@doNotStore
|
||||
@@ -57,8 +59,9 @@ String f() {
|
||||
String g() {
|
||||
return _v;
|
||||
}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
''',
|
||||
);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_returnFromClosureInFunction() async {
|
||||
|
||||
+4
-4
@@ -57,8 +57,8 @@ import 'dart:collection';
|
||||
abstract class A implements LinkedListEntry<Never> {}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
@@ -99,8 +99,8 @@ import 'dart:collection';
|
||||
abstract class A implements LinkedListEntry<Never> {}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
|
||||
+4
-4
@@ -77,8 +77,8 @@ class A implements MapEntry<int, int> {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
@@ -128,8 +128,8 @@ class A implements MapEntry<int, int> {
|
||||
}
|
||||
''');
|
||||
|
||||
await resolveFile2(a);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(a);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'a.dart';
|
||||
|
||||
@@ -160,14 +160,14 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageLibPath/src/b.dart', r'''
|
||||
var result = await resolveFileCode('$testPackageLibPath/src/b.dart', r'''
|
||||
import '../a.dart';
|
||||
class Bar1 extends Foo {}
|
||||
class Bar2 implements Foo {}
|
||||
class Bar4 = Bar1 with Foo;
|
||||
mixin Bar5 implements Foo {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_withinPackageTestDirectory_language219() async {
|
||||
@@ -177,15 +177,18 @@ import 'package:meta/meta.dart';
|
||||
@sealed class Foo {}
|
||||
''');
|
||||
|
||||
await resolveFileCode('$testPackageRootPath/test/test.dart', r'''
|
||||
var result = await resolveFileCode(
|
||||
'$testPackageRootPath/test/test.dart',
|
||||
r'''
|
||||
import 'package:test/a.dart';
|
||||
|
||||
class Bar1 extends Foo {}
|
||||
class Bar2 implements Foo {}
|
||||
class Bar4 = Bar1 with Foo;
|
||||
mixin Bar5 implements Foo {}
|
||||
''');
|
||||
assertNoErrorsInResult();
|
||||
''',
|
||||
);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
|
||||
test_withinPart_language219() async {
|
||||
@@ -205,10 +208,10 @@ class Bar4 = Bar1 with Foo;
|
||||
mixin Bar5 implements Foo {}
|
||||
''');
|
||||
|
||||
await resolveFile2(lib);
|
||||
assertNoErrorsInResult();
|
||||
var result = await resolveFile2(lib);
|
||||
assertNoErrorsInTestResult(result);
|
||||
|
||||
await resolveFile2(part);
|
||||
assertNoErrorsInResult();
|
||||
result = await resolveFile2(part);
|
||||
assertNoErrorsInTestResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1236,7 +1236,7 @@ void foo() {
|
||||
C._();
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
expect(result.diagnostics, isNotEmpty);
|
||||
}
|
||||
|
||||
@@ -3326,7 +3326,7 @@ void foo() {
|
||||
_f();
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
expect(result.diagnostics, isNotEmpty);
|
||||
}
|
||||
|
||||
@@ -3341,7 +3341,7 @@ void foo() {
|
||||
C()._m();
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
var result = await resolveTestFile();
|
||||
expect(result.diagnostics, isNotEmpty);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,8 @@ import 'target.dart';
|
||||
analysisDriver.removeFile(filePath);
|
||||
await analysisDriver.applyPendingFileChanges();
|
||||
|
||||
await resolveTestFile();
|
||||
assertErrorsInResult([error(diag.uriDoesNotExist, 7, 13)]);
|
||||
var result = await resolveTestFile();
|
||||
assertErrorsInTestResult(result, [error(diag.uriDoesNotExist, 7, 13)]);
|
||||
}
|
||||
|
||||
test_libraryImport_cannotResolve() async {
|
||||
@@ -129,8 +129,8 @@ import 'target.dart';
|
||||
// Make sure the error goes away.
|
||||
// TODO(brianwilkerson): The error does not go away, possibly because the
|
||||
// file is not being reanalyzed.
|
||||
await resolveTestFile();
|
||||
assertErrorsInResult([error(diag.unusedImport, 0, 0)]);
|
||||
var result = await resolveTestFile();
|
||||
assertErrorsInTestResult(result, [error(diag.unusedImport, 0, 0)]);
|
||||
}
|
||||
|
||||
test_part() async {
|
||||
|
||||
@@ -281,7 +281,7 @@ class IgnoreInfoTest extends PubPackageResolutionTest {
|
||||
);
|
||||
|
||||
Future<List<IgnoredElement>> _parseIgnoredElements(String comment) async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
$comment
|
||||
int x = 1;
|
||||
''');
|
||||
|
||||
@@ -19,9 +19,13 @@ main() {
|
||||
class TopLevelDeclarationsTest extends PubPackageResolutionTest {
|
||||
/// Verifies that the located public export for [element] is the library with
|
||||
/// URI [libraryUri].
|
||||
Future<void> expectPublicExport(Element element, String libraryUri) async {
|
||||
Future<void> expectPublicExport(
|
||||
TestResolvedUnitResult result,
|
||||
Element element,
|
||||
String libraryUri,
|
||||
) async {
|
||||
var publicLibrary = await TopLevelDeclarations(
|
||||
result,
|
||||
result.analysisResult,
|
||||
).publiclyExporting(element);
|
||||
expect(publicLibrary?.firstFragment.source.uri.toString(), libraryUri);
|
||||
}
|
||||
@@ -34,7 +38,7 @@ class TopLevelDeclarationsTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/x.dart', "export 'src/x.dart';");
|
||||
|
||||
var element = result.findElement.topGet('x');
|
||||
await expectPublicExport(element, 'package:test/x.dart');
|
||||
await expectPublicExport(result, element, 'package:test/x.dart');
|
||||
}
|
||||
|
||||
test_publiclyExporting_lib() async {
|
||||
@@ -44,7 +48,7 @@ class TopLevelDeclarationsTest extends PubPackageResolutionTest {
|
||||
);
|
||||
|
||||
var element = result.findElement.class_('X');
|
||||
await expectPublicExport(element, 'package:test/x.dart');
|
||||
await expectPublicExport(result, element, 'package:test/x.dart');
|
||||
}
|
||||
|
||||
/// Verify we pick a library with the correct element and not just an element
|
||||
@@ -61,7 +65,7 @@ class TopLevelDeclarationsTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/x3.dart', "class X {}");
|
||||
|
||||
var element = result.findElement.class_('X');
|
||||
await expectPublicExport(element, 'package:test/x2.dart');
|
||||
await expectPublicExport(result, element, 'package:test/x2.dart');
|
||||
}
|
||||
|
||||
test_publiclyExporting_setter() async {
|
||||
@@ -72,7 +76,7 @@ class TopLevelDeclarationsTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/x.dart', "export 'src/x.dart';");
|
||||
|
||||
var element = result.findElement.topSet('x');
|
||||
await expectPublicExport(element, 'package:test/x.dart');
|
||||
await expectPublicExport(result, element, 'package:test/x.dart');
|
||||
}
|
||||
|
||||
test_publiclyExporting_src() async {
|
||||
@@ -83,6 +87,6 @@ class TopLevelDeclarationsTest extends PubPackageResolutionTest {
|
||||
newFile('$testPackageLibPath/x.dart', "export 'src/x.dart';");
|
||||
|
||||
var element = result.findElement.class_('X');
|
||||
await expectPublicExport(element, 'package:test/x.dart');
|
||||
await expectPublicExport(result, element, 'package:test/x.dart');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_compoundAssignment_simpleIdentifier_topLevel() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
@@ -183,7 +183,7 @@ main() {
|
||||
// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used.
|
||||
}
|
||||
''');
|
||||
_assertTypeAnnotations();
|
||||
_assertTypeAnnotations(result);
|
||||
}
|
||||
|
||||
test_forIn_identifier() async {
|
||||
@@ -492,7 +492,7 @@ main() {
|
||||
expect(yFragment.element.type, VoidTypeImpl.instance);
|
||||
}
|
||||
|
||||
void _assertTypeAnnotations() {
|
||||
void _assertTypeAnnotations(TestResolvedUnitResult result) {
|
||||
var code = result.content;
|
||||
var unit = result.unit;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// 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.
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
@@ -27,40 +26,36 @@ class InferredTypeTest extends PubPackageResolutionTest {
|
||||
return getFile('${sdkRoot.posixPath}/lib/async/async.dart');
|
||||
}
|
||||
|
||||
LibraryElement get _resultLibraryElement {
|
||||
return result.libraryElement;
|
||||
}
|
||||
|
||||
test_asyncClosureReturnType_flatten() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
Future<int> futureInt = null;
|
||||
// ^^^^
|
||||
// [diag.invalidAssignment] A value of type 'Null' can't be assigned to a variable of type 'Future<int>'.
|
||||
var f = () => futureInt;
|
||||
var g = () async => futureInt;
|
||||
''');
|
||||
var futureInt = _resultLibraryElement.topLevelVariables[0];
|
||||
var futureInt = result.libraryElement.topLevelVariables[0];
|
||||
expect(futureInt.name, 'futureInt');
|
||||
_assertTypeStr(futureInt.type, 'Future<int>');
|
||||
var f = _resultLibraryElement.topLevelVariables[1];
|
||||
var f = result.libraryElement.topLevelVariables[1];
|
||||
expect(f.name, 'f');
|
||||
_assertTypeStr(f.type, 'Future<int> Function()');
|
||||
var g = _resultLibraryElement.topLevelVariables[2];
|
||||
var g = result.libraryElement.topLevelVariables[2];
|
||||
expect(g.name, 'g');
|
||||
_assertTypeStr(g.type, 'Future<int> Function()');
|
||||
}
|
||||
|
||||
test_asyncClosureReturnType_future() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
var f = () async => 0;
|
||||
''');
|
||||
var f = _resultLibraryElement.topLevelVariables[0];
|
||||
var f = result.libraryElement.topLevelVariables[0];
|
||||
expect(f.name, 'f');
|
||||
_assertTypeStr(f.type, 'Future<int> Function()');
|
||||
}
|
||||
|
||||
test_asyncClosureReturnType_futureOr() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
import 'dart:async';
|
||||
FutureOr<int> futureOrInt = null;
|
||||
// ^^^^
|
||||
@@ -68,13 +63,13 @@ FutureOr<int> futureOrInt = null;
|
||||
var f = () => futureOrInt;
|
||||
var g = () async => futureOrInt;
|
||||
''');
|
||||
var futureOrInt = _resultLibraryElement.topLevelVariables[0];
|
||||
var futureOrInt = result.libraryElement.topLevelVariables[0];
|
||||
expect(futureOrInt.name, 'futureOrInt');
|
||||
_assertTypeStr(futureOrInt.type, 'FutureOr<int>');
|
||||
var f = _resultLibraryElement.topLevelVariables[1];
|
||||
var f = result.libraryElement.topLevelVariables[1];
|
||||
expect(f.name, 'f');
|
||||
_assertTypeStr(f.type, 'FutureOr<int> Function()');
|
||||
var g = _resultLibraryElement.topLevelVariables[2];
|
||||
var g = result.libraryElement.topLevelVariables[2];
|
||||
expect(g.name, 'g');
|
||||
_assertTypeStr(g.type, 'Future<int> Function()');
|
||||
}
|
||||
@@ -216,13 +211,13 @@ main() {
|
||||
}
|
||||
|
||||
test_blockBodiedLambdas_downwardsIncompatibleWithUpwardsInference_topLevel() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
String f() => null;
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'String'.
|
||||
var g = f;
|
||||
''');
|
||||
var g = _resultLibraryElement.topLevelVariables[0];
|
||||
var g = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(g.type, 'String Function()');
|
||||
}
|
||||
|
||||
@@ -410,23 +405,23 @@ main() {
|
||||
}
|
||||
|
||||
test_bottom() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
var v = null;
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'dynamic');
|
||||
}
|
||||
|
||||
test_bottom_inClosure() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
var v = () => null;
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'Null Function()');
|
||||
}
|
||||
|
||||
test_circularReference_viaClosures() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
var x = () => y;
|
||||
// ^
|
||||
// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x, y.
|
||||
@@ -435,8 +430,8 @@ var y = () => x;
|
||||
// [diag.topLevelCycle] The type of 'y' can't be inferred because it depends on itself through the cycle: x, y.
|
||||
''');
|
||||
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var y = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
var y = result.libraryElement.topLevelVariables[1];
|
||||
expect(x.name, 'x');
|
||||
expect(y.name, 'y');
|
||||
_assertTypeStr(x.type, 'dynamic');
|
||||
@@ -446,7 +441,7 @@ var y = () => x;
|
||||
@SkippedTest(reason: 'Element model rewrite')
|
||||
test_circularReference_viaClosures_initializerTypes() async {
|
||||
print('-' * 64);
|
||||
await assertErrorsInCode(
|
||||
var result = await assertErrorsInCode(
|
||||
'''
|
||||
var x = () => y;
|
||||
var y = () => x;
|
||||
@@ -454,8 +449,8 @@ var y = () => x;
|
||||
[error(diag.topLevelCycle, 4, 1), error(diag.topLevelCycle, 21, 1)],
|
||||
);
|
||||
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var y = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
var y = result.libraryElement.topLevelVariables[1];
|
||||
expect(x.name, 'x');
|
||||
expect(y.name, 'y');
|
||||
_assertTypeStr(x.type, 'dynamic');
|
||||
@@ -2068,7 +2063,7 @@ void main() {
|
||||
}
|
||||
|
||||
test_fieldRefersToStaticGetter() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
final x = _x;
|
||||
static int get _x => null;
|
||||
@@ -2076,12 +2071,12 @@ class C {
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function '_x' because it has a return type of 'int'.
|
||||
}
|
||||
''');
|
||||
var x = _resultLibraryElement.classes[0].fields[0];
|
||||
var x = result.libraryElement.classes[0].fields[0];
|
||||
_assertTypeStr(x.type, 'int');
|
||||
}
|
||||
|
||||
test_fieldRefersToTopLevelGetter() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
final x = y;
|
||||
}
|
||||
@@ -2089,7 +2084,7 @@ int get y => null;
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'y' because it has a return type of 'int'.
|
||||
''');
|
||||
var x = _resultLibraryElement.classes[0].fields[0];
|
||||
var x = result.libraryElement.classes[0].fields[0];
|
||||
_assertTypeStr(x.type, 'int');
|
||||
}
|
||||
|
||||
@@ -2880,7 +2875,7 @@ main() {
|
||||
}
|
||||
|
||||
test_genericMethods_inferGenericFunctionParameterType() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> extends D<T> {
|
||||
f<U>(x) { return null; }
|
||||
// ^^^^
|
||||
@@ -2893,12 +2888,12 @@ class D<T> {
|
||||
}
|
||||
typedef void F<V>(V v);
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.methods[0];
|
||||
var f = result.libraryElement.getClass('C')!.methods[0];
|
||||
_assertTypeStr(f.type, 'void Function(U) Function<U>(U)');
|
||||
}
|
||||
|
||||
test_genericMethods_inferGenericFunctionParameterType2() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C<T> extends D<T> {
|
||||
f<U>(g) => null;
|
||||
}
|
||||
@@ -2907,12 +2902,12 @@ abstract class D<T> {
|
||||
}
|
||||
typedef List<V> G<V>();
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.methods[0];
|
||||
var f = result.libraryElement.getClass('C')!.methods[0];
|
||||
_assertTypeStr(f.type, 'void Function<U>(List<U> Function())');
|
||||
}
|
||||
|
||||
test_genericMethods_inferGenericFunctionReturnType() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C<T> extends D<T> {
|
||||
f<U>(x) { return null; }
|
||||
// ^^^^
|
||||
@@ -2925,7 +2920,7 @@ class D<T> {
|
||||
}
|
||||
typedef V F<V>();
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.methods[0];
|
||||
var f = result.libraryElement.getClass('C')!.methods[0];
|
||||
_assertTypeStr(f.type, 'U Function() Function<U>(U)');
|
||||
}
|
||||
|
||||
@@ -3016,7 +3011,7 @@ main() {
|
||||
}
|
||||
|
||||
test_genericMethods_usesGreatestLowerBound_topLevel() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
typedef Iterable<num> F(int x);
|
||||
typedef List<int> G(double x);
|
||||
|
||||
@@ -3026,7 +3021,7 @@ T generic<T>(a(T _), b(T _)) => null;
|
||||
|
||||
var v = generic((F f) => null, (G g) => null);
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'List<int> Function(num)');
|
||||
}
|
||||
|
||||
@@ -3716,7 +3711,7 @@ main() {
|
||||
}
|
||||
|
||||
test_inferParameterType_setter_fromField() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C extends D {
|
||||
set foo(x) {}
|
||||
}
|
||||
@@ -3726,12 +3721,12 @@ class D {
|
||||
// [diag.notInitializedNonNullableInstanceField] Non-nullable instance field 'foo' must be initialized.
|
||||
}
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.setters[0];
|
||||
var f = result.libraryElement.getClass('C')!.setters[0];
|
||||
_assertTypeStr(f.type, 'void Function(int)');
|
||||
}
|
||||
|
||||
test_inferParameterType_setter_fromSetter() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C extends D {
|
||||
set foo(x) {}
|
||||
}
|
||||
@@ -3739,12 +3734,12 @@ class D {
|
||||
set foo(int x) {}
|
||||
}
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.setters[0];
|
||||
var f = result.libraryElement.getClass('C')!.setters[0];
|
||||
_assertTypeStr(f.type, 'void Function(int)');
|
||||
}
|
||||
|
||||
test_inferred_nonstatic_field_depends_on_static_field_complex() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
static var x = 'x';
|
||||
var y = {
|
||||
@@ -3753,25 +3748,25 @@ class C {
|
||||
};
|
||||
}
|
||||
''');
|
||||
var x = _resultLibraryElement.getClass('C')!.fields[0];
|
||||
var x = result.libraryElement.getClass('C')!.fields[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'String');
|
||||
var y = _resultLibraryElement.getClass('C')!.fields[1];
|
||||
var y = result.libraryElement.getClass('C')!.fields[1];
|
||||
expect(y.name, 'y');
|
||||
_assertTypeStr(y.type, 'Map<String, Map<String, String>>');
|
||||
}
|
||||
|
||||
test_inferred_nonstatic_field_depends_on_toplevel_var_simple() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
var x = 'x';
|
||||
class C {
|
||||
var y = x;
|
||||
}
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'String');
|
||||
var y = _resultLibraryElement.getClass('C')!.fields[0];
|
||||
var y = result.libraryElement.getClass('C')!.fields[0];
|
||||
expect(y.name, 'y');
|
||||
_assertTypeStr(y.type, 'String');
|
||||
}
|
||||
@@ -3801,7 +3796,7 @@ main() {
|
||||
}
|
||||
|
||||
test_inferredType_cascade() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int a;
|
||||
// ^
|
||||
@@ -3813,12 +3808,12 @@ class A {
|
||||
}
|
||||
var v = new A()..a = 1..b.add(2)..m();
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'A');
|
||||
}
|
||||
|
||||
test_inferredType_customBinaryOp() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
bool operator*(C other) => true;
|
||||
}
|
||||
@@ -3827,13 +3822,13 @@ C c;
|
||||
// [diag.notInitializedNonNullableVariable] The non-nullable variable 'c' must be initialized.
|
||||
var x = c*c;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[1];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool');
|
||||
}
|
||||
|
||||
test_inferredType_customBinaryOp_viaInterface() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class I {
|
||||
bool operator*(C other) => true;
|
||||
}
|
||||
@@ -3843,7 +3838,7 @@ C c;
|
||||
// [diag.notInitializedNonNullableVariable] The non-nullable variable 'c' must be initialized.
|
||||
var x = c*c;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[1];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool');
|
||||
}
|
||||
@@ -3890,7 +3885,7 @@ main() {
|
||||
}
|
||||
|
||||
test_inferredType_customUnaryOp() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
bool operator-() => true;
|
||||
}
|
||||
@@ -3899,13 +3894,13 @@ C c;
|
||||
// [diag.notInitializedNonNullableVariable] The non-nullable variable 'c' must be initialized.
|
||||
var x = -c;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[1];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool');
|
||||
}
|
||||
|
||||
test_inferredType_customUnaryOp_viaInterface() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class I {
|
||||
bool operator-() => true;
|
||||
}
|
||||
@@ -3915,13 +3910,13 @@ C c;
|
||||
// [diag.notInitializedNonNullableVariable] The non-nullable variable 'c' must be initialized.
|
||||
var x = -c;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[1];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool');
|
||||
}
|
||||
|
||||
test_inferredType_extractMethodTearOff() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
bool g() => true;
|
||||
}
|
||||
@@ -3930,13 +3925,13 @@ C f() => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'C'.
|
||||
var x = f().g;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool Function()');
|
||||
}
|
||||
|
||||
test_inferredType_extractMethodTearOff_viaInterface() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class I {
|
||||
bool g() => true;
|
||||
}
|
||||
@@ -3946,21 +3941,21 @@ C f() => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'C'.
|
||||
var x = f().g;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool Function()');
|
||||
}
|
||||
|
||||
test_inferredType_fromTopLevelExecutableTearoff() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
var v = print;
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'void Function(Object?)');
|
||||
}
|
||||
|
||||
test_inferredType_invokeMethod() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
bool g() => true;
|
||||
}
|
||||
@@ -3969,13 +3964,13 @@ C f() => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'C'.
|
||||
var x = f().g();
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool');
|
||||
}
|
||||
|
||||
test_inferredType_invokeMethod_viaInterface() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class I {
|
||||
bool g() => true;
|
||||
}
|
||||
@@ -3985,49 +3980,49 @@ C f() => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'C'.
|
||||
var x = f().g();
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'bool');
|
||||
}
|
||||
|
||||
test_inferredType_isEnum() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
enum E { v1 }
|
||||
final x = E.v1;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'E');
|
||||
}
|
||||
|
||||
test_inferredType_isEnumValues() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
enum E { v1 }
|
||||
final x = E.values;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'List<E>');
|
||||
}
|
||||
|
||||
test_inferredType_isTypedef() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
typedef void F();
|
||||
final x = <String, F>{};
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'Map<String, void Function()>');
|
||||
}
|
||||
|
||||
test_inferredType_isTypedef_parameterized() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
typedef T F<T>();
|
||||
final x = <String, F<int>>{};
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'Map<String, int Function()>');
|
||||
}
|
||||
|
||||
test_inferredType_usesSyntheticFunctionType() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
int f() => null;
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
@@ -4036,12 +4031,12 @@ String g() => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'g' because it has a return type of 'String'.
|
||||
var v = [f, g];
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'List<Object Function()>');
|
||||
}
|
||||
|
||||
test_inferredType_usesSyntheticFunctionType_functionTypedParam() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
int f(int x(String y)) => null;
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
@@ -4050,12 +4045,12 @@ String g(int x(String y)) => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'g' because it has a return type of 'String'.
|
||||
var v = [f, g];
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'List<Object Function(int Function(String))>');
|
||||
}
|
||||
|
||||
test_inferredType_usesSyntheticFunctionType_namedParam() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
int f({int x}) => null;
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameter] The parameter 'x' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
@@ -4068,12 +4063,12 @@ String g({int x}) => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'g' because it has a return type of 'String'.
|
||||
var v = [f, g];
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'List<Object Function({int x})>');
|
||||
}
|
||||
|
||||
test_inferredType_usesSyntheticFunctionType_positionalParam() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
int f([int x]) => null;
|
||||
// ^
|
||||
// [diag.missingDefaultValueForParameterPositional] The parameter 'x' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
|
||||
@@ -4086,12 +4081,12 @@ String g([int x]) => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'g' because it has a return type of 'String'.
|
||||
var v = [f, g];
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'List<Object Function([int])>');
|
||||
}
|
||||
|
||||
test_inferredType_usesSyntheticFunctionType_requiredParam() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
int f(int x) => null;
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'int'.
|
||||
@@ -4100,46 +4095,46 @@ String g(int x) => null;
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'g' because it has a return type of 'String'.
|
||||
var v = [f, g];
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'List<Object Function(int)>');
|
||||
}
|
||||
|
||||
test_inferredType_viaClosure_multipleLevelsOfNesting() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
static final f = (bool b) =>
|
||||
(int i) => {i: b};
|
||||
}
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.fields[0];
|
||||
var f = result.libraryElement.getClass('C')!.fields[0];
|
||||
_assertTypeStr(f.type, 'Map<int, bool> Function(int) Function(bool)');
|
||||
}
|
||||
|
||||
test_inferredType_viaClosure_typeDependsOnArgs() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
static final f = (bool b) => b;
|
||||
}
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.fields[0];
|
||||
var f = result.libraryElement.getClass('C')!.fields[0];
|
||||
_assertTypeStr(f.type, 'bool Function(bool)');
|
||||
}
|
||||
|
||||
test_inferredType_viaClosure_typeIndependentOfArgs_field() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
static final f = (bool b) => 1;
|
||||
}
|
||||
''');
|
||||
var f = _resultLibraryElement.getClass('C')!.fields[0];
|
||||
var f = result.libraryElement.getClass('C')!.fields[0];
|
||||
_assertTypeStr(f.type, 'int Function(bool)');
|
||||
}
|
||||
|
||||
test_inferredType_viaClosure_typeIndependentOfArgs_topLevel() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
final f = (bool b) => 1;
|
||||
''');
|
||||
var f = _resultLibraryElement.topLevelVariables[0];
|
||||
var f = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(f.type, 'int Function(bool)');
|
||||
}
|
||||
|
||||
@@ -4708,11 +4703,11 @@ test() {
|
||||
}
|
||||
|
||||
test_inferVariableVoid() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
void f() {}
|
||||
var x = f();
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
expect(x.name, 'x');
|
||||
_assertTypeStr(x.type, 'void');
|
||||
}
|
||||
@@ -4799,10 +4794,10 @@ test2() {
|
||||
}
|
||||
|
||||
test_listLiteralsCanInferNull_topLevel() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
var x = [null];
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'List<Null>');
|
||||
}
|
||||
|
||||
@@ -4921,15 +4916,15 @@ test1() {
|
||||
}
|
||||
|
||||
test_mapLiteralsCanInferNull_topLevel() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
var x = { null: null };
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'Map<Null, Null>');
|
||||
}
|
||||
|
||||
test_methodCall_withTypeArguments_instanceMethod() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
D<T> f<T>() => null;
|
||||
// ^^^^
|
||||
@@ -4938,12 +4933,12 @@ class C {
|
||||
class D<T> {}
|
||||
var f = new C().f<int>();
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'D<int>');
|
||||
}
|
||||
|
||||
test_methodCall_withTypeArguments_instanceMethod_identifierSequence() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
D<T> f<T>() => null;
|
||||
// ^^^^
|
||||
@@ -4955,13 +4950,13 @@ C c;
|
||||
// [diag.notInitializedNonNullableVariable] The non-nullable variable 'c' must be initialized.
|
||||
var f = c.f<int>();
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[1];
|
||||
var v = result.libraryElement.topLevelVariables[1];
|
||||
expect(v.name, 'f');
|
||||
_assertTypeStr(v.type, 'D<int>');
|
||||
}
|
||||
|
||||
test_methodCall_withTypeArguments_staticMethod() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
class C {
|
||||
static D<T> f<T>() => null;
|
||||
// ^^^^
|
||||
@@ -4970,19 +4965,19 @@ class C {
|
||||
class D<T> {}
|
||||
var f = C.f<int>();
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'D<int>');
|
||||
}
|
||||
|
||||
test_methodCall_withTypeArguments_topLevelFunction() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
D<T> f<T>() => null;
|
||||
// ^^^^
|
||||
// [diag.returnOfInvalidTypeFromFunction] A value of type 'Null' can't be returned from the function 'f' because it has a return type of 'D<T>'.
|
||||
class D<T> {}
|
||||
var g = f<int>();
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'D<int>');
|
||||
}
|
||||
|
||||
@@ -5155,11 +5150,11 @@ void main() {
|
||||
}
|
||||
|
||||
test_referenceToTypedef() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
typedef void F();
|
||||
final x = F;
|
||||
''');
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(x.type, 'Type');
|
||||
}
|
||||
|
||||
@@ -5269,7 +5264,7 @@ class C<T extends num> {
|
||||
}
|
||||
|
||||
test_staticMethod_tearoff() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
const v = C.f;
|
||||
class C {
|
||||
static int f(String s) => null;
|
||||
@@ -5277,7 +5272,7 @@ class C {
|
||||
// [diag.returnOfInvalidTypeFromMethod] A value of type 'Null' can't be returned from the method 'f' because it has a return type of 'int'.
|
||||
}
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
_assertTypeStr(v.type, 'int Function(String)');
|
||||
}
|
||||
|
||||
@@ -5297,25 +5292,25 @@ main() {
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_constructorCall_explicitDynamicParam() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C<T> {
|
||||
C(T x());
|
||||
}
|
||||
var v = new C<dynamic>(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'C<dynamic>');
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_constructorCall_explicitTypeParam() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C<T> {
|
||||
C(T x());
|
||||
}
|
||||
var v = new C<int>(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'C<int>');
|
||||
}
|
||||
@@ -5341,23 +5336,23 @@ main() {
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_constructorCall_noTypeParam() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
C(x());
|
||||
}
|
||||
var v = new C(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'C');
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_functionCall_explicitDynamicParam() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
List<T> f<T>(T g()) => <T>[g()];
|
||||
var v = f<dynamic>(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'List<dynamic>');
|
||||
}
|
||||
@@ -5365,31 +5360,31 @@ var v = f<dynamic>(() { return 1; });
|
||||
// Failing without null safety.
|
||||
test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr1() async {
|
||||
// Note: (f<dynamic>) is not a valid syntax.
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
List<T> f<T>(T g()) => <T>[g()];
|
||||
var v = (f<dynamic>)(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'List<dynamic>');
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_functionCall_explicitDynamicParam_viaExpr2() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
List<T> f<T>(T g()) => <T>[g()];
|
||||
var v = (f)<dynamic>(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'List<dynamic>');
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_functionCall_explicitTypeParam() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
List<T> f<T>(T g()) => <T>[g()];
|
||||
var v = f<int>(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'List<int>');
|
||||
}
|
||||
@@ -5399,21 +5394,21 @@ var v = f<int>(() { return 1; });
|
||||
// Failing without null safety.
|
||||
test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr1() async {
|
||||
// Note: (f<int>) is not a valid syntax.
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
List<T> f<T>(T g()) => <T>[g()];
|
||||
var v = (f<int>)(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'List<int>');
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
List<T> f<T>(T g()) => <T>[g()];
|
||||
var v = (f)<int>(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'List<int>');
|
||||
}
|
||||
@@ -5618,19 +5613,19 @@ main() {
|
||||
}
|
||||
|
||||
test_unsafeBlockClosureInference_methodCall_noTypeParam() async {
|
||||
await resolveTestCodeWithDiagnostics('''
|
||||
var result = await resolveTestCodeWithDiagnostics('''
|
||||
class C {
|
||||
double f(x) => 1.0;
|
||||
}
|
||||
var v = new C().f(() { return 1; });
|
||||
''');
|
||||
var v = _resultLibraryElement.topLevelVariables[0];
|
||||
var v = result.libraryElement.topLevelVariables[0];
|
||||
expect(v.name, 'v');
|
||||
_assertTypeStr(v.type, 'double');
|
||||
}
|
||||
|
||||
test_voidReturnTypeEquivalentToDynamic() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
var result = await resolveTestCodeWithDiagnostics(r'''
|
||||
T run<T>(T f()) {
|
||||
print("running");
|
||||
var t = f();
|
||||
@@ -5658,8 +5653,8 @@ main() {
|
||||
}
|
||||
''');
|
||||
|
||||
var x = _resultLibraryElement.topLevelVariables[0];
|
||||
var y = _resultLibraryElement.topLevelVariables[1];
|
||||
var x = result.libraryElement.topLevelVariables[0];
|
||||
var y = result.libraryElement.topLevelVariables[1];
|
||||
_assertTypeStr(x.type, 'dynamic');
|
||||
_assertTypeStr(y.type, 'void');
|
||||
}
|
||||
@@ -5668,7 +5663,7 @@ main() {
|
||||
String code,
|
||||
List<ExpectedDiagnostic> expectedDiagnostics,
|
||||
) async {
|
||||
await resolveTestCode(code);
|
||||
var result = await resolveTestCode(code);
|
||||
assertErrorsInList(
|
||||
result.diagnostics.where((e) {
|
||||
return e.diagnosticCode != diag.unusedLocalVariable &&
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -181,11 +181,16 @@ language = struct(
|
||||
)
|
||||
''');
|
||||
|
||||
await resolveFileCode('$myPackageRootPath/lib/a.dart', '');
|
||||
_assertLanguageVersion(package: Version.parse('3.1.0'), override: null);
|
||||
var result = await resolveFileCode('$myPackageRootPath/lib/a.dart', '');
|
||||
_assertLanguageVersion(
|
||||
result,
|
||||
package: Version.parse('3.1.0'),
|
||||
override: null,
|
||||
);
|
||||
}
|
||||
|
||||
void _assertLanguageVersion({
|
||||
void _assertLanguageVersion(
|
||||
TestResolvedUnitResult result, {
|
||||
required Version package,
|
||||
required Version? override,
|
||||
}) {
|
||||
|
||||
@@ -466,8 +466,8 @@ class DocumentationValidator {
|
||||
) async {
|
||||
var test = _SnippetTest(snippet);
|
||||
test.setUp();
|
||||
await test.resolveTestFile();
|
||||
var diagnostics = test.result.diagnostics;
|
||||
var result = await test.resolveTestFile();
|
||||
var diagnostics = result.diagnostics;
|
||||
var filteredDiagnostics = <Diagnostic>[];
|
||||
var errorCount = 0;
|
||||
var unneededIgnores = snippet.ignores.toList();
|
||||
|
||||
Reference in New Issue
Block a user