Skip to content

Commit d070ea7

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Fix a TypeImpl cast in BinaryExpressionResolver.
Change-Id: I2618b45d89aec3962afef17a5db9c7e387bd56d3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411500 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent efd357f commit d070ea7

File tree

9 files changed

+27
-23
lines changed

9 files changed

+27
-23
lines changed

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ final class AssignmentExpressionImpl extends ExpressionImpl
886886
ExpressionImpl _rightHandSide;
887887

888888
@override
889-
MethodElement? staticElement;
889+
MethodElementOrMember? staticElement;
890890

891891
/// Initializes a newly created assignment expression.
892892
AssignmentExpressionImpl({
@@ -904,9 +904,9 @@ final class AssignmentExpressionImpl extends ExpressionImpl
904904

905905
@experimental
906906
@override
907-
MethodElement2? get element => staticElement?.asElement2;
907+
MethodElement2OrMember? get element => staticElement?.asElement2;
908908

909-
set element(MethodElement2? element) {
909+
set element(MethodElement2OrMember? element) {
910910
staticElement = element?.asElement;
911911
}
912912

@@ -1837,7 +1837,7 @@ final class BinaryExpressionImpl extends ExpressionImpl
18371837
MethodElement? staticElement;
18381838

18391839
@override
1840-
FunctionType? staticInvokeType;
1840+
FunctionTypeImpl? staticInvokeType;
18411841

18421842
/// Initializes a newly created binary expression.
18431843
BinaryExpressionImpl({

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5985,7 +5985,7 @@ abstract class InstanceElementImpl2 extends ElementImpl2
59855985
}
59865986

59875987
@override
5988-
MethodElement2? getMethod2(String name) {
5988+
MethodElement2OrMember? getMethod2(String name) {
59895989
return methods2.firstWhereOrNull((e) => e.lookupName == name);
59905990
}
59915991

pkg/analyzer/lib/src/dart/element/type_system.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,11 +1526,11 @@ class TypeSystemImpl implements TypeSystem {
15261526
/// Determine the type of a binary expression with the given [operator] whose
15271527
/// left operand has the type [leftType] and whose right operand has the type
15281528
/// [rightType], given that resolution has so far produced the [currentType].
1529-
DartType refineBinaryExpressionType(
1529+
TypeImpl refineBinaryExpressionType(
15301530
DartType leftType,
15311531
TokenType operator,
15321532
DartType rightType,
1533-
DartType currentType,
1533+
TypeImpl currentType,
15341534
MethodElement2? operatorElement) {
15351535
if (operatorElement == null) return currentType;
15361536
return _refineNumericInvocationTypeNullSafe(
@@ -1562,11 +1562,11 @@ class TypeSystemImpl implements TypeSystem {
15621562
/// produced so far by resolution is [currentType].
15631563
///
15641564
// TODO(scheglov): I expected that [methodElement] is [MethodElement].
1565-
DartType refineNumericInvocationType(
1565+
TypeImpl refineNumericInvocationType(
15661566
DartType targetType,
15671567
Element2? methodElement,
15681568
List<DartType> argumentTypes,
1569-
DartType currentType) {
1569+
TypeImpl currentType) {
15701570
if (methodElement is MethodElement2) {
15711571
return _refineNumericInvocationTypeNullSafe(
15721572
targetType, methodElement, argumentTypes, currentType);
@@ -1960,11 +1960,11 @@ class TypeSystemImpl implements TypeSystem {
19601960
return currentType;
19611961
}
19621962

1963-
DartType _refineNumericInvocationTypeNullSafe(
1963+
TypeImpl _refineNumericInvocationTypeNullSafe(
19641964
DartType targetType,
19651965
MethodElement2 methodElement,
19661966
List<DartType> argumentTypes,
1967-
DartType currentType) {
1967+
TypeImpl currentType) {
19681968
// If the method being invoked comes from an extension, don't refine the
19691969
// type because we can only make guarantees about methods defined in the
19701970
// SDK, and the numeric methods we refine are all instance methods.

pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class AssignmentExpressionResolver {
252252
propertyErrorEntity: operator,
253253
nameErrorEntity: operator,
254254
);
255-
node.element = result.getter2 as MethodElement2?;
255+
node.element = result.getter2 as MethodElement2OrMember?;
256256
if (result.needsGetterError) {
257257
_errorReporter.atToken(
258258
operator,

pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,7 @@ class BinaryExpressionResolver {
291291
// using the operator method's parameter type.
292292
var rightParam = invokeType.formalParameters[0];
293293
rightContextType = _typeSystem.refineNumericInvocationContext2(
294-
left.staticType,
295-
node.element,
296-
contextType,
297-
// TODO(paulberry): eliminate this cast by changing the type of
298-
// `FunctionTypeImpl.parameters` to `List<ParameterElementMixin>`.
299-
rightParam.type as TypeImpl);
294+
left.staticType, node.element, contextType, rightParam.type);
300295
} else {
301296
rightContextType = UnknownInferredType.instance;
302297
}
@@ -370,7 +365,7 @@ class BinaryExpressionResolver {
370365
left.setPseudoExpressionStaticType(InvalidTypeImpl.instance);
371366

372367
switch (augmentationTarget) {
373-
case MethodFragment fragment:
368+
case MethodElementImpl fragment:
374369
left.fragment = fragment;
375370
left.setPseudoExpressionStaticType(
376371
_resolver.thisType ?? InvalidTypeImpl.instance);

pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ abstract class FullInvocationInferrer<Node extends AstNodeImpl>
315315
];
316316
}
317317

318-
DartType _refineReturnType(DartType returnType) => returnType;
318+
TypeImpl _refineReturnType(TypeImpl returnType) => returnType;
319319

320320
void _reportWrongNumberOfTypeArguments(TypeArgumentList typeArgumentList,
321321
FunctionType rawType, List<TypeParameterElement2> typeParameters) {
@@ -639,7 +639,7 @@ class MethodInvocationInferrer
639639
}
640640

641641
@override
642-
DartType _refineReturnType(DartType returnType) {
642+
TypeImpl _refineReturnType(TypeImpl returnType) {
643643
var targetType = node.realTarget?.staticType;
644644
if (targetType != null) {
645645
returnType = resolver.typeSystem.refineNumericInvocationType(

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class AstBinaryReader {
273273
operator: Tokens.fromType(operatorType),
274274
rightHandSide: rightHandSide,
275275
);
276-
node.staticElement = _reader.readElement() as MethodElement?;
276+
node.staticElement = _reader.readElement() as MethodElementOrMember?;
277277
node.readElement = _reader.readElement();
278278
node.readType = _reader.readType();
279279
node.writeElement = _reader.readElement();

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ class ResolutionReader {
21462146
);
21472147
}
21482148

2149-
FunctionType? readOptionalFunctionType() {
2149+
FunctionTypeImpl? readOptionalFunctionType() {
21502150
var type = readType();
21512151
return type is FunctionTypeImpl ? type : null;
21522152
}

pkg/analyzer/lib/src/utilities/extensions/element.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,15 @@ extension MethodElement2Extension on MethodElement2 {
555555
}
556556
}
557557

558+
extension MethodElement2OrMemberExtension on MethodElement2OrMember {
559+
MethodElementOrMember get asElement {
560+
if (this case MethodMember member) {
561+
return member;
562+
}
563+
return (this as MethodElementImpl2).lastFragment;
564+
}
565+
}
566+
558567
extension MethodElementExtension on MethodElement {
559568
MethodElement2 get asElement2 {
560569
return switch (this) {

0 commit comments

Comments
 (0)