Skip to content

Commit

Permalink
fix: should match superclass not working with if else
Browse files Browse the repository at this point in the history
  • Loading branch information
MVitelli committed Dec 23, 2024
1 parent 59c43f7 commit 1b87e55
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,26 @@ export const shouldMatchSuperclassReturnValue = error<Method>(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) =>

Check warning on line 228 in src/validator/index.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
!sentence || !superclassSentence || sentence.is(Return) === superclassSentence.is(Return) || sentence.is(Throw) || superclassSentence.is(Throw)

Check warning on line 230 in src/validator/index.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
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<If>(node => {
const lastThenSentence = last(node.thenBody.sentences)
const lastElseSentence = last(node.elseBody.sentences)
Expand Down

0 comments on commit 1b87e55

Please sign in to comment.