Skip to content

Commit

Permalink
Reformat files in the top level of tests/language/.
Browse files Browse the repository at this point in the history
Change-Id: I21e39caac0239bfe388e7c7f149723f3deafb87c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400221
Auto-Submit: Bob Nystrom <[email protected]>
Commit-Queue: Lasse Nielsen <[email protected]>
Reviewed-by: Lasse Nielsen <[email protected]>
  • Loading branch information
munificent authored and Commit Queue committed Jan 2, 2025
1 parent bc521ee commit 0d63c97
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 39 deletions.
15 changes: 9 additions & 6 deletions tests/language/explicit_type_instantiation_parsing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ void main() {

// Parsed as instantiation, can't access statics on instantiated type literal.
expect1<Class>(Z<X, X>.instance);
// ^^^^^^^^
// [analyzer] unspecified
// ^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CLASS_INSTANTIATION_ACCESS_TO_MEMBER
// ^
// [cfe] Cannot access static member on an instantiated generic class.


Expand Down Expand Up @@ -260,13 +261,15 @@ void main() {

// This would be invalid even if `X` had an `any` member. See next.
X<X>.any; // Invalid, Class does not have any static `any` member.
// ^^^
// [analyzer] unspecified
// [error column 3, length 8]
// [analyzer] COMPILE_TIME_ERROR.CLASS_INSTANTIATION_ACCESS_TO_MEMBER
// ^
// [cfe] Member not found: 'any'.

X<X>.instance; // Does have static `instance` member, can't access this way.
// ^^^^^^^^
// [analyzer] unspecified
// [error column 3, length 13]
// [analyzer] COMPILE_TIME_ERROR.CLASS_INSTANTIATION_ACCESS_TO_MEMBER
// ^
// [cfe] Cannot access static member on an instantiated generic class.

// Parse error.
Expand Down
3 changes: 3 additions & 0 deletions tests/language/record_literal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// 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.

// Don't let the formatter remove the trailing commas.
// dart format off

main() {
var record1 = (1, 2, a: 3, b: 4);
print(record1);
Expand Down
3 changes: 3 additions & 0 deletions tests/language/record_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// 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.

// Don't let the formatter remove the trailing commas.
// dart format off

main() {
(int, int) record1 = (1, 2);
print(record1);
Expand Down
10 changes: 6 additions & 4 deletions tests/language/regress_54994_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ void test1() {
}

void test2() {
final B1<num, num> a = kTrue
? (B1<int, double>() as B1<num, num>)
: (B2<double>() as B1<num, num>);
final B1<num, num> a =
kTrue
? (B1<int, double>() as B1<num, num>)
: (B2<double>() as B1<num, num>);
Expect.isFalse(a is B2<int>);
Expect.isFalse(a is B2<double>);
Expect.isFalse(a is B2<num>); // Should be optimized to cid-range check.
Expand Down Expand Up @@ -85,7 +86,8 @@ class X<T extends num> {
kTrue ? B2<List<T>>() : B1<List<T>, List<T>>();
Expect.isTrue(a is B2<List<T>>); // Should be optimized to cid-range check.
Expect.isTrue(
a is B2<List<num>>); // Should be optimized to cid-range check.
a is B2<List<num>>,
); // Should be optimized to cid-range check.
Expect.isTrue(a is B2<List<int>>);
Expect.isFalse(a is B2<List<double>>);
}
Expand Down
40 changes: 20 additions & 20 deletions tests/language/static_weak_reference_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class A {

@pragma('weak-tearoff-reference')
external T Function()? weakReference12<T>(T Function()? x);
// ^
// [cfe] Weak reference pragma can be used on a static method only.
// ^
// [cfe] Weak reference pragma can be used on a static method only.
}

class B {
Expand All @@ -83,42 +83,42 @@ void main() {
validWeakRef(B.validTarget); // OK

validWeakRef(B.new);
//^
// [cfe] The target of weak reference should be a tearoff of a static method.
// [error column 3]
// [cfe] The target of weak reference should be a tearoff of a static method.

validWeakRef(B.bar);
//^
// [cfe] The target of weak reference should be a tearoff of a static method.
// [error column 3]
// [cfe] The target of weak reference should be a tearoff of a static method.

validWeakRef(B.baz);
//^
// [cfe] The target of weak reference should be a tearoff of a static method.
// [error column 3]
// [cfe] The target of weak reference should be a tearoff of a static method.

validWeakRef(B().instanceMethod);
//^
// [cfe] The target of weak reference should be a tearoff of a static method.
// [error column 3]
// [cfe] The target of weak reference should be a tearoff of a static method.

final x = B.validTarget;
validWeakRef(x);
//^
// [cfe] The target of weak reference should be a tearoff of a static method.
// [error column 3]
// [cfe] The target of weak reference should be a tearoff of a static method.

const y = B.validTarget;
validWeakRef(y); // OK

validWeakRef(B.arg1);
//^
// [cfe] The target of weak reference should not take parameters.
// [error column 3]
// [cfe] The target of weak reference should not take parameters.

validWeakRef(B.arg2);
//^
// [cfe] The target of weak reference should not take parameters.
// [error column 3]
// [cfe] The target of weak reference should not take parameters.

validWeakRef(B.arg3);
//^
// [cfe] The target of weak reference should not take parameters.
// [error column 3]
// [cfe] The target of weak reference should not take parameters.

validWeakRef(B.arg4);
//^
// [cfe] The target of weak reference should not take parameters.
// [error column 3]
// [cfe] The target of weak reference should not take parameters.
}
27 changes: 18 additions & 9 deletions tests/language/syntax_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ String syntax(Object? x) {
return '{${x.map(syntax).join(', ')}}';
} else if (x is Map) {
if (x.isEmpty) return '{}';
var entries = x.entries
.map((entry) => '${syntax(entry.key)}: ${syntax(entry.value)}');
var entries = x.entries.map(
(entry) => '${syntax(entry.key)}: ${syntax(entry.value)}',
);
return '{ ${entries.join(', ')} }';
} else if (x is String) {
return json.encode(x);
} else {
throw UnimplementedError('Unknown syntax for $x. '
'Consider adding to `SyntaxTracker.known`.');
throw UnimplementedError(
'Unknown syntax for $x. '
'Consider adding to `SyntaxTracker.known`.',
);
}
}

Expand All @@ -58,18 +61,23 @@ class SyntaxTracker {
static Map<Object?, String> known = {
true: 'true',
false: 'false',
null: 'null'
null: 'null',
};
}

/// Extension allowing us to detect the syntax of most operations performed on
/// arbitrary types.
extension SyntaxTrackingExtension on Object? {
Object? method<T, U>([Object? x = absent, Object? y = absent]) => SyntaxTracker(
'${syntax(this)}.method${SyntaxTracker.typeArgs(T, U)}${SyntaxTracker.args(x, y)}');
Object? method<T, U>([
Object? x = absent,
Object? y = absent,
]) => SyntaxTracker(
'${syntax(this)}.method${SyntaxTracker.typeArgs(T, U)}${SyntaxTracker.args(x, y)}',
);

Object? call<T, U>([Object? x = absent, Object? y = absent]) => SyntaxTracker(
'${syntax(this)}${SyntaxTracker.typeArgs(T, U)}${SyntaxTracker.args(x, y)}');
'${syntax(this)}${SyntaxTracker.typeArgs(T, U)}${SyntaxTracker.args(x, y)}',
);

Object? get getter => SyntaxTracker('${syntax(this)}.getter');

Expand Down Expand Up @@ -131,6 +139,7 @@ void checkSyntax(Object? x, String expectedSyntax) {
}

Object? f<T, U>([Object? x = absent, Object? y = absent]) => SyntaxTracker(
'f${SyntaxTracker.typeArgs(T, U)}${SyntaxTracker.args(x, y)}');
'f${SyntaxTracker.typeArgs(T, U)}${SyntaxTracker.args(x, y)}',
);

Object? x = SyntaxTracker('x');

0 comments on commit 0d63c97

Please sign in to comment.