From 1b87e5535df5a96fe06d06ad96b3b24e227930cf Mon Sep 17 00:00:00 2001 From: MVitelli Date: Tue, 24 Dec 2024 00:03:33 +0100 Subject: [PATCH] fix: should match superclass not working with if else --- src/validator/index.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/validator/index.ts b/src/validator/index.ts index a734fa9d..f826d3d3 100644 --- a/src/validator/index.ts +++ b/src/validator/index.ts @@ -224,9 +224,26 @@ export const shouldMatchSuperclassReturnValue = error(node => { if (!overridenMethod || overridenMethod.isAbstract() || overridenMethod.isNative()) return true const lastSentence = last(node.sentences) const superclassSentence = last(overridenMethod.sentences) - return !lastSentence || !superclassSentence || lastSentence.is(Return) === superclassSentence.is(Return) || lastSentence.is(Throw) || superclassSentence.is(Throw) + + const isCompatibleWithSuperclass = (sentence: Sentence | undefined) => + !sentence || !superclassSentence || sentence.is(Return) === superclassSentence.is(Return) || sentence.is(Throw) || superclassSentence.is(Throw) + + if (node.sentences.length === 1 && node.sentences[0].is(If)) { + const [ifSentence] = node.sentences + + const lastThenSentence = last(ifSentence.thenBody.sentences) + const lastElseSentence = last(ifSentence.elseBody.sentences) + + const thenOK = isCompatibleWithSuperclass(lastThenSentence) + const elseOK = isCompatibleWithSuperclass(lastElseSentence) + + return thenOK && elseOK + } + + return isCompatibleWithSuperclass(lastSentence) }, valuesForNodeName, sourceMapForBody) + export const shouldReturnAValueOnAllFlows = error(node => { const lastThenSentence = last(node.thenBody.sentences) const lastElseSentence = last(node.elseBody.sentences)