Skip to content

Commit de2ce48

Browse files
askeksacommit-bot@chromium.org
authored andcommitted
Finish type variables earlier so their bounds are available when building the program.
Check bounds in verifier. Fixed an inconsistency in the printing of parent nodes in the verifier. Closes #30838 Closes #31213 Closes #31700 Change-Id: I328ca2c5bfa01a6753a806abd2510c98fa2b7cfe Reviewed-on: https://dart-review.googlesource.com/22500 Commit-Queue: Aske Simon Christensen <[email protected]> Reviewed-by: Peter von der Ahé <[email protected]>
1 parent 0e2ca15 commit de2ce48

17 files changed

+155
-39
lines changed

pkg/analyzer/test/generated/non_error_resolver_kernel_test.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,6 @@ class NonErrorResolverTest_Kernel extends NonErrorResolverTest_Driver {
197197
return super.test_genericTypeAlias_fieldAndReturnType_noTypeParameters();
198198
}
199199

200-
@override
201-
@failingTest
202-
@FastaProblem('https://github.com/dart-lang/sdk/issues/30838')
203-
test_genericTypeAlias_fieldAndReturnType_typeParameters_arguments() async {
204-
return super
205-
.test_genericTypeAlias_fieldAndReturnType_typeParameters_arguments();
206-
}
207-
208-
@override
209-
@failingTest
210-
@FastaProblem('https://github.com/dart-lang/sdk/issues/30838')
211-
test_genericTypeAlias_fieldAndReturnType_typeParameters_noArguments() async {
212-
return super
213-
.test_genericTypeAlias_fieldAndReturnType_typeParameters_noArguments();
214-
}
215-
216200
@override
217201
@failingTest
218202
@potentialAnalyzerProblem

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9525,31 +9525,19 @@ class D {
95259525
test_typedef_type_parameters_bound_recursive() async {
95269526
shouldCompareLibraryElements = false;
95279527
var library = await checkLibrary('typedef void F<T extends F>();');
9528-
if (isSharedFrontEnd) {
9529-
// Typedefs cannot reference themselves.
9530-
checkElementText(library, r'''
9531-
typedef F<T extends dynamic> = void Function();
9532-
''');
9533-
} else {
9534-
checkElementText(library, r'''
9528+
// Typedefs cannot reference themselves.
9529+
checkElementText(library, r'''
95359530
typedef F<T extends () → void> = void Function();
95369531
''');
9537-
}
95389532
}
95399533

95409534
test_typedef_type_parameters_bound_recursive2() async {
95419535
shouldCompareLibraryElements = false;
95429536
var library = await checkLibrary('typedef void F<T extends List<F>>();');
9543-
if (isSharedFrontEnd) {
9544-
// Typedefs cannot reference themselves.
9545-
checkElementText(library, r'''
9546-
typedef F<T extends List<dynamic>> = void Function();
9547-
''');
9548-
} else {
9549-
checkElementText(library, r'''
9537+
// Typedefs cannot reference themselves.
9538+
checkElementText(library, r'''
95509539
typedef F<T extends List<() → void>> = void Function();
95519540
''');
9552-
}
95539541
}
95549542

95559543
test_typedef_type_parameters_f_bound_complex() async {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class C {
383383
}
384384

385385
@failingTest
386-
@FastaProblem('https://github.com/dart-lang/sdk/issues/31213')
386+
@FastaProblem('https://github.com/dart-lang/sdk/issues/31711')
387387
test_typedef_generic_asFieldType() async {
388388
await super.test_typedef_generic_asFieldType();
389389
}

pkg/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class KernelFunctionTypeAliasBuilder
6666
builtType.typedefReference = target.reference;
6767
if (typeVariables != null) {
6868
for (KernelTypeVariableBuilder tv in typeVariables) {
69-
tv.parameter.bound = tv?.bound?.build(library);
69+
// Follow bound in order to find all cycles
70+
tv.bound?.build(library);
7071
target.typeParameters.add(tv.parameter..parent = target);
7172
}
7273
}

pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ class KernelTarget extends TargetImplementation {
231231
loader.resolveTypes();
232232
List<SourceClassBuilder> myClasses = collectMyClasses();
233233
loader.checkSemantics(myClasses);
234+
loader.finishTypeVariables(objectClassBuilder);
234235
loader.buildProgram();
235236
installDefaultSupertypes();
236237
installDefaultConstructors(myClasses);
237238
loader.resolveConstructors();
238-
loader.finishTypeVariables(objectClassBuilder);
239239
program =
240240
link(new List<Library>.from(loader.libraries), nameRoot: nameRoot);
241241
if (metadataCollector != null) {

pkg/front_end/testcases/ast_builder.status

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ regress/issue_29979: Crash
132132
regress/issue_29983: Crash
133133
regress/issue_29984: Crash
134134
regress/issue_29985: Crash
135+
regress/issue_30838: Crash
135136
regress/issue_31155: Crash # Issue 31155.
136137
regress/issue_31157: Crash
137138
regress/issue_31180: Crash
138139
regress/issue_31184: Crash
139140
regress/issue_31186: Crash
140141
regress/issue_31187: Crash
141142
regress/issue_31198: Crash
143+
regress/issue_31213: Crash
142144
reorder_super: Crash
143145
runtime_checks/implicit_downcast_assert_initializer: Crash
144146
runtime_checks/implicit_downcast_constructor_initializer: Crash
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
typedef Foo<S> = S Function<T>(T x);
6+
int foo<T>(T x) => 3;
7+
Foo<int> bar() => foo;
8+
void test1() {
9+
bar()<String>("hello");
10+
}
11+
12+
class A {
13+
Foo<int> f;
14+
void test() {
15+
f<String>("hello");
16+
}
17+
}
18+
19+
main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
typedef Foo<S extends core::Object> = <T extends core::Object>(T) → S;
6+
class A extends core::Object {
7+
field <T extends core::Object>(T) → core::int f = null;
8+
default constructor •() → void
9+
: super core::Object::•()
10+
;
11+
method test() → void {
12+
this.f<core::String>("hello");
13+
}
14+
}
15+
static method foo<T extends core::Object>(self::foo::T x) → core::int
16+
return 3;
17+
static method bar() → <T extends core::Object>(T) → core::int
18+
return self::foo;
19+
static method test1() → void {
20+
self::bar().call<core::String>("hello");
21+
}
22+
static method main() → dynamic {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
typedef Foo<S extends core::Object> = <T extends core::Object>(T) → S;
6+
class A extends core::Object {
7+
field <T extends core::Object>(T) → core::int f;
8+
default constructor •() → void
9+
;
10+
method test() → void
11+
;
12+
}
13+
static method foo<T extends core::Object>(self::foo::T x) → core::int
14+
;
15+
static method bar() → <T extends core::Object>(T) → core::int
16+
;
17+
static method test1() → void
18+
;
19+
static method main() → dynamic
20+
;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
typedef Foo<S extends core::Object> = <T extends core::Object>(T) → S;
6+
class A extends core::Object {
7+
field <T extends core::Object>(T) → core::int f = null;
8+
default constructor •() → void
9+
: super core::Object::•()
10+
;
11+
method test() → void {
12+
this.{self::A::f}<core::String>("hello");
13+
}
14+
}
15+
static method foo<T extends core::Object>(self::foo::T x) → core::int
16+
return 3;
17+
static method bar() → <T extends core::Object>(T) → core::int
18+
return self::foo;
19+
static method test1() → void {
20+
self::bar().call<core::String>("hello");
21+
}
22+
static method main() → dynamic {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
typedef C<A, K> = int Function<B>(A x, K y, B v);
6+
typedef D<K> = C<A, K> Function<A>(int z);
7+
8+
dynamic producer<K>() {
9+
return <A>(int v1) {
10+
return <B>(A v2, K v3, B v4) => 0;
11+
};
12+
}
13+
14+
main() {
15+
assert(producer<String>() is D<String>);
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
typedef C<A extends core::Object, K extends core::Object> = <B extends core::Object>(A, K, B) → core::int;
6+
typedef D<K extends core::Object> = <A extends core::Object>(core::int) → <B extends core::Object>(A, K, B) → core::int;
7+
static method producer<K extends core::Object>() → dynamic {
8+
return <A extends core::Object>(core::int v1) → dynamic {
9+
return <B extends core::Object>(A v2, self::producer::K v3, B v4) → dynamic => 0;
10+
};
11+
}
12+
static method main() → dynamic {
13+
assert(self::producer<core::String>() is <A extends core::Object>(core::int) → <B extends core::Object>(A, core::String, B) → core::int);
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
typedef C<A extends core::Object, K extends core::Object> = <B extends core::Object>(A, K, B) → core::int;
6+
typedef D<K extends core::Object> = <A extends core::Object>(core::int) → <B extends core::Object>(A, K, B) → core::int;
7+
static method producer<K extends core::Object>() → dynamic
8+
;
9+
static method main() → dynamic
10+
;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
typedef C<A extends core::Object, K extends core::Object> = <B extends core::Object>(A, K, B) → core::int;
6+
typedef D<K extends core::Object> = <A extends core::Object>(core::int) → <B extends core::Object>(A, K, B) → core::int;
7+
static method producer<K extends core::Object>() → dynamic {
8+
return <A extends core::Object>(core::int v1) → <B extends core::Object>(A, self::producer::K, B) → core::int {
9+
return <B extends core::Object>(A v2, self::producer::K v3, B v4) → core::int => 0;
10+
};
11+
}
12+
static method main() → dynamic {
13+
assert(self::producer<core::String>() is <A extends core::Object>(core::int) → <B extends core::Object>(A, core::String, B) → core::int);
14+
}

pkg/kernel/lib/type_algebra.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class _InnerTypeSubstitutor extends _TypeSubstitutor {
340340
TypeParameter freshTypeParameter(TypeParameter node) {
341341
var fresh = new TypeParameter(node.name);
342342
substitution[node] = new TypeParameterType(fresh);
343-
fresh.bound = node.bound != null ? visit(node.bound) : null;
343+
fresh.bound = visit(node.bound);
344344
return fresh;
345345
}
346346
}

pkg/kernel/lib/verifier.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class VerifyingVisitor extends RecursiveVisitor {
145145
void declareTypeParameters(List<TypeParameter> parameters) {
146146
for (int i = 0; i < parameters.length; ++i) {
147147
var parameter = parameters[i];
148+
if (parameter.bound == null) {
149+
problem(
150+
currentParent, "Missing bound for type parameter '$parameter'.");
151+
}
148152
if (!typeParametersInScope.add(parameter)) {
149153
problem(parameter, "Type parameter '$parameter' redeclared.");
150154
}
@@ -577,7 +581,7 @@ class VerifyingVisitor extends RecursiveVisitor {
577581
problem(
578582
currentParent,
579583
"Type parameter '$parameter' referenced from"
580-
" static context, parent is '${parameter.parent}'.");
584+
" static context, parent is: '${parameter.parent}'.");
581585
}
582586
}
583587

pkg/kernel/test/verify_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ main() {
104104
negativeTest(
105105
'Class type parameter in static method',
106106
"Type parameter 'test_lib::TestClass::T' referenced from static context,"
107-
" parent is 'test_lib::TestClass'.", (TestHarness test) {
107+
" parent is: 'test_lib::TestClass'.", (TestHarness test) {
108108
return new Procedure(
109109
new Name('bar'),
110110
ProcedureKind.Method,
@@ -115,7 +115,7 @@ main() {
115115
negativeTest(
116116
'Class type parameter in static field',
117117
"Type parameter 'test_lib::TestClass::T' referenced from static context,"
118-
" parent is 'test_lib::TestClass'.", (TestHarness test) {
118+
" parent is: 'test_lib::TestClass'.", (TestHarness test) {
119119
return new Field(new Name('field'),
120120
initializer:
121121
new TypeLiteral(new TypeParameterType(test.classTypeParameter)),

0 commit comments

Comments
 (0)