@@ -2933,11 +2933,24 @@ export class Resolver extends DiagnosticEmitter {
29332933 incompatibleOverride = false ;
29342934 } else {
29352935 if ( baseMember . kind == ElementKind . FunctionPrototype ) {
2936- // Possibly generic. Resolve with same type arguments to obtain the correct one.
29372936 let basePrototype = < FunctionPrototype > baseMember ;
2938- let baseFunction = this . resolveFunction ( basePrototype , typeArguments , new Map ( ) , ReportMode . Swallow ) ;
2939- if ( baseFunction && instance . signature . isAssignableTo ( baseFunction . signature , true ) ) {
2940- incompatibleOverride = false ;
2937+ let baseTypeParameterNodes = basePrototype . typeParameterNodes ;
2938+ let baseIsGeneric = baseTypeParameterNodes != null && baseTypeParameterNodes . length > 0 ;
2939+ let instanceIsGeneric = typeArguments != null && typeArguments . length > 0 ;
2940+ if ( baseIsGeneric != instanceIsGeneric ) {
2941+ // Cannot mix generic and non-generic functions in an override chain
2942+ this . errorRelated (
2943+ DiagnosticCode . Cannot_override_generic_method_0_with_a_non_generic_method_or_vice_versa ,
2944+ instance . identifierAndSignatureRange , baseMember . identifierAndSignatureRange ,
2945+ methodOrPropertyName
2946+ ) ;
2947+ incompatibleOverride = false ; // already reported
2948+ } else {
2949+ // Possibly generic. Resolve with same type arguments to obtain the correct one.
2950+ let baseFunction = this . resolveFunction ( basePrototype , typeArguments , new Map ( ) , ReportMode . Swallow ) ;
2951+ if ( baseFunction && instance . signature . isAssignableTo ( baseFunction . signature , true ) ) {
2952+ incompatibleOverride = false ;
2953+ }
29412954 }
29422955 }
29432956 }
@@ -3069,11 +3082,8 @@ export class Resolver extends DiagnosticEmitter {
30693082 // arguments to forward to the monomorphized child.
30703083 // - generic child → generic base: OK; type args come from the base call site.
30713084 // - non-generic child → non-generic base: OK; plain vtable override.
3072- // FIXME: non-generic child → generic base is also mismatched (resolveFunction
3073- // would assert on typeArguments/typeParameterNodes length mismatch) but that
3074- // case is not yet guarded here. The correct fix is to replace this condition
3075- // with `boundFuncPrototype.is(Generic) == instance.is(Generic)`.
3076- if ( ! boundFuncPrototype . is ( CommonFlags . Generic ) || instance . is ( CommonFlags . Generic ) ) {
3085+ // - non-generic child → generic base: skip; mismatched generic-ness.
3086+ if ( boundFuncPrototype . is ( CommonFlags . Generic ) == instance . is ( CommonFlags . Generic ) ) {
30773087 overrideInstance = this . resolveFunction ( boundFuncPrototype , instance . typeArguments ) ;
30783088 }
30793089 }
0 commit comments