Skip to content

positionInRange function in PluginUtils doesn't work as its name suggests #2618

Closed
@kokobd

Description

@kokobd

Look closely at this function:

positionInRange :: Position -> Range -> Bool
positionInRange (Position pl po) (Range (Position sl so) (Position el eo)) =
pl > sl && pl < el
|| pl == sl && pl == el && po >= so && po <= eo
|| pl == sl && po >= so
|| pl == el && po <= eo

If this range has only 1 line, and the position lies in the same line as the range, but after the end of the range, then,
the second branch will fail, but the third branch will succeed, which is not expected, I think.

Your environment

Which OS do you use:

Ubuntu 20.04

Steps to reproduce

I wrote a testcase for that

tests :: TestTree
tests = testGroup "PluginUtils"
    [ testCase "positionInRange" $
        positionInRange (Position 1 10) (Range (Position 1 1) (Position 1 3)) @?= False
    ]

Expected behaviour

Position 1 10 is not in the range of Position 1 1 and Position 1 3. The above testcase should pass.

Actual behaviour

The testcase fails
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triagetype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions