on master help sign in
Add some of the error messages for anonymous functions
commitf20c66281e67d673874e08ff40c263d295e2a0e0 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 6 May 2019, 18:10 (7 years ago) parent5ce58a1
1 file changed+101−2
compiler/src/Reporting/Error/Syntax.hs+101−2
compiler/src/Reporting/Error/Syntax.hs+101−2
@@ -813,8 +813,8 @@ toExprReport source name expr _ _ =
813813 Tuple _ _ _ ->
814814 error "TODO Tuple"
815815
816− Func _ _ _ ->
817− error "TODO Func"
816+ Func func row col ->
817+ toFuncReport source name func row col
818818
819819 Dot row col ->
820820 let region = toRegion row col in
@@ -1327,6 +1327,105 @@ toOperatorReport source name operator row col =
13271327 )
13281328
13291329
1330+toFuncReport :: Code.Source -> Name.Name -> Func -> Row -> Col -> Report.Report
1331+toFuncReport source name func frow fcol =
1332+ case func of
1333+ FuncSpace space row col ->
1334+ toSpaceReport source space row col
1335+
1336+ FuncArg pattern row col ->
1337+ error "TODO FuncArg" pattern row col
1338+
1339+ FuncBody expr row col ->
1340+ toExprReport source name expr row col
1341+
1342+ FuncArrow row col ->
1343+ let
1344+ surroundings = A.Region (A.Position frow fcol) (A.Position row col)
1345+ region = toRegion row col
1346+ in
1347+ Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
1348+ Report.toCodeSnippet source surroundings (Just region)
1349+ (
1350+ D.reflow $
1351+ "I was expecting to see an arrow here:"
1352+ ,
1353+ D.reflow $
1354+ "The syntax for anonymous functions is (\\x -> x + 1) so I am missing the arrow\
1355+ \ and the body of the function."
1356+ )
1357+
1358+ FuncIndentArg row col ->
1359+ let
1360+ surroundings = A.Region (A.Position frow fcol) (A.Position row col)
1361+ region = toRegion row col
1362+ in
1363+ Report.Report "MISSING ARGUMENT" region [] $
1364+ Report.toCodeSnippet source surroundings (Just region)
1365+ (
1366+ D.reflow $
1367+ "I just saw the start of an anonymous function, so I was expecting to see an argument here:"
1368+ ,
1369+ D.stack
1370+ [ D.fillSep
1371+ ["Something","like",D.dullyellow"x","or",D.dullyellow "name" <> "."
1372+ ,"Anything","that","starts","with","a","lower","case","letter!"
1373+ ]
1374+ , D.toSimpleNote $
1375+ "The syntax for anonymous functions is (\\x -> x + 1) where the backslash\
1376+ \ is meant to look a bit like a lambda if you squint. This visual pun seemed\
1377+ \ like a better idea at the time!"
1378+ ]
1379+ )
1380+
1381+ FuncIndentArrow row col ->
1382+ let
1383+ surroundings = A.Region (A.Position frow fcol) (A.Position row col)
1384+ region = toRegion row col
1385+ in
1386+ Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
1387+ Report.toCodeSnippet source surroundings (Just region)
1388+ (
1389+ D.reflow $
1390+ "I was expecting to see an arrow here:"
1391+ ,
1392+ D.stack
1393+ [ D.reflow $
1394+ "The syntax for anonymous functions is (\\x -> x + 1) so I am missing the arrow\
1395+ \ and the body of the function."
1396+ , D.toSimpleNote $
1397+ "It is possible that I am confused about indetation! I generally recommend\
1398+ \ switching to named functions if the definition cannot fit inline nicely, so\
1399+ \ either (1) try to fit the whole anonymous function on one line or (2) break\
1400+ \ the whole thing out into a named function. Things tend to be clearer that way!"
1401+ ]
1402+ )
1403+
1404+ FuncIndentBody row col ->
1405+ let
1406+ surroundings = A.Region (A.Position frow fcol) (A.Position row col)
1407+ region = toRegion row col
1408+ in
1409+ Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
1410+ Report.toCodeSnippet source surroundings (Just region)
1411+ (
1412+ D.reflow $
1413+ "I was expecting to see the body of your anonymous function here:"
1414+ ,
1415+ D.stack
1416+ [ D.reflow $
1417+ "The syntax for anonymous functions is (\\x -> x + 1) so I am missing all the stuff after the arrow!"
1418+ , D.toSimpleNote $
1419+ "It is possible that I am confused about indetation! I generally recommend\
1420+ \ switching to named functions if the definition cannot fit inline nicely, so\
1421+ \ either (1) try to fit the whole anonymous function on one line or (2) break\
1422+ \ the whole thing out into a named function. Things tend to be clearer that way!"
1423+ ]
1424+ )
1425+
1426+
1427+
1428+
13301429{-
13311430 case err of
13321431 CommentOnNothing region ->