Skip to content

Commit 87f449d

Browse files
jacgcocreature
authored andcommitted
Fix #237 (#243)
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).
1 parent 069e8ee commit 87f449d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Development/IDE/Spans/Calculate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ getSpanInfo mods tcm =
7474
where cmp (_,a,_) (_,b,_)
7575
| a `isSubspanOf` b = LT
7676
| b `isSubspanOf` a = GT
77-
| otherwise = EQ
77+
| otherwise = compare (srcSpanStart a) (srcSpanStart b)
7878

7979
getExports :: TypecheckedModule -> [(SpanSource, SrcSpan, Maybe Type)]
8080
getExports m

test/exe/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,9 @@ findDefinitionAndHoverTests = let
810810
, test yes broken clL23 cls "class in instance declaration"
811811
, test yes broken clL25 cls "class in signature" -- 147
812812
, test broken broken eclL15 ecls "external class in signature"
813-
, test yes broken dnbL29 dnb "do-notation bind" -- 137
813+
, test yes yes dnbL29 dnb "do-notation bind" -- 137
814814
, test yes yes dnbL30 dnb "do-notation lookup"
815-
, test yes broken lcbL33 lcb "listcomp bind" -- 137
815+
, test yes yes lcbL33 lcb "listcomp bind" -- 137
816816
, test yes yes lclL33 lcb "listcomp lookup"
817817
]
818818
where yes, broken :: (TestTree -> Maybe TestTree)

0 commit comments

Comments
 (0)