From d120af39c6bcd7e1f333baea64380eed0a4645b6 Mon Sep 17 00:00:00 2001 From: Dmitry Stefantsov Date: Tue, 7 Sep 2021 09:39:32 +0000 Subject: [PATCH] [cfe] Fix crash on const constructor tear-off Closes #46133. Bug: https://github.com/dart-lang/sdk/issues/46133 Change-Id: I73035d2b27a2d8116fa7c31abdebfdd7299d6898 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212572 Reviewed-by: Johnni Winther Commit-Queue: Dmitry Stefantsov --- .../lib/src/fasta/kernel/body_builder.dart | 2 ++ .../constructor_tearoffs/issue46133.dart | 9 ++++++ .../issue46133.dart.strong.expect | 28 +++++++++++++++++++ .../issue46133.dart.strong.transformed.expect | 28 +++++++++++++++++++ .../issue46133.dart.textual_outline.expect | 3 ++ .../issue46133.dart.weak.expect | 28 +++++++++++++++++++ .../issue46133.dart.weak.outline.expect | 20 +++++++++++++ .../issue46133.dart.weak.transformed.expect | 28 +++++++++++++++++++ .../testcases/textual_outline.status | 1 + 9 files changed, 147 insertions(+) create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.expect create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.expect create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.outline.expect create mode 100644 pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.transformed.expect diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index 2a2955ac701..38d7818ca13 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -4833,6 +4833,8 @@ class BodyBuilder extends ScopeListener } else if (type is ParserRecovery) { push(new ParserErrorGenerator( this, nameToken, fasta.messageSyntheticToken)); + } else if (type is InvalidExpression) { + push(type); } else if (type is Expression) { push(createInstantiationAndInvocation( () => type, typeArguments, name, name, arguments, diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart new file mode 100644 index 00000000000..209a1f49d79 --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// 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. + +class A {} + +test() => A.const.toString(); + +main() {} diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.expect b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.expect new file mode 100644 index 00000000000..912d2640b74 --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.expect @@ -0,0 +1,28 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: Expected an identifier, but got '.'. +// Try inserting an identifier before '.'. +// test() => A.const.toString(); +// ^ +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +// Try inserting an identifier before 'const'. +// test() => A.const.toString(); +// ^^^^^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + synthetic constructor •() → self::A + : super core::Object::•() + ; +} +static method test() → dynamic + return invalid-expression "pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +Try inserting an identifier before 'const'. +test() => A.const.toString(); + ^^^^^"; +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.transformed.expect b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.transformed.expect new file mode 100644 index 00000000000..912d2640b74 --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.transformed.expect @@ -0,0 +1,28 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: Expected an identifier, but got '.'. +// Try inserting an identifier before '.'. +// test() => A.const.toString(); +// ^ +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +// Try inserting an identifier before 'const'. +// test() => A.const.toString(); +// ^^^^^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + synthetic constructor •() → self::A + : super core::Object::•() + ; +} +static method test() → dynamic + return invalid-expression "pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +Try inserting an identifier before 'const'. +test() => A.const.toString(); + ^^^^^"; +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.textual_outline.expect b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.textual_outline.expect new file mode 100644 index 00000000000..a9b23c0740c --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.textual_outline.expect @@ -0,0 +1,3 @@ +class A {} +test() => A.const.toString(); +main() {} diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.expect b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.expect new file mode 100644 index 00000000000..912d2640b74 --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.expect @@ -0,0 +1,28 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: Expected an identifier, but got '.'. +// Try inserting an identifier before '.'. +// test() => A.const.toString(); +// ^ +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +// Try inserting an identifier before 'const'. +// test() => A.const.toString(); +// ^^^^^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + synthetic constructor •() → self::A + : super core::Object::•() + ; +} +static method test() → dynamic + return invalid-expression "pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +Try inserting an identifier before 'const'. +test() => A.const.toString(); + ^^^^^"; +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.outline.expect b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.outline.expect new file mode 100644 index 00000000000..3fd2ec817fb --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.outline.expect @@ -0,0 +1,20 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: Expected an identifier, but got '.'. +// Try inserting an identifier before '.'. +// test() => A.const.toString(); +// ^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + synthetic constructor •() → self::A + ; +} +static method test() → dynamic + ; +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.transformed.expect b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.transformed.expect new file mode 100644 index 00000000000..912d2640b74 --- /dev/null +++ b/pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.weak.transformed.expect @@ -0,0 +1,28 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: Expected an identifier, but got '.'. +// Try inserting an identifier before '.'. +// test() => A.const.toString(); +// ^ +// +// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +// Try inserting an identifier before 'const'. +// test() => A.const.toString(); +// ^^^^^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + synthetic constructor •() → self::A + : super core::Object::•() + ; +} +static method test() → dynamic + return invalid-expression "pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'. +Try inserting an identifier before 'const'. +test() => A.const.toString(); + ^^^^^"; +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/textual_outline.status b/pkg/front_end/testcases/textual_outline.status index c24938eb0fa..45bfa23f408 100644 --- a/pkg/front_end/testcases/textual_outline.status +++ b/pkg/front_end/testcases/textual_outline.status @@ -23,6 +23,7 @@ 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/issue46133: FormatterCrash constructor_tearoffs/issue47075: FormatterCrash dart2js/late_fields: FormatterCrash dart2js/late_statics: FormatterCrash