Issue 45459. Report EXPERIMENT_NOT_ENABLED instead of INVALID_GENERIC_FUNCTION_TYPE when nonfunction_type_aliases is not enabled.

Bug: https://github.com/dart-lang/sdk/issues/45459
Change-Id: I0773f15e4697620427f4449622a592e40b5a5de4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-03-25 21:43:04 +00:00 committed by commit-bot@chromium.org
parent 2febc7d526
commit 4af81e2a5b
8 changed files with 58 additions and 14 deletions

View file

@ -26,7 +26,6 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
messageMissingAssignableSelector,
messageNativeClauseShouldBeAnnotation,
messageOperatorWithTypeParameters,
messageTypedefNotFunction,
templateDuplicateLabelInSwitchStatement,
templateExpectedButGot,
templateExpectedIdentifier,
@ -1549,7 +1548,15 @@ class AstBuilder extends StackListener {
var metadata = pop() as List<Annotation>?;
var comment = _findComment(metadata, typedefKeyword);
if (type is! GenericFunctionType && !enableNonFunctionTypeAliases) {
handleRecoverableError(messageTypedefNotFunction, equals, equals);
var feature = Feature.nonfunction_type_aliases;
handleRecoverableError(
templateExperimentNotEnabled.withArguments(
feature.enableString,
_versionAsString(ExperimentStatus.currentVersion),
),
equals,
equals,
);
}
declarations.add(ast.genericTypeAlias(comment, metadata, typedefKeyword,
name, templateParameters, equals, type, semicolon));

View file

@ -1698,7 +1698,7 @@ class Wrong<T> {
errors: [
expectedError(ParserErrorCode.EXPECTED_TYPE_NAME, 12, 7),
expectedError(ParserErrorCode.EXPECTED_TOKEN, 12, 7),
expectedError(ParserErrorCode.INVALID_GENERIC_FUNCTION_TYPE, 10, 1),
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 10, 1),
]);
}

View file

@ -3311,7 +3311,7 @@ main(p) {
p is F;
}
''', [
error(ParserErrorCode.INVALID_GENERIC_FUNCTION_TYPE, 10, 1),
error(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 10, 1),
]);
}

View file

@ -0,0 +1,35 @@
// 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.
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ExperimentNotEnabledTest);
});
}
@reflectiveTest
class ExperimentNotEnabledTest extends PubPackageResolutionTest {
test_nonFunctionTypeAliases_disabled() async {
await assertErrorsInCode(r'''
// @dart = 2.12
typedef A = int;
''', [
error(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 26, 1),
]);
}
test_nonFunctionTypeAliases_disabled_nullable() async {
await assertErrorsInCode(r'''
// @dart = 2.12
typedef A = int?;
''', [
error(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 26, 1),
]);
}
}

View file

@ -147,6 +147,7 @@ import 'expected_one_set_type_arguments_test.dart'
as expected_one_set_type_arguments;
import 'expected_two_map_type_arguments_test.dart'
as expected_two_map_type_arguments;
import 'experiment_not_enabled_test.dart' as experiment_not_enabled;
import 'export_internal_library_test.dart' as export_internal_library;
import 'export_legacy_symbol_test.dart' as export_legacy_symbol;
import 'export_of_non_library_test.dart' as export_of_non_library;
@ -784,6 +785,7 @@ main() {
expected_one_list_type_arguments.main();
expected_one_set_type_arguments.main();
expected_two_map_type_arguments.main();
experiment_not_enabled.main();
export_internal_library.main();
export_legacy_symbol.main();
export_of_non_library.main();

View file

@ -50,11 +50,11 @@ class TypedefTest extends PartialCodeTest {
[
ParserErrorCode.EXPECTED_TYPE_NAME,
ParserErrorCode.EXPECTED_TOKEN,
ParserErrorCode.INVALID_GENERIC_FUNCTION_TYPE
ParserErrorCode.EXPERIMENT_NOT_ENABLED
],
"typedef T = _s_;",
expectedErrorsInValidCode: [
ParserErrorCode.INVALID_GENERIC_FUNCTION_TYPE
ParserErrorCode.EXPERIMENT_NOT_ENABLED
],
failing: ['functionVoid', 'functionNonVoid', 'getter', 'mixin']),
],

View file

@ -11,19 +11,19 @@ typedef int F();
typedef G = F;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef H = int;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef I = A;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef J = List<int>;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef K = Function(Function<A>(A<int>));
// ^^^^^^

View file

@ -11,19 +11,19 @@ typedef int F();
typedef G = F;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef H = int;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef I = A;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef J = List<int>;
// ^
// [analyzer] SYNTACTIC_ERROR.INVALID_GENERIC_FUNCTION_TYPE
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] Can't create typedef from non-function type.
typedef K = Function(Function<A>(A<int>));
// ^^^^^^