Skip to content

Commit

Permalink
[CP] Issue 49097. Resolve constants in enhanced enum constructors/met…
Browse files Browse the repository at this point in the history
…hods.

Bug: #49097
Change-Id: I9fccbd2f70d94f7d6cfe780b8d4fadf1708eb7a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245909
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and whesse committed Jun 1, 2022
1 parent b144eaa commit 59ac492
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/summary2/default_value_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DefaultValueResolver {
for (var unitElement in _libraryElement.units.impl) {
_UnitContext(unitElement)
..forEach(unitElement.classes, _class)
..forEach(unitElement.enums, _class)
..forEach(unitElement.extensions, _extension)
..forEach(unitElement.functions, _executable)
..forEach(unitElement.mixins, _class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ class A {
]);
}

test_enum_issue49097() async {
newFile2('$testPackageLibPath/a.dart', r'''
class A {
static const foo = A();
static const bar = A();
const A();
}
''');
await assertNoErrorsInCode(r'''
import 'a.dart';
enum E {
v(f: A.foo);
final A f;
const E({this.f = A.bar});
}
''');
}

test_function_named() async {
await assertErrorsInCode(r'''
int y = 0;
Expand Down
73 changes: 73 additions & 0 deletions pkg/analyzer/test/src/summary/elements_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17847,6 +17847,79 @@ library
''');
}

test_enum_constructor_fieldFormal_optionalNamed_defaultValue() async {
var library = await buildLibrary(r'''
enum E {
v;
final int x;
const E({this.x = 1 + 2});
}
''');
checkElementText(library, r'''
library
definingUnit
enums
enum E @5
supertype: Enum
fields
static const enumConstant v @11
type: E
constantInitializer
InstanceCreationExpression
constructorName: ConstructorName
type: NamedType
name: SimpleIdentifier
token: E @-1
staticElement: self::@enum::E
staticType: null
type: E
staticElement: self::@enum::E::@constructor::•
argumentList: ArgumentList
leftParenthesis: ( @0
rightParenthesis: ) @0
staticType: E
synthetic static const values @-1
type: List<E>
constantInitializer
ListLiteral
leftBracket: [ @0
elements
SimpleIdentifier
token: v @-1
staticElement: self::@enum::E::@getter::v
staticType: E
rightBracket: ] @0
staticType: List<E>
final x @26
type: int
constructors
const @37
parameters
optionalNamed final this.x @45
type: int
constantInitializer
BinaryExpression
leftOperand: IntegerLiteral
literal: 1 @49
staticType: int
operator: + @51
rightOperand: IntegerLiteral
literal: 2 @53
staticType: int
staticElement: dart:core::@class::num::@method::+
staticInvokeType: num Function(num)
staticType: int
field: self::@enum::E::@field::x
accessors
synthetic static get v @-1
returnType: E
synthetic static get values @-1
returnType: List<E>
synthetic get x @-1
returnType: int
''');
}

test_enum_constructor_fieldFormal_typed_typed() async {
var library = await buildLibrary('''
enum E {
Expand Down

0 comments on commit 59ac492

Please sign in to comment.