Skip to content

Commit 11c84d0

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Extension type. Issue 54080. The result of == is always 'bool'.
Bug: #54080 Change-Id: I5deff67f480b24dc719d438bc7df5a7697772bee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337281 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 3c3dd78 commit 11c84d0

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ class BinaryExpressionResolver {
391391
}
392392

393393
var staticType = node.staticInvokeType?.returnType;
394-
if (leftType is DynamicType) {
394+
if (node.operator.type == TokenType.EQ_EQ) {
395+
staticType = _typeSystem.typeProvider.boolType;
396+
} else if (leftType is DynamicType) {
395397
staticType ??= DynamicTypeImpl.instance;
396398
} else {
397399
staticType ??= InvalidTypeImpl.instance;

pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart

+32-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,37 @@ main() {
1717
@reflectiveTest
1818
class BinaryExpressionResolutionTest extends PubPackageResolutionTest
1919
with BinaryExpressionResolutionTestCases {
20+
test_eqEq_alwaysBool() async {
21+
await assertNoErrorsInCode(r'''
22+
extension type MyBool(bool it) implements bool {}
23+
24+
class A {
25+
MyBool operator ==(_) => MyBool(true);
26+
}
27+
28+
void f(A a) {
29+
a == 0;
30+
}
31+
''');
32+
33+
final node = findNode.binary('a == 0');
34+
assertResolvedNodeText(node, r'''
35+
BinaryExpression
36+
leftOperand: SimpleIdentifier
37+
token: a
38+
staticElement: self::@function::f::@parameter::a
39+
staticType: A
40+
operator: ==
41+
rightOperand: IntegerLiteral
42+
literal: 0
43+
parameter: self::@class::A::@method::==::@parameter::_
44+
staticType: int
45+
staticElement: self::@class::A::@method::==
46+
staticInvokeType: MyBool Function(Object)
47+
staticType: bool
48+
''');
49+
}
50+
2051
test_eqEq_switchExpression_left() async {
2152
await assertNoErrorsInCode(r'''
2253
void f(Object? x) {
@@ -742,7 +773,7 @@ BinaryExpression
742773
staticType: int
743774
staticElement: <null>
744775
staticInvokeType: null
745-
staticType: InvalidType
776+
staticType: bool
746777
''');
747778
}
748779

0 commit comments

Comments
 (0)