@@ -142,14 +142,13 @@ p_match' placer pretty style isInfix m_pats m_grhss = do
142142 return inci'
143143
144144 let
145− -- Calculate a 'SrcSpan' that captures the end of the name\/pattern part
146− -- of the match. This is used to tell if we need to have the body on a
147− -- newline.
148− endOfPatsSpan = srcLocSpan . srcSpanEnd <$> case NE.nonEmpty m_pats of
145+ -- Calculate position of end of patterns. This is useful when we decide
146+ -- about putting certain constructions in hanging positions.
147+ endOfPats = case NE.nonEmpty m_pats of
149148 Nothing -> case style of
150− Function name -> Just $ getLoc name
149+ Function name -> (Just . srcSpanEnd . getLoc) name
151150 _ -> Nothing
152− Just pats -> Just . getLoc $ NE.last pats
151+ Just pats -> (Just . srcSpanEnd . getLoc . NE.last) pats
153152 isCase = \case
154153 Case -> True
155154 LambdaCase -> True
@@ -166,8 +165,16 @@ p_match' placer pretty style isInfix m_pats m_grhss = do
166165 _ -> txt " ->"
167166 let grhssSpan = combineSrcSpans' $
168167 getGRHSSpan . unLoc <$> NE.fromList grhssGRHSs
169− patGrhssSpan = maybe grhssSpan (combineSrcSpans grhssSpan) endOfPatsSpan
170− placement = blockPlacement placer grhssGRHSs
168+ patGrhssSpan = maybe grhssSpan
169+ (combineSrcSpans grhssSpan . srcLocSpan) endOfPats
170+ placement =
171+ case endOfPats of
172+ Nothing -> blockPlacement placer grhssGRHSs
173+ Just spn ->
174+ if isOneLineSpan
175+ (mkSrcSpan spn (srcSpanStart grhssSpan))
176+ then blockPlacement placer grhssGRHSs
177+ else Normal
171178 inciLocalBinds = case placement of
172179 Normal -> id
173180 Hanging -> inci