on master help sign in
Finish TODO on infinite type errors
15b9171Evan Czaplicki
src/Reporting/Error/Type.hs+28−3
@@ -40,7 +40,7 @@ import qualified Type.Error as T
40data Error
40data Error
41 = BadExpr R.Region Category T.Type (Expected T.Type)
41 = BadExpr R.Region Category T.Type (Expected T.Type)
42 | BadPattern R.Region PCategory T.Type (PExpected T.Type)
42 | BadPattern R.Region PCategory T.Type (PExpected T.Type)
43− | InfiniteType T.Type
43+ | InfiniteType R.Region N.Name T.Type
44
44
45
45
46
46
@@ -170,8 +170,8 @@ toReport source localizer err =
170 BadPattern region category tipe expected ->
170 BadPattern region category tipe expected ->
171 toPatternReport source localizer region category tipe expected
171 toPatternReport source localizer region category tipe expected
172
172
173− InfiniteType overallType ->
173+ InfiniteType region name overallType ->
174− error "TODO" source localizer overallType
174+ toInfiniteReport source localizer region name overallType
175
175
176
176
177
177
@@ -1250,3 +1250,28 @@ badEquality localizer op tipe expectedType =
1250 ]
1250 ]
1251 )
1251 )
1252 )
1252 )
1253+
1254+
1255+
1256+-- INFINITE TYPES
1257+
1258+
1259+toInfiniteReport :: Code.Source -> T.Localizer -> R.Region -> N.Name -> T.Type -> Report.Report
1260+toInfiniteReport source localizer region name overallType =
1261+ Report.Report "INFINITE TYPE" region [] $
1262+ Report.toCodeSnippet source region Nothing
1263+ (
1264+ H.reflow $
1265+ "I am inferring a weird self-referential type for " <> N.toString name <> ":"
1266+ ,
1267+ H.stack
1268+ [ H.reflow $
1269+ "Here is my best effort at writing down the type. You will see ∞ for\
1270+ \ parts of the type that repeat something already printed out infinitely."
1271+ , indentType localizer overallType
1272+ , H.reflowLink
1273+ "Staring at the type is usually not so helpful, so I recommend reading the hints at"
1274+ "infinite-type"
1275+ "to get unstuck."
1276+ ]
1277+ )
src/Type/Solve.hs+2−2
@@ -260,14 +260,14 @@ addError (State savedEnv rank errors) err =
260
260
261
261
262occurs :: State -> (N.Name, A.Located Variable) -> IO State
262occurs :: State -> (N.Name, A.Located Variable) -> IO State
263−occurs state (_name, A.At _region variable) =
263+occurs state (name, A.At region variable) =
264 do hasOccurred <- Occurs.occurs variable
264 do hasOccurred <- Occurs.occurs variable
265 if hasOccurred
265 if hasOccurred
266 then
266 then
267 do errorType <- Type.toErrorType variable
267 do errorType <- Type.toErrorType variable
268 (Descriptor _ rank mark copy) <- UF.get variable
268 (Descriptor _ rank mark copy) <- UF.get variable
269 UF.set variable (Descriptor Error rank mark copy)
269 UF.set variable (Descriptor Error rank mark copy)
270− return $ state { _errors = Error.InfiniteType errorType : _errors state }
270+ return $ state { _errors = Error.InfiniteType region name errorType : _errors state }
271 else
271 else
272 return state
272 return state
273
273