Skip to content

Commit a2acd7b

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
More testing of strict modes for extension types
Fixes #53982 Change-Id: Ie28c3ad80c8f9209551d336d49386236d26bc620 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335280 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 2cce183 commit a2acd7b

10 files changed

+78
-7
lines changed

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ mixin WithStrictCastsMixin on PubPackageResolutionTest {
580580

581581
writeTestPackageAnalysisOptionsFile(
582582
AnalysisOptionsFileConfig(
583+
experiments: experiments,
583584
strictCasts: true,
584585
),
585586
);

pkg/analyzer/test/src/diagnostics/argument_type_not_assignable_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,17 @@ main() {
800800
@reflectiveTest
801801
class ArgumentTypeNotAssignableWithStrictCastsTest
802802
extends PubPackageResolutionTest with WithStrictCastsMixin {
803+
test_extensionTypePrimaryConstructor() async {
804+
await assertErrorsWithStrictCasts('''
805+
extension type E(int i) {}
806+
807+
dynamic a;
808+
var e = E(a);
809+
''', [
810+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 49, 1),
811+
]);
812+
}
813+
803814
test_functionCall() async {
804815
await assertErrorsWithStrictCasts('''
805816
void f(int i) {}

pkg/analyzer/test/src/diagnostics/inference_failure_on_collection_literal_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class InferenceFailureOnCollectionLiteralTest extends PubPackageResolutionTest {
2020
super.setUp();
2121
writeTestPackageAnalysisOptionsFile(
2222
AnalysisOptionsFileConfig(
23+
experiments: experiments,
2324
strictInference: true,
2425
),
2526
);

pkg/analyzer/test/src/diagnostics/inference_failure_on_function_invocation_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class InferenceFailureOnFunctionInvocationTest
2323
super.setUp();
2424
writeTestPackageAnalysisOptionsFile(
2525
AnalysisOptionsFileConfig(
26+
experiments: experiments,
2627
strictInference: true,
2728
),
2829
);

pkg/analyzer/test/src/diagnostics/inference_failure_on_generic_invocation_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class InferenceFailureOnGenericInvocationTest extends PubPackageResolutionTest {
2222
super.setUp();
2323
writeTestPackageAnalysisOptionsFile(
2424
AnalysisOptionsFileConfig(
25+
experiments: experiments,
2526
strictInference: true,
2627
),
2728
);

pkg/analyzer/test/src/diagnostics/inference_failure_on_instance_creation_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class InferenceFailureOnInstanceCreationTest extends PubPackageResolutionTest {
2121
super.setUp();
2222
writeTestPackageAnalysisOptionsFile(
2323
AnalysisOptionsFileConfig(
24+
experiments: experiments,
2425
strictInference: true,
2526
),
2627
);
@@ -83,6 +84,17 @@ void f() {
8384
''');
8485
}
8586

87+
test_extensionType() async {
88+
await assertErrorsInCode('''
89+
extension type E<T>(int i) {}
90+
void f() {
91+
E(1);
92+
}
93+
''', [
94+
error(WarningCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION, 43, 1),
95+
]);
96+
}
97+
8698
test_genericMetadata_missingTypeArg() async {
8799
await assertErrorsInCode(r'''
88100
class C<T> {

pkg/analyzer/test/src/diagnostics/inference_failure_on_uninitialized_variable_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class InferenceFailureOnUninitializedVariableTest
2323
super.setUp();
2424
writeTestPackageAnalysisOptionsFile(
2525
AnalysisOptionsFileConfig(
26+
experiments: experiments,
2627
strictInference: true,
2728
),
2829
);

pkg/analyzer/test/src/diagnostics/inference_failure_on_untyped_parameter_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class InferenceFailureOnUntypedParameterTest extends PubPackageResolutionTest {
2222
super.setUp();
2323
writeTestPackageAnalysisOptionsFile(
2424
AnalysisOptionsFileConfig(
25+
experiments: experiments,
2526
strictInference: true,
2627
),
2728
);

pkg/analyzer/test/src/diagnostics/invalid_assignment_test.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,12 +1085,30 @@ class B<T> {
10851085
@reflectiveTest
10861086
class InvalidAssignmentWithStrictCastsTest extends PubPackageResolutionTest
10871087
with WithStrictCastsMixin {
1088-
test_assignment() async {
1088+
test_functionType() async {
1089+
await assertErrorsWithStrictCasts('''
1090+
dynamic a;
1091+
void Function(int i) f = a;
1092+
''', [
1093+
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 36, 1),
1094+
]);
1095+
}
1096+
1097+
test_interfaceType() async {
10891098
await assertErrorsWithStrictCasts('''
10901099
dynamic a;
10911100
int b = a;
10921101
''', [
10931102
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 19, 1),
10941103
]);
10951104
}
1105+
1106+
test_recordType() async {
1107+
await assertErrorsWithStrictCasts('''
1108+
dynamic a;
1109+
(int i, ) r = a;
1110+
''', [
1111+
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 25, 1),
1112+
]);
1113+
}
10961114
}

pkg/analyzer/test/src/diagnostics/strict_raw_type_test.dart

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,47 @@ void g(C a) {}
9090
extension type E<T>(int i) {}
9191
9292
void f() {
93-
var e = <List<E>>[];
93+
<List<E>>[];
9494
}
9595
''', [
96-
error(WarningCode.UNUSED_LOCAL_VARIABLE, 48, 1),
97-
error(WarningCode.STRICT_RAW_TYPE, 58, 1),
96+
error(WarningCode.STRICT_RAW_TYPE, 50, 1),
9897
]);
9998
}
10099

101100
test_genericTypeArgument_extensionType_withTypeArg() async {
102-
await assertErrorsInCode(r'''
101+
await assertNoErrorsInCode(r'''
103102
extension type E<T>(int i) {}
104103
105104
void f() {
106-
var e = <List<E<int>>>[];
105+
<List<E<int>>>[];
107106
}
107+
''');
108+
}
109+
110+
test_genericTypeArgument_extensionTypeImplements_missingTypeArg() async {
111+
await assertErrorsInCode(r'''
112+
extension type E(List<int> i) implements Iterable {}
113+
''', [
114+
error(WarningCode.STRICT_RAW_TYPE, 41, 8),
115+
]);
116+
}
117+
118+
test_genericTypeArgument_extensionTypeImplementsExtensionType_missingTypeArg() async {
119+
await assertErrorsInCode(r'''
120+
121+
extension type E<T>(Iterable<T> i) {}
122+
123+
extension type F(List<int> j) implements E {}
124+
''', [
125+
error(WarningCode.STRICT_RAW_TYPE, 81, 1),
126+
]);
127+
}
128+
129+
test_genericTypeArgument_extensionTypeRepresentationType_missingTypeArg() async {
130+
await assertErrorsInCode(r'''
131+
extension type E(List i) {}
108132
''', [
109-
error(WarningCode.UNUSED_LOCAL_VARIABLE, 48, 1),
133+
error(WarningCode.STRICT_RAW_TYPE, 17, 4),
110134
]);
111135
}
112136

0 commit comments

Comments
 (0)