Skip to content

#1959. Grammar tests added #2031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023, 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.

/// @assertion The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is a compile-time error if a built-in identifier
/// `interface` is used as an identifier
/// @author [email protected]

// SharedOptions=--enable-experiment=class-modifiers

class interface {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
}
34 changes: 34 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2023, 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.

/// @assertion The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is not an error to create a class named `base` or
/// `sealed`
/// @author [email protected]

// SharedOptions=--enable-experiment=class-modifiers

class base {}

class sealed {}

main() {
print(base);
print(sealed);
}
35 changes: 35 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2023, 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.

/// @assertion The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is not an error to declare a variable named
/// `base`, `sealed` or `interface`
/// @author [email protected]

// SharedOptions=--enable-experiment=class-modifiers

main() {
var base = 1;
var sealed = 2;
var interface = 3;

print(base);
print(sealed);
print(interface);
}
46 changes: 46 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023, 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.

/// @assertion The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is a compile-time error if 'base', 'interface' or
/// 'final' modifiers are placed before an `abstract` modifier
/// @author [email protected]

// SharedOptions=--enable-experiment=class-modifiers

base abstract class C1 {}
//^^^^
// [analyzer] unspecified
// [cfe] unspecified

interface abstract class C2 {}
//^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final abstract class C3 {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C1);
print(C2);
print(C3);
}
70 changes: 70 additions & 0 deletions LanguageFeatures/Class-modifiers/grammar_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2023, 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.

/// @assertion The grammar is:
///
/// classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
/// typeParameters? superclass? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
/// | classModifiers 'class' mixinApplicationClass
///
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
///
/// mixinClassModifiers ::= 'abstract'? 'base'? 'mixin'
///
/// mixinDeclaration ::= 'base'? 'mixin' typeIdentifier typeParameters?
/// ('on' typeNotVoidList)? interfaces?
/// '{' (metadata classMemberDeclaration)* '}'
///
/// @description Check that it is a compile-time error if 'mixin', 'base', or
/// `abstract` modifiers goes in a wrong order
/// @author [email protected]

// SharedOptions=--enable-experiment=class-modifiers

base abstract mixin class C1 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

base mixin abstract class C2 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin base abstract class C3 {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin abstract base class C4 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract mixin base class C5 {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin abstract class C6 {}
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

mixin base class C7 {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C1);
print(C2);
print(C3);
print(C4);
print(C5);
print(C6);
print(C7);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! The parser could get confused about these situations, e.g., it could crash, and we should test this.