@@ -2933,11 +2933,23 @@ 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 baseIsGeneric = basePrototype . typeParameterNodes != null && basePrototype . typeParameterNodes . length > 0 ;
2938+ let instanceIsGeneric = typeArguments != null && typeArguments . length > 0 ;
2939+ if ( baseIsGeneric != instanceIsGeneric ) {
2940+ // Cannot mix generic and non-generic functions in an override chain
2941+ this . errorRelated (
2942+ DiagnosticCode . Cannot_override_generic_method_0_with_a_non_generic_method_or_vice_versa ,
2943+ instance . identifierAndSignatureRange , baseMember . identifierAndSignatureRange ,
2944+ methodOrPropertyName
2945+ ) ;
2946+ incompatibleOverride = false ; // already reported
2947+ } else {
2948+ // Possibly generic. Resolve with same type arguments to obtain the correct one.
2949+ let baseFunction = this . resolveFunction ( basePrototype , typeArguments , new Map ( ) , ReportMode . Swallow ) ;
2950+ if ( baseFunction && instance . signature . isAssignableTo ( baseFunction . signature , true ) ) {
2951+ incompatibleOverride = false ;
2952+ }
29412953 }
29422954 }
29432955 }
@@ -3069,11 +3081,8 @@ export class Resolver extends DiagnosticEmitter {
30693081 // arguments to forward to the monomorphized child.
30703082 // - generic child → generic base: OK; type args come from the base call site.
30713083 // - 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 ) ) {
3084+ // - non-generic child → generic base: skip; mismatched generic-ness.
3085+ if ( boundFuncPrototype . is ( CommonFlags . Generic ) == instance . is ( CommonFlags . Generic ) ) {
30773086 overrideInstance = this . resolveFunction ( boundFuncPrototype , instance . typeArguments ) ;
30783087 }
30793088 }
0 commit comments