File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -391,7 +391,9 @@ class BinaryExpressionResolver {
391
391
}
392
392
393
393
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 ) {
395
397
staticType ?? = DynamicTypeImpl .instance;
396
398
} else {
397
399
staticType ?? = InvalidTypeImpl .instance;
Original file line number Diff line number Diff line change @@ -17,6 +17,37 @@ main() {
17
17
@reflectiveTest
18
18
class BinaryExpressionResolutionTest extends PubPackageResolutionTest
19
19
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
+
20
51
test_eqEq_switchExpression_left () async {
21
52
await assertNoErrorsInCode (r'''
22
53
void f(Object? x) {
@@ -742,7 +773,7 @@ BinaryExpression
742
773
staticType: int
743
774
staticElement: <null>
744
775
staticInvokeType: null
745
- staticType: InvalidType
776
+ staticType: bool
746
777
''' );
747
778
}
748
779
You can’t perform that action at this time.
0 commit comments