analyzer: Support operators in extension on a type variable type

Fixes https://github.com/dart-lang/sdk/issues/54462

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: If0c2a29559d86830434ae9c68ae1f0da72380741
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372840
Commit-Queue: Sam Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Sam Rawlins 2024-06-24 17:37:29 +00:00 committed by Commit Queue
parent 87ca13f90a
commit 89d9912790
2 changed files with 29 additions and 1 deletions

View file

@ -407,7 +407,6 @@ class BinaryExpressionResolver {
}
var leftType = leftOperand.typeOrThrow;
leftType = _typeSystem.resolveToBound(leftType);
if (identical(leftType, NeverTypeImpl.instance)) {
_resolver.errorReporter.atNode(

View file

@ -1788,6 +1788,35 @@ BinaryExpression
''');
}
test_plus_int_typeVariable_via_extension() async {
await assertNoErrorsInCode('''
class Foo {}
extension FooExtension<F extends Foo> on F {
F operator +(int i) => this;
F get gg => this + 1;
}
''');
assertResolvedNodeText(findNode.binary('this + 1'), r'''
BinaryExpression
leftOperand: ThisExpression
thisKeyword: this
staticType: F
operator: +
rightOperand: IntegerLiteral
literal: 1
parameter: root::@parameter::i
staticType: int
staticElement: MethodMember
base: self::@extension::FooExtension::@method::+
substitution: {F: F}
staticInvokeType: F Function(int)
staticType: F
''');
}
test_plus_invalidType_int() async {
await assertErrorsInCode(r'''
void f() {