rokucommunity / bslint

A linter for BrightScript and BrighterScript.
MIT License
27 stars 14 forks source link

spurius "error BSLINT2004: Not all code paths return a value" #76

Closed ZeeD closed 1 year ago

ZeeD commented 1 year ago

minimal test:

function foo() as Integer
    throw "error"
end function

running bslint on this snippet will return the error message error BSLINT2004: Not all code paths return a value, but IMHO this is a false result, as all branches here return (or, in this case throw) some value.

For instance I have the same error even on little variations, like

function foo1(bar as Boolean) as Integer
    if bar then return 42
    throw "error"
end function

but not on a (conceptually equals) variant, like

function foo2(bar as Boolean) as Integer
    if not bar then  throw "error"
    return 42
end function
ZeeD commented 1 year ago

oh, and it seems that adding a spurious return after the throw makes bslint happy - it seems that the tool just ignore the throw flow

TwitchBronBron commented 1 year ago

Closing as this is already being tracked by #71 . But yes, this is definitely something we need to fix at some point. I'd be happy to help you set up the bslint project to fix the bug if you're interested (I'm swamped with other work so this is a bit lower of a priority).

ZeeD commented 1 year ago

(oh, sorry for the duplicate, I searched with the error code and totally missed the other issue with the same error message)

TwitchBronBron commented 1 year ago

(oh, sorry for the duplicate, I searched with the error code and totally missed the other issue with the same error message)

No worries!