Skip to content

Commit

Permalink
Fixed a false positive "incompatible method override" error in a case…
Browse files Browse the repository at this point in the history
… that involves both class-scoped and method-scoped type variables. This addresses #9347. (#9348)
  • Loading branch information
erictraut authored Oct 29, 2024
1 parent 2ffc5f1 commit 84b77b0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 180 deletions.
7 changes: 4 additions & 3 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6558,9 +6558,11 @@ export class Checker extends ParseTreeWalker {
}

const baseClass = baseClassAndSymbol.classType;
const childClassSelf = ClassType.cloneAsInstance(selfSpecializeClass(childClassType));
const childClassSelf = ClassType.cloneAsInstance(
selfSpecializeClass(childClassType, { useBoundTypeVars: true })
);

let baseType = partiallySpecializeType(
const baseType = partiallySpecializeType(
this._evaluator.getEffectiveTypeOfSymbol(baseClassAndSymbol.symbol),
baseClass,
this._evaluator.getTypeClassType(),
Expand All @@ -6575,7 +6577,6 @@ export class Checker extends ParseTreeWalker {
);

if (childClassType.shared.typeVarScopeId) {
baseType = makeTypeVarsBound(baseType, [childClassType.shared.typeVarScopeId]);
overrideType = makeTypeVarsBound(overrideType, [childClassType.shared.typeVarScopeId]);
}

Expand Down
19 changes: 10 additions & 9 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26812,6 +26812,7 @@ export function createTypeEvaluator(
): boolean {
const baseParamDetails = getParamListDetails(baseMethod);
const overrideParamDetails = getParamListDetails(overrideMethod);
const constraints = new ConstraintTracker();

let canOverride = true;

Expand Down Expand Up @@ -26853,8 +26854,8 @@ export function createTypeEvaluator(
overrideArgsType,
baseParamDetails.params[i].type,
diag?.createAddendum(),
/* constraints */ undefined,
AssignTypeFlags.Default
constraints,
AssignTypeFlags.Contravariant
)
) {
LocAddendum.overrideParamType().format({
Expand Down Expand Up @@ -26976,8 +26977,8 @@ export function createTypeEvaluator(
overrideParamType,
baseParamType,
diag?.createAddendum(),
/* constraints */ undefined,
AssignTypeFlags.Default
constraints,
AssignTypeFlags.Contravariant
)
) {
diag?.addMessage(
Expand Down Expand Up @@ -27038,8 +27039,8 @@ export function createTypeEvaluator(
overrideParamType,
baseParamType,
diag?.createAddendum(),
/* constraints */ undefined,
AssignTypeFlags.Default
constraints,
AssignTypeFlags.Contravariant
)
) {
diag?.addMessage(
Expand Down Expand Up @@ -27083,8 +27084,8 @@ export function createTypeEvaluator(
targetParamType,
paramInfo.type,
diag?.createAddendum(),
/* constraints */ undefined,
AssignTypeFlags.Default
constraints,
AssignTypeFlags.Contravariant
)
) {
diag?.addMessage(
Expand Down Expand Up @@ -27164,7 +27165,7 @@ export function createTypeEvaluator(
baseReturnType,
overrideReturnType,
diag?.createAddendum(),
/* constraints */ undefined,
constraints,
AssignTypeFlags.Default
)
) {
Expand Down
Loading

0 comments on commit 84b77b0

Please sign in to comment.