Roll dart_style 2.1.0 into the SDK.

This only adds support for the new constructor tear-offs. No existing
formatted code should be changed, so it should be safe to land this
without coordinating a roll of the pre-built SDK.

Change-Id: Ic3fd04f12ef5a1f67760d3edc78c5f419ba1c3c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210285
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
This commit is contained in:
Robert Nystrom 2021-08-17 00:30:11 +00:00 committed by commit-bot@chromium.org
parent cfb057ddca
commit 5657acfc76
43 changed files with 423 additions and 35 deletions

2
DEPS
View file

@ -103,7 +103,7 @@ vars = {
# and land the review.
#
# For more details, see https://github.com/dart-lang/sdk/issues/30164
"dart_style_rev": "06bfd19593ed84dd288f67e02c6a753e6516288a",
"dart_style_rev": "14d9b6fd58cc4744676c12be3cc5eee2a779db82",
"dartdoc_rev" : "5f39ec674d81f5c199151d823fa4ecd01fc59eb2",
"devtools_rev" : "64cffbed6366329ad05e44d48fa2298367643bb6",

View file

@ -1,4 +1,6 @@
T func<T>(T value) => value;
int Function(int) f = funcValue.call;
int Function(int) g = funcValue.call<int>;
main() {}
test(Function f) {}
var funcValue = func;

View file

@ -3,6 +3,7 @@ class A<T> {
factory A.fact() => new A();
factory A.redirect() = A;
}
typedef B<T> = A<T>;
typedef C<T> = A<int>;
const a = A.new;

View file

@ -0,0 +1,27 @@
class A<T> {
A();
factory A.fact() => new A();
factory A.redirect() = A;
}
const a = A.new;
const b = A<int>.new;
const c = A.fact;
const d = A<int>.fact;
const e = A.redirect;
const f = A<int>.redirect;
const g = B.new;
const h = B<int>.new;
const i = B.fact;
const j = B<int>.fact;
const k = B.redirect;
const l = B<int>.redirect;
const m = C.new;
const n = C<int>.new;
const o = C.fact;
const p = C<int>.fact;
const q = C.redirect;
const r = C<int>.redirect;
main() {}
typedef B<T> = A<T>;
typedef C<T> = A<int>;

View file

@ -0,0 +1,5 @@
main() {}
test1(dynamic x) => x.foo<int>;
test2(Never x) => x.foo<int>;
test3(dynamic x) => x.toString<int>;
test4(Never x) => x.toString<int>;

View file

@ -0,0 +1,13 @@
X boundedMethod<X extends num>(X x) => x;
X id<X>(X x) => x;
main() {}
test() {}
var a = id;
var b = a<int>;
var c = id<int>;
var d = id<int, String>;
var e = method<int>;
var f = 0<int>;
var g = main<int>;
var h = boundedMethod<String>;
void method<X, Y>() {}

View file

@ -1,35 +1,43 @@
class A {
A.new();
}
class B {
B();
}
class C {
C();
C.new();
}
class D {
D.new();
D();
}
class E1 {
E1._();
E1();
factory E1.new() => E1._();
}
class E2 {
E2._();
factory E2.new() => E2._();
E2();
}
class E3 {
E3._();
E3();
factory E3.new() = E3._;
}
class E4 {
E4._();
factory E4.new() = E4._;
E4();
}
main() {}

View file

@ -0,0 +1,43 @@
class A {
A.new();
}
class B {
B();
}
class C {
C();
C.new();
}
class D {
D();
D.new();
}
class E1 {
E1();
E1._();
factory E1.new() => E1._();
}
class E2 {
E2();
E2._();
factory E2.new() => E2._();
}
class E3 {
E3();
E3._();
factory E3.new() = E3._;
}
class E4 {
E4();
E4._();
factory E4.new() = E4._;
}
main() {}

View file

@ -4,6 +4,7 @@ class A<X> {
A();
factory A.bar1() => new A();
}
A<X> Function<X>(X) test1() => A.foo1;
A<X> Function<X>(X) test2() => A.foo2;
A<X> Function<X>(X) test3() => A.new;

View file

@ -1,9 +1,22 @@
A<X> Function<X>(X) bar1() => A.foo1;
A<X> Function<X>(X) bar2() => A.foo2;
A<X> Function<X>() test10() => A.bar1;
A<X> Function<X>(X) test1() => A.foo1;
A<X> Function<X>(X) test11() => A.bar1;
A<X> Function<X>(X) test2() => A.foo2;
A<X> Function<X>(X) test3() => A.new;
A<X> Function<X>(X) test4() => A<int>.new;
A<X> Function<X>(X) test5() => A<int, String>.new;
A<X> Function<X>(X) test6() => A<int>.foo1;
A<X> Function<X>(X) test7() => A<int, String>.foo1;
A<X> Function<X>(X) test8() => A<int>.foo2;
A<X> Function<X>(X) test9() => A<int, String>.foo2;
A<int> Function() test12() => A<int>.bar1;
A<int> Function() test13() => A.bar1;
class A<X> {
A();
A.foo1(X x) {}
A.foo2(X x, int y) {}
factory A.bar1() => new A();
}
main() {}

View file

@ -3,6 +3,7 @@ class A<X> {
A() {}
factory A.bar() => new A<X>();
}
testFoo() => A.foo;
testFooArgs() => A<int>.foo;
testNew() => A.new;

View file

@ -1,7 +1,17 @@
bar() => A.foo;
class A<X> {
A() {}
A.foo() {}
factory A.bar() => new A<X>();
}
main() {}
method() {}
testBar() => A.bar;
testBarArgs() => A<int>.bar;
testBarExtraArgs() => A<int, String>.bar;
testFoo() => A.foo;
testFooArgs() => A<int>.foo;
testFooExtraArgs() => A<int, String>.foo;
testNew() => A.new;
testNewArgs() => A<int>.new;
testNewExtraArgs() => A<int, String>.new;

View file

@ -0,0 +1,8 @@
T Function(T) create<T>() => id<T>;
T id<T>(T t) => t;
const explicitConstInstantiation = id<int>;
const int Function(int) implicitConstInstantiation = id;
expect(expected, actual) {}
int Function(int) implicitInstantiation = id;
main() {}
var explicitInstantiation = id<int>;

View file

@ -1,16 +1,20 @@
final bool inSoundMode = <int?>[] is! List<int>;
main() {}
class Class1 {
int field;
Class1(this.field);
}
abstract class Interface2 {
int get field;
}
class Class2 implements Interface2 {
final field;
Class2(this.field);
}
var Class1_new = Class1.new;
var Class2_new = Class2.new;
testInferred() {}

View file

@ -0,0 +1,21 @@
abstract class Interface2 {
int get field;
}
class Class1 {
Class1(this.field);
int field;
}
class Class2 implements Interface2 {
Class2(this.field);
final field;
}
expect(expected, actual) {}
final bool inSoundMode = <int?>[] is! List<int>;
main() {}
testInferred() {}
throws(Function() f, {bool inSoundModeOnly: false}) {}
var Class1_new = Class1.new;
var Class2_new = Class2.new;

View file

@ -1,5 +1,7 @@
final bool inSoundMode = <int?>[] is! List<int>;
class A<T> {}
typedef F<X extends num> = A<X>;
typedef G<Y> = A<int>;
typedef H<X, Y> = A<X>;

View file

@ -0,0 +1,18 @@
class A<T> {}
const A<int> Function() f1c = F.new;
const A<int> Function() g1c = G.new;
const A<int> Function() h1c = H.new;
const f1a = A<int>.new;
const f1b = F<int>.new;
const g1a = A<int>.new;
const g1b = G<String>.new;
const h1a = A<int>.new;
const h1b = H<int, String>.new;
expect(expected, actual) {}
final bool inSoundMode = <int?>[] is! List<int>;
main() {}
test<T extends num>() {}
typedef F<X extends num> = A<X>;
typedef G<Y> = A<int>;
typedef H<X, Y> = A<X>;

View file

@ -3,6 +3,7 @@ class A<X extends num> {
A(X x) {}
factory A.bar(X x) => new A<X>(x);
}
A<num> Function(num) test1() => A.foo;
A<int> Function(int) test2() => A.foo;
A<num> Function(num) test3() => A.new;

View file

@ -1,9 +1,20 @@
A<dynamic> Function(String) bar3() => A.foo;
A<int> Function(int) bar2() => A.foo;
A<num> Function(num) bar1() => A.foo;
A<dynamic> Function(String) test11() => A.bar;
A<dynamic> Function(String) test5() => A.foo;
A<dynamic> Function(String) test6() => A.new;
A<dynamic> Function(num) test12() => A.bar;
A<dynamic> Function(num) test7() => A<num>.foo;
A<dynamic> Function(num) test8() => A<num>.new;
A<int> Function(int) test10() => A.bar;
A<int> Function(int) test2() => A.foo;
A<int> Function(int) test4() => A.new;
A<num> Function(num) test1() => A.foo;
A<num> Function(num) test3() => A.new;
A<num> Function(num) test9() => A.bar;
class A<X extends num> {
A(X x) {}
A.foo(X x) {}
factory A.bar(X x) => new A<X>(x);
}
main() {}

View file

@ -1,16 +1,20 @@
final bool inSoundMode = <int?>[] is! List<int>;
main() {}
class Class1 {
int field;
Class1(this.field);
}
abstract class Interface2 {
int get field;
}
class Class2 implements Interface2 {
final field;
Class2(this.field);
}
var Class1_new = Class1.new;
var Class2_new = Class2.new;
testInferred() {}

View file

@ -17,3 +17,5 @@ final bool inSoundMode = <int?>[] is! List<int>;
main() {}
testInferred() {}
throws(Function() f, {bool inSoundModeOnly: false}) {}
var Class1_new = Class1.new;
var Class2_new = Class2.new;

View file

@ -1,9 +1,11 @@
final bool inSoundMode = <int?>[] is! List<int>;
class A<T> {
A();
factory A.fact() => new A<T>();
factory A.redirect() = A<T>;
}
typedef F<X extends num> = A<X>;
typedef G<Y> = A<int>;
typedef H<X, Y> = A<X>;

View file

@ -0,0 +1,28 @@
class A<T> {
A();
factory A.fact() => new A<T>();
factory A.redirect() = A<T>;
}
const A<int> Function() f1c = F.new;
const A<int> Function() f1f = F.fact;
const A<int> Function() f1i = F.redirect;
const A<int> Function() g1c = G.new;
const A<int> Function() h1c = H.new;
const f1a = A<int>.new;
const f1b = F<int>.new;
const f1d = A<int>.fact;
const f1e = F<int>.fact;
const f1g = A<int>.redirect;
const f1h = F<int>.redirect;
const g1a = A<int>.new;
const g1b = G<String>.new;
const h1a = A<int>.new;
const h1b = H<int, String>.new;
expect(expected, actual) {}
final bool inSoundMode = <int?>[] is! List<int>;
main() {}
test<T extends num>() {}
typedef F<X extends num> = A<X>;
typedef G<Y> = A<int>;
typedef H<X, Y> = A<X>;

View file

@ -2,17 +2,20 @@ var A_new = A.new;
var B_new = B.new;
var F_new = F.new;
var G_new = G.new;
class A {
int field1 = 0;
A(this.field1);
A.named(this.field1);
}
class B<T> implements A {
var field1;
T field2;
B(this.field1, this.field2);
B.named(this.field1, this.field2);
}
typedef F<T> = A;
typedef G<T extends num> = B;
var A_named = A.named;

View file

@ -0,0 +1,24 @@
class A {
A(this.field1);
A.named(this.field1);
int field1 = 0;
}
class B<T> implements A {
B(this.field1, this.field2);
B.named(this.field1, this.field2);
T field2;
var field1;
}
main() {}
typedef F<T> = A;
typedef G<T extends num> = B;
var A_named = A.named;
var A_new = A.new;
var B_named = B<int>.named;
var B_new = B.new;
var F_named = F.named;
var F_new = F.new;
var G_named = G<int>.named;
var G_new = G.new;

View file

@ -1,4 +1,5 @@
import 'main_lib.dart';
typedef H<X, Y> = A<Y>;
dynamic H_new = H.new;
dynamic H_named = H.named;

View file

@ -0,0 +1,13 @@
import 'main_lib.dart';
dynamic F_fact = F.fact;
dynamic F_named = F.named;
dynamic F_new = F.new;
dynamic F_redirect = F.redirect;
dynamic H_fact = H.fact;
dynamic H_named = H.named;
dynamic H_new = H.new;
dynamic H_redirect = H.redirect;
expect(expected, actual) {}
main() {}
typedef H<X, Y> = A<Y>;

View file

@ -1,4 +1,5 @@
import 'typedef_identical_lib.dart';
typedef H<X, Y> = A<Y>;
var H_new = H.new;
var H_named = H.named;

View file

@ -0,0 +1,13 @@
import 'typedef_identical_lib.dart';
expect(expected, actual) {}
main() {}
typedef H<X, Y> = A<Y>;
var F_fact = F.fact;
var F_named = F.named;
var F_new = F.new;
var F_redirect = F.redirect;
var H_fact = H.fact;
var H_named = H.named;
var H_new = H.new;
var H_redirect = H.redirect;

View file

@ -4,6 +4,7 @@ class A {
A() {}
factory A.bar1() => new A();
}
A Function() test1() => A.foo1;
A Function() test2() => A.foo2;
A Function() test3() => A.new;

View file

@ -1,9 +1,15 @@
A Function() bar1() => A.foo1;
A Function() bar2() => A.foo2;
A Function() test1() => A.foo1;
A Function() test2() => A.foo2;
A Function() test3() => A.new;
A Function() test5() => A.bar1;
A Function(int) test4() => A.new;
A Function(int) test6() => A.bar1;
class A {
A() {}
A.foo1() {}
A.foo2(int x) {}
factory A.bar1() => new A();
}
main() {}

View file

@ -3,6 +3,7 @@ class A {
A() {}
factory A.bar() => new A();
}
testFoo() => A.foo;
testNew() => A.new;
testBar() => A.bar;

View file

@ -1,7 +1,13 @@
bar() => A.foo;
class A {
A() {}
A.foo() {}
factory A.bar() => new A();
}
main() {}
testBar() => A.bar;
testBarExtraArgs() => A<int>.bar;
testFoo() => A.foo;
testFooExtraArgs() => A<int>.foo;
testNew() => A.new;
testNewExtraArgs() => A<int>.new;

View file

@ -4,6 +4,8 @@ class A {
factory A.redirectingFactoryChild() = B.new;
factory A.redirectingTwice() = A.redirectingFactory;
}
class B extends A {}
test() {}
main() => test();

View file

@ -0,0 +1,11 @@
class A {
A.new();
factory A.redirectingFactory() = A.new;
factory A.redirectingFactoryChild() = B.new;
factory A.redirectingTwice() = A.redirectingFactory;
}
class B extends A {}
main() => test();
test() {}

View file

@ -0,0 +1,3 @@
bar() {}
foo() => List<int>;
main() {}

View file

@ -1,16 +1,27 @@
class A1<T> {}
typedef B1<T> = A1<T>;
class A2<T extends num> {}
typedef B2<T extends num> = A2<T>;
class A3<T extends List<dynamic>, S extends Never?> {}
typedef B3<T extends List<Object?>, S extends Null> = A3<T, S>;
class A4<T extends num> {}
typedef B4<T extends int> = A4<T>;
class A5<T extends List<dynamic>, S extends Never?> {}
typedef B5<T extends List<Object?>, S extends Null> = A5;
class StaticIdentityTest {
const StaticIdentityTest(a, b) : assert(identical(a, b));
}
test1() => const StaticIdentityTest(A1.new, B1.new);
test2() => const StaticIdentityTest(A2.new, B2.new);
test3() => const StaticIdentityTest(A3.new, B3.new);

View file

@ -0,0 +1,25 @@
class A1<T> {}
class A2<T extends num> {}
class A3<T extends List<dynamic>, S extends Never?> {}
class A4<T extends num> {}
class A5<T extends List<dynamic>, S extends Never?> {}
class StaticIdentityTest {
const StaticIdentityTest(a, b) : assert(identical(a, b));
}
main() {}
test1() => const StaticIdentityTest(A1.new, B1.new);
test2() => const StaticIdentityTest(A2.new, B2.new);
test3() => const StaticIdentityTest(A3.new, B3.new);
test4() => const StaticIdentityTest(A4.new, B4.new);
test5() => const StaticIdentityTest(A5.new, B5.new);
typedef B1<T> = A1<T>;
typedef B2<T extends num> = A2<T>;
typedef B3<T extends List<Object?>, S extends Null> = A3<T, S>;
typedef B4<T extends int> = A4<T>;
typedef B5<T extends List<Object?>, S extends Null> = A5;

View file

@ -1,9 +1,11 @@
class A {}
class B<X> {
B();
B.foo();
factory B.bar() => new B<X>();
}
typedef DA1 = A;
typedef DA2<X extends num> = A;
typedef DB1 = B<String>;

View file

@ -0,0 +1,39 @@
A Function() test2() => DA1.new;
A Function() test4() => DA2.new;
A Function() test5() => DA2<String>.new;
A Function() test6() => DA2<int>.new;
B<String> Function() test10() => DB1.foo;
B<String> Function() test11() => DB1.bar;
B<String> Function() test24() => DB2.new;
B<String> Function() test8() => DB1.new;
B<Y> Function<Y, Z>() test23() => DB3.new;
B<Y> Function<Y>() test17() => DB2.new;
B<Y> Function<Y extends num, Z extends String>() test22() => DB3.new;
B<Y> Function<Y extends num>() test16() => DB2.new;
B<num> Function() test12() => DB2<num>.new;
B<num> Function() test13() => DB2<num>.foo;
B<num> Function() test14() => DB2<num>.bar;
B<num> Function() test15() => DB2.new;
B<num> Function() test18() => DB3<num, String>.new;
B<num> Function() test19() => DB3<num, String>.foo;
B<num> Function() test20() => DB3<num, String>.bar;
B<num> Function() test21() => DB3.new;
B<num> Function() test9() => DB1.new;
DA1 Function() test1() => DA1.new;
DA2<num> Function() test3() => DA2.new;
DB1 Function() test7() => DB1.new;
class A {}
class B<X> {
B();
B.foo();
factory B.bar() => new B<X>();
}
main() {}
typedef DA1 = A;
typedef DA2<X extends num> = A;
typedef DB1 = B<String>;
typedef DB2<X extends num> = B<X>;
typedef DB3<X extends num, Y extends String> = B<X>;

View file

@ -4,13 +4,17 @@ class A {
factory A.redirectingFactoryChild() = B.new;
A.redirecting() : this.new();
}
class B extends A {}
class C {
final int x;
const C.new(this.x);
}
class D extends C {
D(int x) : super.new(x * 2);
}
test() {}
main() {}

View file

@ -0,0 +1,20 @@
class A {
A.new();
A.redirecting() : this.new();
factory A.redirectingFactory() = A.new;
factory A.redirectingFactoryChild() = B.new;
}
class B extends A {}
class C {
const C.new(this.x);
final int x;
}
class D extends C {
D(int x) : super.new(x * 2);
}
main() {}
test() {}

View file

@ -23,29 +23,6 @@ regress/utf_16_le_content.crash: EmptyOutput
const_functions/const_functions_const_ctor: FormatterCrash
const_functions/const_functions_const_ctor_error: FormatterCrash
const_functions/const_functions_const_factory: FormatterCrash
constructor_tearoffs/call_instantiation: FormatterCrash
constructor_tearoffs/const_tear_off: FormatterCrash
constructor_tearoffs/dynamic_explicit_instantiation: FormatterCrash
constructor_tearoffs/explicit_instantiation_errors: FormatterCrash
constructor_tearoffs/explicit_new_as_unnamed: FormatterCrash
constructor_tearoffs/generic_tearoff_with_context: FormatterCrash
constructor_tearoffs/generic_tearoff_without_context: FormatterCrash
constructor_tearoffs/identical_instantiated_function_tearoffs: FormatterCrash
constructor_tearoffs/inferred_constructor_tear_off: FormatterCrash
constructor_tearoffs/inferred_non_proper_rename: FormatterCrash
constructor_tearoffs/instantiation: FormatterCrash
constructor_tearoffs/lowering/inferred_constructor_tear_off: FormatterCrash
constructor_tearoffs/lowering/inferred_non_proper_rename: FormatterCrash
constructor_tearoffs/lowering/inferred_tear_off: FormatterCrash
constructor_tearoffs/lowering/typedef_from_dill/main: FormatterCrash
constructor_tearoffs/lowering/typedef_identical: FormatterCrash
constructor_tearoffs/nongeneric_tearoff_with_context: FormatterCrash
constructor_tearoffs/nongeneric_tearoff_without_context: FormatterCrash
constructor_tearoffs/redirecting_constructors: FormatterCrash
constructor_tearoffs/simple_instantiated_type_literals: FormatterCrash
constructor_tearoffs/simple_proper_rename_identity: FormatterCrash
constructor_tearoffs/typedef_tearoffs: FormatterCrash
constructor_tearoffs/unnamed_constructor: FormatterCrash
dart2js/late_fields: FormatterCrash
dart2js/late_statics: FormatterCrash
extension_types/simple_getter_resolution: FormatterCrash