Skip to content

Commit

Permalink
Fix #237 (#243)
Browse files Browse the repository at this point in the history
The bug was caused by broken transitivity of the comparison function used to
sort spans. Nested spans were meant to be sorted in innermost-first order, with
the first (innermost) one being used to get type information about the symbol at
a given position.

Because the comparison function considered any two non-nested spans to be EQ,
the sort could incorrectly conclude (by transitivity) that two nested spans were
equal, and thus leave them in incorrect relative order. This resulted in the
innermost span sometimes not appearing at the front of the list of spans which
enclose a given point, and hover reporting the type of a bigger expression in
which the point appeared.

The solution imposes ordering on non-nested spans by comparing their starting
positions, thus fixing transitivity.

Fixes #237 (... probably along with a bunch of other little bugs caused by the
same mistake).
  • Loading branch information
jacg authored and cocreature committed Dec 14, 2019
1 parent 069e8ee commit 87f449d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Development/IDE/Spans/Calculate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ getSpanInfo mods tcm =
where cmp (_,a,_) (_,b,_)
| a `isSubspanOf` b = LT
| b `isSubspanOf` a = GT
| otherwise = EQ
| otherwise = compare (srcSpanStart a) (srcSpanStart b)

getExports :: TypecheckedModule -> [(SpanSource, SrcSpan, Maybe Type)]
getExports m
Expand Down
4 changes: 2 additions & 2 deletions test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,9 @@ findDefinitionAndHoverTests = let
, test yes broken clL23 cls "class in instance declaration"
, test yes broken clL25 cls "class in signature" -- 147
, test broken broken eclL15 ecls "external class in signature"
, test yes broken dnbL29 dnb "do-notation bind" -- 137
, test yes yes dnbL29 dnb "do-notation bind" -- 137
, test yes yes dnbL30 dnb "do-notation lookup"
, test yes broken lcbL33 lcb "listcomp bind" -- 137
, test yes yes lcbL33 lcb "listcomp bind" -- 137
, test yes yes lclL33 lcb "listcomp lookup"
]
where yes, broken :: (TestTree -> Maybe TestTree)
Expand Down

0 comments on commit 87f449d

Please sign in to comment.