Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should match superclass not working with if else #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,23 @@
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

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

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 => {
Expand Down
Loading