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

False negatives for BS1011 (same name as global function) #70

Closed
TwitchBronBron opened this issue May 3, 2020 · 2 comments
Closed

False negatives for BS1011 (same name as global function) #70

TwitchBronBron opened this issue May 3, 2020 · 2 comments

Comments

@TwitchBronBron
Copy link
Member

This is false.

src/components/RALETRackerTask.brs:417:5 - undefined BS1011: Local var 'str' has same name as global function in 'platform' and will never be called.
417 str = number.toStr()
417 ~~~

@TwitchBronBron
Copy link
Member Author

There was definitely a reason I created this rule, so I'm thinking it's just overreaching and applying to situations it was not intended. I need to create an exhaustive list of possible ways to override parent scope methods and narrow this checking to only the situations that apply.

@TwitchBronBron
Copy link
Member Author

TwitchBronBron commented May 3, 2020

@georgejecook I ran a few tests, and here are the results:

  1. Source Scope : override built-in function with own function
sub main()
    str = function(p)
        return "override"
    end function
    print str(12345) 'prints "12345" (i.e. our local function is never used)
end sub
  1. Source scope: override built-in function with own variable
sub main()
    str = 12345
    print str ' prints "12345" (i.e. our local variable overrode the name)
end sub
  1. Source scope: override built-in function with own variable and call it
sub main()
    str = 6789
    print str(12345) ' prints "12345" (i.e. our local variable did not override the callable global function)
end sub
  1. source scope: override same-scope function with own function
sub main()
    getHello = function()
        return "override"
    end function
    print getHello() 'prints "hello" (i.e. our local variable is never used)
end sub

function getHello()
    return "hello"
end function
  1. source scope: override same-scope function with own variable
sub main()
    getHello = "override"
    print getHello ' prints <Function: gethello> (i.e. local variable override does NOT work for same-scope-defined methods)
end sub
function getHello()
    return "hello"
end function
  1. Scope function with same name as built-in-function
sub main()
    print str(12345) ' prints 12345 (i.e. our str() function below is ignored)
end sub
function str(num)
    return "override"
end function

Conclusion

  • BS1011 should be shown for 1 and 4.
  • 2 and 3 should not have any error.
  • 5 should get its own error message
  • 6 should get its own error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant