[cfe] Report errors on declared 'values' member in enums

Part of https://github.com/dart-lang/sdk/issues/47453

Closes https://github.com/dart-lang/sdk/issues/48389
Closes https://github.com/dart-lang/sdk/issues/48387

Change-Id: I8313e3f63122c85c91a9647ddaa53346591d7238
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232841
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
This commit is contained in:
Chloe Stefantsova 2022-02-15 12:22:19 +00:00 committed by Commit Bot
parent 97176be3d4
commit 6c8ad6a723
14 changed files with 920 additions and 3 deletions

View file

@ -2786,6 +2786,16 @@ const MessageCode messageEnumConstructorTearoff = const MessageCode(
"EnumConstructorTearoff",
problemMessage: r"""Enum constructors can't be torn off.""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeEnumContainsValuesDeclaration =
messageEnumContainsValuesDeclaration;
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageEnumContainsValuesDeclaration = const MessageCode(
"EnumContainsValuesDeclaration",
problemMessage:
r"""Enums can't contain declarations of members with the name 'values'.""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeEnumDeclarationEmpty = messageEnumDeclarationEmpty;

View file

@ -722,8 +722,18 @@ class DietListener extends StackListenerImpl {
builder =
lookupConstructor(beginToken, name!) as SourceFunctionBuilderImpl;
} else {
builder = lookupBuilder(beginToken, getOrSet, name as String)
as SourceFunctionBuilderImpl;
Builder? memberBuilder =
lookupBuilder(beginToken, getOrSet, name as String);
if (currentClass?.isEnum == true &&
memberBuilder is SourceFieldBuilder &&
memberBuilder.name == "values") {
// This is the case of a method with the name 'values' declared in an
// Enum. In that case the method is replaced with the synthesized field
// in the outline building phase, and the error is reported there. At
// this point we skip the member.
return;
}
builder = memberBuilder as SourceFunctionBuilderImpl;
}
buildFunctionBody(
createFunctionListener(builder),

View file

@ -27,6 +27,7 @@ import '../builder/type_variable_builder.dart';
import '../fasta_codes.dart'
show
LocatedMessage,
messageEnumContainsValuesDeclaration,
messageEnumEntryWithTypeArgumentsWithoutArguments,
messageEnumNonConstConstructor,
messageNoUnnamedConstructorInObject,
@ -242,6 +243,20 @@ class SourceEnumBuilder extends SourceClassBuilder {
referencesFromIndexed.lookupSetterReference(valuesName);
}
Builder? customValuesDeclaration =
scope.lookupLocalMember("values", setter: false);
if (customValuesDeclaration != null) {
// Retrieve the earliest declaration for error reporting.
while (customValuesDeclaration?.next != null) {
customValuesDeclaration = customValuesDeclaration?.next;
}
parent.addProblem(
messageEnumContainsValuesDeclaration,
customValuesDeclaration!.charOffset,
customValuesDeclaration.fullNameForErrors.length,
fileUri);
}
SourceFieldBuilder valuesBuilder = new SourceFieldBuilder(
/* metadata = */ null,
listType,
@ -338,7 +353,9 @@ class SourceEnumBuilder extends SourceClassBuilder {
final int startCharOffsetComputed =
metadata == null ? startCharOffset : metadata.first.charOffset;
scope.forEachLocalMember((name, member) {
members[name] = member as MemberBuilder;
if (name != "values") {
members[name] = member as MemberBuilder;
}
});
scope.forEachLocalSetter((name, member) {
setters[name] = member;

View file

@ -5,6 +5,8 @@
# Note that test/spelling: Status will have no effect. Spelling errors can
# always be fixed by either spelling correctly or updating the dictionary.
EnumContainsValuesDeclaration/analyzerCode: Fail
EnumContainsValuesDeclaration/example: Fail
AbstractClassConstructorTearOff/analyzerCode: Fail
AbstractClassInstantiation/example: Fail
AbstractExtensionField/analyzerCode: Fail

View file

@ -5473,3 +5473,6 @@ EnumConstructorTearoff:
EnumFactoryRedirectsToConstructor:
problemMessage: "Enum factory constructors can't redirect to generative constructors."
EnumContainsValuesDeclaration:
problemMessage: "Enums can't contain declarations of members with the name 'values'."

View file

@ -0,0 +1,48 @@
// Copyright (c) 2022, 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.
enum E1 {
element;
static const List<E1> values = [E1.element]; // Error in E1.
}
enum E2 {
element;
int values = 42; // Error in E2.
}
enum E3 {
element;
static const List<E3> values = [E3.element]; // Error in E3.
int values = 42; // Duplicate.
}
enum E4 {
element;
static void set values(List<E4> x) {} // Ok.
}
enum E5 {
element;
static void set values(dynamic x) {} // Ok.
}
enum E6 {
element;
static void set values(Never x) {} // Error in E6.
}
enum E7 {
element;
void values() {} // Error in E7.
}
main() {}

View file

@ -0,0 +1,138 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:8:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E1> values = [E1.element]; // Error in E1.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:14:7: Error: Enums can't contain declarations of members with the name 'values'.
// int values = 42; // Error in E2.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:21:7: Error: 'values' is already declared in this scope.
// int values = 42; // Duplicate.
// ^^^^^^
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Context: Previous declaration of 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:45:8: Error: Enums can't contain declarations of members with the name 'values'.
// void values() {} // Error in E7.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:36:6: Error: The type 'List<E6>' of the getter 'E6.values' is not a subtype of the type 'Never' of the setter 'E6.values'.
// - 'List' is from 'dart:core'.
// - 'E6' is from 'pkg/front_end/testcases/enhanced_enums/declared_values.dart'.
// enum E6 {
// ^^^^^...
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:39:19: Context: This is the declaration of the setter 'E6.values'.
// static void set values(Never x) {} // Error in E6.
// ^^^^^^
//
import self as self;
import "dart:core" as core;
class E1 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E1> values = #C4;
static const field self::E1 element = #C3;
const constructor •(core::int index, core::String name) → self::E1
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E1.${this.{core::_Enum::_name}{core::String}}";
}
class E2 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E2> values = #C6;
static const field self::E2 element = #C5;
const constructor •(core::int index, core::String name) → self::E2
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E2.${this.{core::_Enum::_name}{core::String}}";
}
class E3 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E3> values = #C8;
static const field self::E3 element = #C7;
const constructor •(core::int index, core::String name) → self::E3
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E3.${this.{core::_Enum::_name}{core::String}}";
}
class E4 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E4> values = #C10;
static const field self::E4 element = #C9;
const constructor •(core::int index, core::String name) → self::E4
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E4.${this.{core::_Enum::_name}{core::String}}";
static set values(core::List<self::E4> x) → void {}
}
class E5 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E5> values = #C12;
static const field self::E5 element = #C11;
const constructor •(core::int index, core::String name) → self::E5
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E5.${this.{core::_Enum::_name}{core::String}}";
static set values(dynamic x) → void {}
}
class E6 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E6> values = #C14;
static const field self::E6 element = #C13;
const constructor •(core::int index, core::String name) → self::E6
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E6.${this.{core::_Enum::_name}{core::String}}";
static set values(Never x) → void {}
}
class E7 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E7> values = #C16;
static const field self::E7 element = #C15;
const constructor •(core::int index, core::String name) → self::E7
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E7.${this.{core::_Enum::_name}{core::String}}";
}
static method main() → dynamic {}
constants {
#C1 = 0
#C2 = "element"
#C3 = self::E1 {index:#C1, _name:#C2}
#C4 = <self::E1>[#C3]
#C5 = self::E2 {index:#C1, _name:#C2}
#C6 = <self::E2>[#C5]
#C7 = self::E3 {index:#C1, _name:#C2}
#C8 = <self::E3>[#C7]
#C9 = self::E4 {index:#C1, _name:#C2}
#C10 = <self::E4>[#C9]
#C11 = self::E5 {index:#C1, _name:#C2}
#C12 = <self::E5>[#C11]
#C13 = self::E6 {index:#C1, _name:#C2}
#C14 = <self::E6>[#C13]
#C15 = self::E7 {index:#C1, _name:#C2}
#C16 = <self::E7>[#C15]
}
Constructor coverage from constants:
org-dartlang-testcase:///declared_values.dart:
- E1. (from org-dartlang-testcase:///declared_values.dart:5:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
- E2. (from org-dartlang-testcase:///declared_values.dart:11:6)
- E3. (from org-dartlang-testcase:///declared_values.dart:17:6)
- E4. (from org-dartlang-testcase:///declared_values.dart:24:6)
- E5. (from org-dartlang-testcase:///declared_values.dart:30:6)
- E6. (from org-dartlang-testcase:///declared_values.dart:36:6)
- E7. (from org-dartlang-testcase:///declared_values.dart:42:6)

View file

@ -0,0 +1,138 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:8:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E1> values = [E1.element]; // Error in E1.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:14:7: Error: Enums can't contain declarations of members with the name 'values'.
// int values = 42; // Error in E2.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:21:7: Error: 'values' is already declared in this scope.
// int values = 42; // Duplicate.
// ^^^^^^
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Context: Previous declaration of 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:45:8: Error: Enums can't contain declarations of members with the name 'values'.
// void values() {} // Error in E7.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:36:6: Error: The type 'List<E6>' of the getter 'E6.values' is not a subtype of the type 'Never' of the setter 'E6.values'.
// - 'List' is from 'dart:core'.
// - 'E6' is from 'pkg/front_end/testcases/enhanced_enums/declared_values.dart'.
// enum E6 {
// ^^^^^...
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:39:19: Context: This is the declaration of the setter 'E6.values'.
// static void set values(Never x) {} // Error in E6.
// ^^^^^^
//
import self as self;
import "dart:core" as core;
class E1 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E1> values = #C4;
static const field self::E1 element = #C3;
const constructor •(core::int index, core::String name) → self::E1
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E1.${this.{core::_Enum::_name}{core::String}}";
}
class E2 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E2> values = #C6;
static const field self::E2 element = #C5;
const constructor •(core::int index, core::String name) → self::E2
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E2.${this.{core::_Enum::_name}{core::String}}";
}
class E3 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E3> values = #C8;
static const field self::E3 element = #C7;
const constructor •(core::int index, core::String name) → self::E3
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E3.${this.{core::_Enum::_name}{core::String}}";
}
class E4 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E4> values = #C10;
static const field self::E4 element = #C9;
const constructor •(core::int index, core::String name) → self::E4
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E4.${this.{core::_Enum::_name}{core::String}}";
static set values(core::List<self::E4> x) → void {}
}
class E5 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E5> values = #C12;
static const field self::E5 element = #C11;
const constructor •(core::int index, core::String name) → self::E5
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E5.${this.{core::_Enum::_name}{core::String}}";
static set values(dynamic x) → void {}
}
class E6 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E6> values = #C14;
static const field self::E6 element = #C13;
const constructor •(core::int index, core::String name) → self::E6
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E6.${this.{core::_Enum::_name}{core::String}}";
static set values(Never x) → void {}
}
class E7 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E7> values = #C16;
static const field self::E7 element = #C15;
const constructor •(core::int index, core::String name) → self::E7
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E7.${this.{core::_Enum::_name}{core::String}}";
}
static method main() → dynamic {}
constants {
#C1 = 0
#C2 = "element"
#C3 = self::E1 {index:#C1, _name:#C2}
#C4 = <self::E1>[#C3]
#C5 = self::E2 {index:#C1, _name:#C2}
#C6 = <self::E2>[#C5]
#C7 = self::E3 {index:#C1, _name:#C2}
#C8 = <self::E3>[#C7]
#C9 = self::E4 {index:#C1, _name:#C2}
#C10 = <self::E4>[#C9]
#C11 = self::E5 {index:#C1, _name:#C2}
#C12 = <self::E5>[#C11]
#C13 = self::E6 {index:#C1, _name:#C2}
#C14 = <self::E6>[#C13]
#C15 = self::E7 {index:#C1, _name:#C2}
#C16 = <self::E7>[#C15]
}
Constructor coverage from constants:
org-dartlang-testcase:///declared_values.dart:
- E1. (from org-dartlang-testcase:///declared_values.dart:5:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
- E2. (from org-dartlang-testcase:///declared_values.dart:11:6)
- E3. (from org-dartlang-testcase:///declared_values.dart:17:6)
- E4. (from org-dartlang-testcase:///declared_values.dart:24:6)
- E5. (from org-dartlang-testcase:///declared_values.dart:30:6)
- E6. (from org-dartlang-testcase:///declared_values.dart:36:6)
- E7. (from org-dartlang-testcase:///declared_values.dart:42:6)

View file

@ -0,0 +1,8 @@
enum E1 { element; static const List<E1> values = [E1.element]; }
enum E2 { element; int values = 42; }
enum E3 { element; static const List<E3> values = [E3.element]; int values = 42; }
enum E4 { element; static void set values(List<E4> x) {} }
enum E5 { element; static void set values(dynamic x) {} }
enum E6 { element; static void set values(Never x) {} }
enum E7 { element; void values() {} }
main() {}

View file

@ -0,0 +1,138 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:8:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E1> values = [E1.element]; // Error in E1.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:14:7: Error: Enums can't contain declarations of members with the name 'values'.
// int values = 42; // Error in E2.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:21:7: Error: 'values' is already declared in this scope.
// int values = 42; // Duplicate.
// ^^^^^^
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Context: Previous declaration of 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:45:8: Error: Enums can't contain declarations of members with the name 'values'.
// void values() {} // Error in E7.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:36:6: Error: The type 'List<E6>' of the getter 'E6.values' is not a subtype of the type 'Never' of the setter 'E6.values'.
// - 'List' is from 'dart:core'.
// - 'E6' is from 'pkg/front_end/testcases/enhanced_enums/declared_values.dart'.
// enum E6 {
// ^^^^^...
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:39:19: Context: This is the declaration of the setter 'E6.values'.
// static void set values(Never x) {} // Error in E6.
// ^^^^^^
//
import self as self;
import "dart:core" as core;
class E1 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E1> values = #C4;
static const field self::E1 element = #C3;
const constructor •(core::int index, core::String name) → self::E1
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E1.${this.{core::_Enum::_name}{core::String}}";
}
class E2 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E2> values = #C6;
static const field self::E2 element = #C5;
const constructor •(core::int index, core::String name) → self::E2
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E2.${this.{core::_Enum::_name}{core::String}}";
}
class E3 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E3> values = #C8;
static const field self::E3 element = #C7;
const constructor •(core::int index, core::String name) → self::E3
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E3.${this.{core::_Enum::_name}{core::String}}";
}
class E4 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E4> values = #C10;
static const field self::E4 element = #C9;
const constructor •(core::int index, core::String name) → self::E4
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E4.${this.{core::_Enum::_name}{core::String}}";
static set values(core::List<self::E4> x) → void {}
}
class E5 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E5> values = #C12;
static const field self::E5 element = #C11;
const constructor •(core::int index, core::String name) → self::E5
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E5.${this.{core::_Enum::_name}{core::String}}";
static set values(dynamic x) → void {}
}
class E6 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E6> values = #C14;
static const field self::E6 element = #C13;
const constructor •(core::int index, core::String name) → self::E6
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E6.${this.{core::_Enum::_name}{core::String}}";
static set values(Never x) → void {}
}
class E7 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E7> values = #C16;
static const field self::E7 element = #C15;
const constructor •(core::int index, core::String name) → self::E7
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E7.${this.{core::_Enum::_name}{core::String}}";
}
static method main() → dynamic {}
constants {
#C1 = 0
#C2 = "element"
#C3 = self::E1 {index:#C1, _name:#C2}
#C4 = <self::E1*>[#C3]
#C5 = self::E2 {index:#C1, _name:#C2}
#C6 = <self::E2*>[#C5]
#C7 = self::E3 {index:#C1, _name:#C2}
#C8 = <self::E3*>[#C7]
#C9 = self::E4 {index:#C1, _name:#C2}
#C10 = <self::E4*>[#C9]
#C11 = self::E5 {index:#C1, _name:#C2}
#C12 = <self::E5*>[#C11]
#C13 = self::E6 {index:#C1, _name:#C2}
#C14 = <self::E6*>[#C13]
#C15 = self::E7 {index:#C1, _name:#C2}
#C16 = <self::E7*>[#C15]
}
Constructor coverage from constants:
org-dartlang-testcase:///declared_values.dart:
- E1. (from org-dartlang-testcase:///declared_values.dart:5:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
- E2. (from org-dartlang-testcase:///declared_values.dart:11:6)
- E3. (from org-dartlang-testcase:///declared_values.dart:17:6)
- E4. (from org-dartlang-testcase:///declared_values.dart:24:6)
- E5. (from org-dartlang-testcase:///declared_values.dart:30:6)
- E6. (from org-dartlang-testcase:///declared_values.dart:36:6)
- E7. (from org-dartlang-testcase:///declared_values.dart:42:6)

View file

@ -0,0 +1,138 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:8:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E1> values = [E1.element]; // Error in E1.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:14:7: Error: Enums can't contain declarations of members with the name 'values'.
// int values = 42; // Error in E2.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:21:7: Error: 'values' is already declared in this scope.
// int values = 42; // Duplicate.
// ^^^^^^
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Context: Previous declaration of 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:45:8: Error: Enums can't contain declarations of members with the name 'values'.
// void values() {} // Error in E7.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:36:6: Error: The type 'List<E6>' of the getter 'E6.values' is not a subtype of the type 'Never' of the setter 'E6.values'.
// - 'List' is from 'dart:core'.
// - 'E6' is from 'pkg/front_end/testcases/enhanced_enums/declared_values.dart'.
// enum E6 {
// ^^^^^...
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:39:19: Context: This is the declaration of the setter 'E6.values'.
// static void set values(Never x) {} // Error in E6.
// ^^^^^^
//
import self as self;
import "dart:core" as core;
class E1 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E1> values = #C4;
static const field self::E1 element = #C3;
const constructor •(core::int index, core::String name) → self::E1
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E1.${this.{core::_Enum::_name}{core::String}}";
}
class E2 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E2> values = #C6;
static const field self::E2 element = #C5;
const constructor •(core::int index, core::String name) → self::E2
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E2.${this.{core::_Enum::_name}{core::String}}";
}
class E3 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E3> values = #C8;
static const field self::E3 element = #C7;
const constructor •(core::int index, core::String name) → self::E3
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E3.${this.{core::_Enum::_name}{core::String}}";
}
class E4 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E4> values = #C10;
static const field self::E4 element = #C9;
const constructor •(core::int index, core::String name) → self::E4
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E4.${this.{core::_Enum::_name}{core::String}}";
static set values(core::List<self::E4> x) → void {}
}
class E5 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E5> values = #C12;
static const field self::E5 element = #C11;
const constructor •(core::int index, core::String name) → self::E5
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E5.${this.{core::_Enum::_name}{core::String}}";
static set values(dynamic x) → void {}
}
class E6 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E6> values = #C14;
static const field self::E6 element = #C13;
const constructor •(core::int index, core::String name) → self::E6
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E6.${this.{core::_Enum::_name}{core::String}}";
static set values(Never x) → void {}
}
class E7 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E7> values = #C16;
static const field self::E7 element = #C15;
const constructor •(core::int index, core::String name) → self::E7
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E7.${this.{core::_Enum::_name}{core::String}}";
}
static method main() → dynamic {}
constants {
#C1 = 0
#C2 = "element"
#C3 = self::E1 {index:#C1, _name:#C2}
#C4 = <self::E1*>[#C3]
#C5 = self::E2 {index:#C1, _name:#C2}
#C6 = <self::E2*>[#C5]
#C7 = self::E3 {index:#C1, _name:#C2}
#C8 = <self::E3*>[#C7]
#C9 = self::E4 {index:#C1, _name:#C2}
#C10 = <self::E4*>[#C9]
#C11 = self::E5 {index:#C1, _name:#C2}
#C12 = <self::E5*>[#C11]
#C13 = self::E6 {index:#C1, _name:#C2}
#C14 = <self::E6*>[#C13]
#C15 = self::E7 {index:#C1, _name:#C2}
#C16 = <self::E7*>[#C15]
}
Constructor coverage from constants:
org-dartlang-testcase:///declared_values.dart:
- E1. (from org-dartlang-testcase:///declared_values.dart:5:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
- E2. (from org-dartlang-testcase:///declared_values.dart:11:6)
- E3. (from org-dartlang-testcase:///declared_values.dart:17:6)
- E4. (from org-dartlang-testcase:///declared_values.dart:24:6)
- E5. (from org-dartlang-testcase:///declared_values.dart:30:6)
- E6. (from org-dartlang-testcase:///declared_values.dart:36:6)
- E7. (from org-dartlang-testcase:///declared_values.dart:42:6)

View file

@ -0,0 +1,128 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:8:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E1> values = [E1.element]; // Error in E1.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:14:7: Error: Enums can't contain declarations of members with the name 'values'.
// int values = 42; // Error in E2.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:21:7: Error: 'values' is already declared in this scope.
// int values = 42; // Duplicate.
// ^^^^^^
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Context: Previous declaration of 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:45:8: Error: Enums can't contain declarations of members with the name 'values'.
// void values() {} // Error in E7.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:36:6: Error: The type 'List<E6>' of the getter 'E6.values' is not a subtype of the type 'Never' of the setter 'E6.values'.
// - 'List' is from 'dart:core'.
// - 'E6' is from 'pkg/front_end/testcases/enhanced_enums/declared_values.dart'.
// enum E6 {
// ^^^^^...
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:39:19: Context: This is the declaration of the setter 'E6.values'.
// static void set values(Never x) {} // Error in E6.
// ^^^^^^
//
import self as self;
import "dart:core" as core;
class E1 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E1> values = const <self::E1>[self::E1::element];
static const field self::E1 element = const self::E1::•(0, "element");
const constructor •(core::int index, core::String name) → self::E1
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E1.${this.{core::_Enum::_name}{core::String}}";
}
class E2 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E2> values = const <self::E2>[self::E2::element];
static const field self::E2 element = const self::E2::•(0, "element");
const constructor •(core::int index, core::String name) → self::E2
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E2.${this.{core::_Enum::_name}{core::String}}";
}
class E3 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E3> values = const <self::E3>[self::E3::element];
static const field self::E3 element = const self::E3::•(0, "element");
const constructor •(core::int index, core::String name) → self::E3
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E3.${this.{core::_Enum::_name}{core::String}}";
}
class E4 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E4> values = const <self::E4>[self::E4::element];
static const field self::E4 element = const self::E4::•(0, "element");
const constructor •(core::int index, core::String name) → self::E4
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E4.${this.{core::_Enum::_name}{core::String}}";
static set values(core::List<self::E4> x) → void
;
}
class E5 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E5> values = const <self::E5>[self::E5::element];
static const field self::E5 element = const self::E5::•(0, "element");
const constructor •(core::int index, core::String name) → self::E5
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E5.${this.{core::_Enum::_name}{core::String}}";
static set values(dynamic x) → void
;
}
class E6 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E6> values = const <self::E6>[self::E6::element];
static const field self::E6 element = const self::E6::•(0, "element");
const constructor •(core::int index, core::String name) → self::E6
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E6.${this.{core::_Enum::_name}{core::String}}";
static set values(Never x) → void
;
}
class E7 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E7> values = const <self::E7>[self::E7::element];
static const field self::E7 element = const self::E7::•(0, "element");
const constructor •(core::int index, core::String name) → self::E7
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E7.${this.{core::_Enum::_name}{core::String}}";
}
static method main() → dynamic
;
Extra constant evaluation status:
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:5:6 -> ListConstant(const <E1*>[const E1{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:6:3 -> InstanceConstant(const E1{_Enum.index: 0, _Enum._name: "element"})
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:11:6 -> ListConstant(const <E2*>[const E2{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:12:3 -> InstanceConstant(const E2{_Enum.index: 0, _Enum._name: "element"})
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:17:6 -> ListConstant(const <E3*>[const E3{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:18:3 -> InstanceConstant(const E3{_Enum.index: 0, _Enum._name: "element"})
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:24:6 -> ListConstant(const <E4*>[const E4{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:25:3 -> InstanceConstant(const E4{_Enum.index: 0, _Enum._name: "element"})
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:30:6 -> ListConstant(const <E5*>[const E5{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:31:3 -> InstanceConstant(const E5{_Enum.index: 0, _Enum._name: "element"})
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:36:6 -> ListConstant(const <E6*>[const E6{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:37:3 -> InstanceConstant(const E6{_Enum.index: 0, _Enum._name: "element"})
Evaluated: ListLiteral @ org-dartlang-testcase:///declared_values.dart:42:6 -> ListConstant(const <E7*>[const E7{_Enum.index: 0, _Enum._name: "element"}])
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///declared_values.dart:43:3 -> InstanceConstant(const E7{_Enum.index: 0, _Enum._name: "element"})
Extra constant evaluation: evaluated: 49, effectively constant: 14

View file

@ -0,0 +1,138 @@
library /*isNonNullableByDefault*/;
//
// Problems in library:
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:8:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E1> values = [E1.element]; // Error in E1.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:14:7: Error: Enums can't contain declarations of members with the name 'values'.
// int values = 42; // Error in E2.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:21:7: Error: 'values' is already declared in this scope.
// int values = 42; // Duplicate.
// ^^^^^^
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Context: Previous declaration of 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:20:25: Error: Enums can't contain declarations of members with the name 'values'.
// static const List<E3> values = [E3.element]; // Error in E3.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:45:8: Error: Enums can't contain declarations of members with the name 'values'.
// void values() {} // Error in E7.
// ^^^^^^
//
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:36:6: Error: The type 'List<E6>' of the getter 'E6.values' is not a subtype of the type 'Never' of the setter 'E6.values'.
// - 'List' is from 'dart:core'.
// - 'E6' is from 'pkg/front_end/testcases/enhanced_enums/declared_values.dart'.
// enum E6 {
// ^^^^^...
// pkg/front_end/testcases/enhanced_enums/declared_values.dart:39:19: Context: This is the declaration of the setter 'E6.values'.
// static void set values(Never x) {} // Error in E6.
// ^^^^^^
//
import self as self;
import "dart:core" as core;
class E1 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E1> values = #C4;
static const field self::E1 element = #C3;
const constructor •(core::int index, core::String name) → self::E1
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E1.${this.{core::_Enum::_name}{core::String}}";
}
class E2 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E2> values = #C6;
static const field self::E2 element = #C5;
const constructor •(core::int index, core::String name) → self::E2
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E2.${this.{core::_Enum::_name}{core::String}}";
}
class E3 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E3> values = #C8;
static const field self::E3 element = #C7;
const constructor •(core::int index, core::String name) → self::E3
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E3.${this.{core::_Enum::_name}{core::String}}";
}
class E4 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E4> values = #C10;
static const field self::E4 element = #C9;
const constructor •(core::int index, core::String name) → self::E4
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E4.${this.{core::_Enum::_name}{core::String}}";
static set values(core::List<self::E4> x) → void {}
}
class E5 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E5> values = #C12;
static const field self::E5 element = #C11;
const constructor •(core::int index, core::String name) → self::E5
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E5.${this.{core::_Enum::_name}{core::String}}";
static set values(dynamic x) → void {}
}
class E6 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E6> values = #C14;
static const field self::E6 element = #C13;
const constructor •(core::int index, core::String name) → self::E6
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E6.${this.{core::_Enum::_name}{core::String}}";
static set values(Never x) → void {}
}
class E7 extends core::_Enum /*isEnum*/ {
static const field core::List<self::E7> values = #C16;
static const field self::E7 element = #C15;
const constructor •(core::int index, core::String name) → self::E7
: super core::_Enum::•(index, name)
;
method toString() → core::String
return "E7.${this.{core::_Enum::_name}{core::String}}";
}
static method main() → dynamic {}
constants {
#C1 = 0
#C2 = "element"
#C3 = self::E1 {index:#C1, _name:#C2}
#C4 = <self::E1*>[#C3]
#C5 = self::E2 {index:#C1, _name:#C2}
#C6 = <self::E2*>[#C5]
#C7 = self::E3 {index:#C1, _name:#C2}
#C8 = <self::E3*>[#C7]
#C9 = self::E4 {index:#C1, _name:#C2}
#C10 = <self::E4*>[#C9]
#C11 = self::E5 {index:#C1, _name:#C2}
#C12 = <self::E5*>[#C11]
#C13 = self::E6 {index:#C1, _name:#C2}
#C14 = <self::E6*>[#C13]
#C15 = self::E7 {index:#C1, _name:#C2}
#C16 = <self::E7*>[#C15]
}
Constructor coverage from constants:
org-dartlang-testcase:///declared_values.dart:
- E1. (from org-dartlang-testcase:///declared_values.dart:5:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
- E2. (from org-dartlang-testcase:///declared_values.dart:11:6)
- E3. (from org-dartlang-testcase:///declared_values.dart:17:6)
- E4. (from org-dartlang-testcase:///declared_values.dart:24:6)
- E5. (from org-dartlang-testcase:///declared_values.dart:30:6)
- E6. (from org-dartlang-testcase:///declared_values.dart:36:6)
- E7. (from org-dartlang-testcase:///declared_values.dart:42:6)

View file

@ -30,6 +30,7 @@ dart2js/late_fields: FormatterCrash
dart2js/late_statics: FormatterCrash
enhanced_enums/conflicting_elements: FormatterCrash
enhanced_enums/constructor_calls: FormatterCrash
enhanced_enums/declared_values: FormatterCrash
enhanced_enums/entries_with_type_arguments: FormatterCrash
enhanced_enums/enum_as_supertype: FormatterCrash
enhanced_enums/inference_in_constructor_parameters: FormatterCrash