@@ -138,12 +138,13 @@ diagnosticToChangeSig recorder decls diagnostic = runMaybeT $ do
138
138
(expectedType, actualType, errInfo) <- hoistMaybe $ do
139
139
msg <- diagnostic ^. fdStructuredMessageL ^? _SomeStructuredMessage
140
140
tcRnMsg <- msg ^. msgEnvelopeErrorL ^? _TcRnMessage
141
- (solverReport, errInfo) <- findSolverReport tcRnMsg
142
- mismatch <- findMismatchMessage solverReport
143
- (expectedType', actualType') <- findTypeEqMismatch mismatch
144
- errInfo' <- errInfo
141
+ TcRnMessageDetailed errInfo tcRnMsg' <- tcRnMsg ^? _TcRnMessageDetailed
142
+ solverReport <- tcRnMsg' ^? _TcRnSolverReport . tcSolverReportMsgL
143
+ mismatch <- solverReport ^? _MismatchMessage
144
+ expectedType <- mismatch ^? _TypeEqMismatchExpected
145
+ actualType <- mismatch ^? _TypeEqMismatchActual
145
146
146
- pure (showType expectedType' , showType actualType' , errInfo' )
147
+ pure (showType expectedType, showType actualType, errInfo)
147
148
148
149
logWith recorder Debug (LogErrInfoCtxt errInfo)
149
150
@@ -163,35 +164,48 @@ diagnosticToChangeSig recorder decls diagnostic = runMaybeT $ do
163
164
showType :: Type -> Text
164
165
showType = T. pack . showSDocUnsafe . pprTidiedType
165
166
166
- -- TODO: Make this a prism?
167
- findSolverReport :: TcRnMessage -> Maybe ( TcSolverReportMsg , Maybe ErrInfo )
168
- findSolverReport ( TcRnMessageWithInfo _ ( TcRnMessageDetailed errInfo msg)) =
169
- case findSolverReport msg of
170
- Just (mismatch, _) -> Just (mismatch, Just errInfo)
171
- _ -> Nothing
167
+ _TcRnMessageDetailed :: Traversal' TcRnMessage TcRnMessageDetailed
168
+ _TcRnMessageDetailed focus ( TcRnMessageWithInfo errInfo detailed) =
169
+ ( \ detailed' -> TcRnMessageWithInfo errInfo detailed') <$> focus detailed
170
+ _TcRnMessageDetailed _ msg = pure msg
171
+
172
+ _TcRnSolverReport :: Traversal' TcRnMessage SolverReportWithCtxt
172
173
#if MIN_VERSION_ghc(9,10,0)
173
- findSolverReport (TcRnSolverReport ( SolverReportWithCtxt _ mismatch) _ ) =
174
- Just (mismatch, Nothing )
174
+ _TcRnSolverReport focus (TcRnSolverReport report reason ) =
175
+ ( \ report' -> TcRnSolverReport report' reason) <$> focus report
175
176
#else
176
- findSolverReport (TcRnSolverReport ( SolverReportWithCtxt _ mismatch) _ _ ) =
177
- Just (mismatch, Nothing )
177
+ _TcRnSolverReport focus (TcRnSolverReport report reason hints ) =
178
+ ( \ report' -> TcRnSolverReport report' reason hints) <$> focus report
178
179
#endif
179
- findSolverReport _ = Nothing
180
+ _TcRnSolverReport _ msg = pure msg
181
+
182
+ tcSolverReportMsgL :: Lens' SolverReportWithCtxt TcSolverReportMsg
183
+ tcSolverReportMsgL = lens reportContent (\ report content' -> report { reportContent = content' })
184
+
185
+ _MismatchMessage :: Traversal' TcSolverReportMsg MismatchMsg
186
+ _MismatchMessage focus (Mismatch msg t a c) = (\ msg' -> Mismatch msg' t a c) <$> focus msg
187
+ _MismatchMessage focus (CannotUnifyVariable msg a) = flip CannotUnifyVariable a <$> focus msg
188
+ _MismatchMessage _ report = pure report
180
189
181
- -- TODO: Make this a prism?
182
- findMismatchMessage :: TcSolverReportMsg -> Maybe MismatchMsg
183
- findMismatchMessage (Mismatch m _ _ _) = Just m
184
- findMismatchMessage (CannotUnifyVariable m _) = Just m
185
- findMismatchMessage _ = Nothing
190
+ _TypeEqMismatchExpected :: Traversal' MismatchMsg Type
191
+ #if MIN_VERSION_ghc(9,12,0)
192
+ _TypeEqMismatchExpected focus mismatch@ (TypeEqMismatch _ _ _ expected _ _ _) =
193
+ (\ expected' -> mismatch { teq_mismatch_expected = expected' }) <$> focus expected
194
+ #else
195
+ _TypeEqMismatchExpected focus mismatch@ (TypeEqMismatch _ _ _ expected _ _ _ _) =
196
+ (\ expected' -> mismatch { teq_mismatch_expected = expected' }) <$> focus expected
197
+ #endif
198
+ _TypeEqMismatchExpected _ mismatch = pure mismatch
186
199
187
- -- TODO: Make this a prism?
188
- findTypeEqMismatch :: MismatchMsg -> Maybe (Type , Type )
200
+ _TypeEqMismatchActual :: Traversal' MismatchMsg Type
189
201
#if MIN_VERSION_ghc(9,12,0)
190
- findTypeEqMismatch (TypeEqMismatch _ _ _ expected actual _ _) = Just (expected, actual)
202
+ _TypeEqMismatchActual focus mismatch@ (TypeEqMismatch _ _ _ _ actual _ _) =
203
+ (\ actual' -> mismatch { teq_mismatch_actual = actual' }) <$> focus actual
191
204
#else
192
- findTypeEqMismatch (TypeEqMismatch _ _ _ _ expected actual _ _) = Just (expected, actual)
205
+ _TypeEqMismatchActual focus mismatch@ (TypeEqMismatch _ _ _ _ actual _ _ _) =
206
+ (\ actual' -> mismatch { teq_mismatch_expected = actual' }) <$> focus actual
193
207
#endif
194
- findTypeEqMismatch _ = Nothing
208
+ _TypeEqMismatchActual _ mismatch = pure mismatch
195
209
196
210
-- | If a diagnostic has the proper message create a ChangeSignature from it
197
211
matchingDiagnostic :: ErrInfo -> Maybe DeclName
@@ -207,8 +221,7 @@ matchingDiagnostic ErrInfo{errInfoContext} =
207
221
-- | List of regexes that match various Error Messages
208
222
errorMessageRegexes :: [Text ]
209
223
errorMessageRegexes = [ -- be sure to add new Error Messages Regexes at the bottom to not fail any existing tests
210
- " In an equation for ‘(.+)’:" -- TODO: Check if this is useful only for tests
211
- , " In an equation for `(.+)':"
224
+ " In an equation for ‘(.+)’:"
212
225
]
213
226
214
227
-- | Given a String with the name of a declaration, GHC's "Expected Type", find the declaration that matches
0 commit comments