File tree Expand file tree Collapse file tree 22 files changed +890
-0
lines changed
LanguageFeatures/Extension-types Expand file tree Collapse file tree 22 files changed +890
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @description Helper library for testing extension types
6
+ /// @author sgrekhov22@gmail.com
7
+
8
+ // SharedOptions=--enable-experiment=inline-class
9
+
10
+ library extension_type_lib;
11
+
12
+ int x = 42 ;
13
+
14
+ extension type _PrivateExtensionType (int id) {
15
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// The token `type` is not made a built-in identifier: the built-in identifier
23
+ /// extension that occurs right before type serves to disambiguate the extension
24
+ /// type declaration with a fixed lookahead.
25
+ ///
26
+ /// @description Checks that it is not an error to declare a class named `type`
27
+ /// @author sgrekhov22@gmail.com
28
+
29
+ // SharedOptions=--enable-experiment=inline-class
30
+
31
+ class type {
32
+ }
33
+
34
+ main () {
35
+ type ();
36
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// The token `type` is not made a built-in identifier: the built-in identifier
23
+ /// extension that occurs right before type serves to disambiguate the extension
24
+ /// type declaration with a fixed lookahead.
25
+ ///
26
+ /// @description Checks that it is not an error to declare a mixin named `type`
27
+ /// @author sgrekhov22@gmail.com
28
+
29
+ // SharedOptions=--enable-experiment=inline-class
30
+
31
+ mixin type on Object {
32
+ }
33
+
34
+ class IA = Object with type;
35
+
36
+ main () {
37
+ IA ();
38
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// The token `type` is not made a built-in identifier: the built-in identifier
23
+ /// extension that occurs right before type serves to disambiguate the extension
24
+ /// type declaration with a fixed lookahead.
25
+ ///
26
+ /// @description Checks that it is not an error to import a library with
27
+ /// import prefix `type`
28
+ /// @author sgrekhov22@gmail.com
29
+
30
+ // SharedOptions=--enable-experiment=inline-class
31
+
32
+ import "extension_type_lib.dart" as type;
33
+
34
+ main () {
35
+ print (type.x);
36
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// The token `type` is not made a built-in identifier: the built-in identifier
23
+ /// extension that occurs right before type serves to disambiguate the extension
24
+ /// type declaration with a fixed lookahead.
25
+ ///
26
+ /// @description Checks that it is not an error to declare a type alias named
27
+ /// `type`
28
+ /// @author sgrekhov22@gmail.com
29
+
30
+ // SharedOptions=--enable-experiment=inline-class
31
+
32
+ typedef type = String ;
33
+
34
+ main () {
35
+ type s = "type" ;
36
+ s.substring (1 );
37
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// @description Checks that it is a compile-time error if an extension type
23
+ /// declaration doesn't contain `typeIdentifier`
24
+ /// @author sgrekhov22@gmail.com
25
+
26
+ // SharedOptions=--enable-experiment=inline-class
27
+
28
+ extension type (int id) {
29
+ // ^
30
+ // [analyzer] unspecified
31
+ // [cfe] unspecified
32
+ }
33
+
34
+ main () {
35
+
36
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// @description Checks that it is a compile-time error to refer an extension
23
+ /// type with the `typeIdentifier` started with `_` outside of the library where
24
+ /// it is defined
25
+ /// @author sgrekhov22@gmail.com
26
+
27
+ // SharedOptions=--enable-experiment=inline-class
28
+
29
+ main () {
30
+ print (_PrivateExtensionType );
31
+ // ^^^^^^^^^^^^^^^^^^^^^
32
+ // [analyzer] unspecified
33
+ // [cfe] unspecified
34
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// @description Checks that an extension type declaration may have type
23
+ /// parameters
24
+ /// @author sgrekhov22@gmail.com
25
+
26
+ // SharedOptions=--enable-experiment=inline-class
27
+
28
+ import "../../Utils/expect.dart" ;
29
+
30
+ extension type ET <T >(T id) {}
31
+
32
+ main () {
33
+ ET <int > et1 = ET <int >(42 );
34
+ Expect .equals (42 , et1.id);
35
+
36
+ ET <String > et2 = ET <String >.new ("42" );
37
+ Expect .equals ("42" , et2.id);
38
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// @description Checks that it is a compile-time error if an extension type
23
+ /// declaration doesn't contain `representationDeclaration`
24
+ /// @author sgrekhov22@gmail.com
25
+
26
+ // SharedOptions=--enable-experiment=inline-class
27
+
28
+ extension type ET {
29
+ // ^^
30
+ // [analyzer] unspecified
31
+ // [cfe] unspecified
32
+ }
33
+
34
+ main () {
35
+ print (ET );
36
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// @description Checks that a `representationDeclaration` may have form
23
+ /// `identifier` .`identifier` ...
24
+ /// @author sgrekhov22@gmail.com
25
+
26
+ // SharedOptions=--enable-experiment=inline-class
27
+
28
+ import "../../Utils/expect.dart" ;
29
+
30
+ extension type ET .et (int id) {}
31
+
32
+ main () {
33
+ ET et = ET .et (42 );
34
+ Expect .equals (42 , et.id);
35
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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
+ /// @assertion A rule for <extensionTypeDeclaration> is added to the grammar,
6
+ /// along with some rules for elements used in extension type declarations:
7
+ ///
8
+ /// <extensionTypeDeclaration> ::=
9
+ /// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>?
10
+ /// <representationDeclaration> <interfaces>?
11
+ /// '{'
12
+ /// (<metadata> <extensionTypeMemberDeclaration>)*
13
+ /// '}'
14
+ ///
15
+ /// <representationDeclaration> ::=
16
+ /// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')'
17
+ ///
18
+ /// <identifierOrNew> ::= <identifier> | 'new'
19
+ ///
20
+ /// <extensionTypeMemberDeclaration> ::= <classMemberDefinition>
21
+ ///
22
+ /// @description Checks that a `representationDeclaration` may have form
23
+ /// `identifier` .new
24
+ /// @author sgrekhov22@gmail.com
25
+
26
+ // SharedOptions=--enable-experiment=inline-class
27
+
28
+ import "../../Utils/expect.dart" ;
29
+
30
+ extension type ET .new (int id) {}
31
+
32
+ main () {
33
+ ET et1 = ET (1 );
34
+ Expect .equals (1 , et1.id);
35
+
36
+ ET et2 = ET .new (2 );
37
+ Expect .equals (2 , et2.id);
38
+ }
You can’t perform that action at this time.
0 commit comments