Skip to content

Commit b6f03e1

Browse files
jensjohaCommit Bot
authored and
Commit Bot
committed
[CFE] Reproduction & fix of crashes found by weekly bot (#83)
Calling "SpecialCasedBinaryOperator" and "SpecialCasedTernaryOperator" with wrong number of parameters (especially too few) would not go well. It's now checked and goes a lot better. Change-Id: Id9606db869f020bbd7264686adaf9521bd263fb9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237900 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 04f8303 commit b6f03e1

24 files changed

+275
-14
lines changed

pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,20 +2488,39 @@ class TypeInferrerImpl implements TypeInferrer {
24882488
namedIndex == arguments.named.length,
24892489
"Expected 'namedIndex' to be ${arguments.named.length}, "
24902490
"got ${namedIndex}.");
2491-
if (isSpecialCasedBinaryOperator) {
2492-
calleeType = replaceReturnType(
2493-
calleeType,
2494-
typeSchemaEnvironment.getTypeOfSpecialCasedBinaryOperator(
2495-
receiverType!, actualTypes![0],
2496-
isNonNullableByDefault: isNonNullableByDefault));
2497-
} else if (isSpecialCasedTernaryOperator) {
2498-
calleeType = replaceReturnType(
2499-
calleeType,
2500-
typeSchemaEnvironment.getTypeOfSpecialCasedTernaryOperator(
2501-
receiverType!,
2502-
actualTypes![0],
2503-
actualTypes[1],
2504-
libraryBuilder.library));
2491+
2492+
if (isSpecialCasedBinaryOperator || isSpecialCasedTernaryOperator) {
2493+
if (typeChecksNeeded && !identical(calleeType, unknownFunction)) {
2494+
LocatedMessage? argMessage = helper!.checkArgumentsForType(
2495+
calleeType, arguments, offset,
2496+
isExtensionMemberInvocation: isExtensionMemberInvocation);
2497+
if (argMessage != null) {
2498+
return new WrapInProblemInferenceResult(
2499+
const InvalidType(),
2500+
const InvalidType(),
2501+
argMessage.messageObject,
2502+
argMessage.charOffset,
2503+
argMessage.length,
2504+
helper!,
2505+
isInapplicable: true,
2506+
hoistedArguments: localHoistedExpressions);
2507+
}
2508+
}
2509+
if (isSpecialCasedBinaryOperator) {
2510+
calleeType = replaceReturnType(
2511+
calleeType,
2512+
typeSchemaEnvironment.getTypeOfSpecialCasedBinaryOperator(
2513+
receiverType!, actualTypes![0],
2514+
isNonNullableByDefault: isNonNullableByDefault));
2515+
} else if (isSpecialCasedTernaryOperator) {
2516+
calleeType = replaceReturnType(
2517+
calleeType,
2518+
typeSchemaEnvironment.getTypeOfSpecialCasedTernaryOperator(
2519+
receiverType!,
2520+
actualTypes![0],
2521+
actualTypes[1],
2522+
libraryBuilder.library));
2523+
}
25052524
}
25062525

25072526
// Check for and remove duplicated named arguments.

pkg/front_end/test/fasta/expression_suite.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ import 'package:vm/target/vm.dart' show VmTarget;
6767

6868
import "package:yaml/yaml.dart" show YamlMap, YamlList, loadYamlNode;
6969

70+
import '../testing_utils.dart' show checkEnvironment;
71+
7072
import '../utils/kernel_chain.dart' show runDiff, openWrite;
7173

7274
class Context extends ChainContext {
@@ -568,6 +570,12 @@ class CompileExpression extends Step<List<TestCase>, List<TestCase>, Context> {
568570

569571
Future<Context> createContext(
570572
Chain suite, Map<String, String> environment) async {
573+
const Set<String> knownEnvironmentKeys = {
574+
"updateExpectations",
575+
"fuzz",
576+
};
577+
checkEnvironment(environment, knownEnvironmentKeys);
578+
571579
final Uri base = Uri.parse("org-dartlang-test:///");
572580

573581
/// Unused because we supply entry points to [computeDelta] directly above.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2022, 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+
sources: ""
6+
definitions: []
7+
position: "dart:core#double"
8+
expression: |
9+
remainder()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Errors: {
2+
org-dartlang-debug:synthetic_debug_expression:1:10: Error: Too few positional arguments: 1 required, 0 given.
3+
remainder()
4+
^
5+
}
6+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
7+
return invalid-expression "org-dartlang-debug:synthetic_debug_expression:1:10: Error: Too few positional arguments: 1 required, 0 given.\nremainder()\n ^" in this.{dart.core::double::remainder}{<inapplicable>}.(){() → invalid-type};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2022, 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+
sources: ""
6+
definitions: []
7+
position: "dart:core#double"
8+
expression: |
9+
clamp()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Errors: {
2+
org-dartlang-debug:synthetic_debug_expression:1:6: Error: Too few positional arguments: 2 required, 0 given.
3+
clamp()
4+
^
5+
}
6+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
7+
return invalid-expression "org-dartlang-debug:synthetic_debug_expression:1:6: Error: Too few positional arguments: 2 required, 0 given.\nclamp()\n ^" in this.{dart.core::num::clamp}{<inapplicable>}.(){() → invalid-type};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2022, 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+
sources: ""
6+
definitions: []
7+
position: "dart:core#double"
8+
expression: |
9+
clamp(42, 42)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
4+
return this.{dart.core::num::clamp}(42, 42){(dart.core::num, dart.core::num) → dart.core::num};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2022, 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+
sources: ""
6+
definitions: []
7+
position: "dart:core#double"
8+
expression: |
9+
remainder(42)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
4+
return this.{dart.core::double::remainder}(42){(dart.core::num) → dart.core::double};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
main2() {
2+
double x = 42;
3+
x.remainder();
4+
}
5+
6+
main(List<String> args) {
7+
if (args.length == 42) {
8+
main2();
9+
}
10+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main2() {}
2+
main(List<String> args) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main(List<String> args) {}
2+
main2() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure.dart:3:14: Error: Too few positional arguments: 1 required, 0 given.
6+
// x.remainder();
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
static method main2() → dynamic {
13+
core::double x = 42.0;
14+
invalid-expression "pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure.dart:3:14: Error: Too few positional arguments: 1 required, 0 given.
15+
x.remainder();
16+
^" in x.{core::double::remainder}{<inapplicable>}.(){() → invalid-type};
17+
}
18+
static method main(core::List<core::String> args) → dynamic {
19+
if(args.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} 42) {
20+
self::main2();
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure.dart:3:14: Error: Too few positional arguments: 1 required, 0 given.
6+
// x.remainder();
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
static method main2() → dynamic {
13+
core::double x = 42.0;
14+
invalid-expression "pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure.dart:3:14: Error: Too few positional arguments: 1 required, 0 given.
15+
x.remainder();
16+
^" in x.{core::double::remainder}{<inapplicable>}.(){() → invalid-type};
17+
}
18+
static method main(core::List<core::String> args) → dynamic {
19+
if(args.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} 42) {
20+
self::main2();
21+
}
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method main2() → dynamic
6+
;
7+
static method main(core::List<core::String> args) → dynamic
8+
;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure.dart:3:14: Error: Too few positional arguments: 1 required, 0 given.
6+
// x.remainder();
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
static method main2() → dynamic {
13+
core::double x = 42.0;
14+
invalid-expression "pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure.dart:3:14: Error: Too few positional arguments: 1 required, 0 given.
15+
x.remainder();
16+
^" in x.{core::double::remainder}{<inapplicable>}.(){() → invalid-type};
17+
}
18+
static method main(core::List<core::String> args) → dynamic {
19+
if(args.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} 42) {
20+
self::main2();
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
main2() {
2+
double x = 42;
3+
x.clamp();
4+
}
5+
6+
main(List<String> args) {
7+
if (args.length == 42) {
8+
main2();
9+
}
10+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main2() {}
2+
main(List<String> args) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main(List<String> args) {}
2+
main2() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure_2.dart:3:10: Error: Too few positional arguments: 2 required, 0 given.
6+
// x.clamp();
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
static method main2() → dynamic {
13+
core::double x = 42.0;
14+
invalid-expression "pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure_2.dart:3:10: Error: Too few positional arguments: 2 required, 0 given.
15+
x.clamp();
16+
^" in x.{core::num::clamp}{<inapplicable>}.(){() → invalid-type};
17+
}
18+
static method main(core::List<core::String> args) → dynamic {
19+
if(args.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} 42) {
20+
self::main2();
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure_2.dart:3:10: Error: Too few positional arguments: 2 required, 0 given.
6+
// x.clamp();
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
static method main2() → dynamic {
13+
core::double x = 42.0;
14+
invalid-expression "pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure_2.dart:3:10: Error: Too few positional arguments: 2 required, 0 given.
15+
x.clamp();
16+
^" in x.{core::num::clamp}{<inapplicable>}.(){() → invalid-type};
17+
}
18+
static method main(core::List<core::String> args) → dynamic {
19+
if(args.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} 42) {
20+
self::main2();
21+
}
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method main2() → dynamic
6+
;
7+
static method main(core::List<core::String> args) → dynamic
8+
;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure_2.dart:3:10: Error: Too few positional arguments: 2 required, 0 given.
6+
// x.clamp();
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
static method main2() → dynamic {
13+
core::double x = 42.0;
14+
invalid-expression "pkg/front_end/testcases/general/error_recovery/weekly_bot_83_failure_2.dart:3:10: Error: Too few positional arguments: 2 required, 0 given.
15+
x.clamp();
16+
^" in x.{core::num::clamp}{<inapplicable>}.(){() → invalid-type};
17+
}
18+
static method main(core::List<core::String> args) → dynamic {
19+
if(args.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} 42) {
20+
self::main2();
21+
}
22+
}

0 commit comments

Comments
 (0)