@@ -801,6 +801,10 @@ data Node
801 | NParens
801 | NParens
806getDefName :: Context -> Name.Name
810getDefName :: Context -> Name.Name
@@ -810,6 +814,13 @@ getDefName context =
810 InNode _ _ _ c -> getDefName c
814 InNode _ _ _ c -> getDefName c
817+isWithin :: Node -> Context -> Bool
818+isWithin desiredNode context =
820+ InDef _ _ _ -> False
821+ InNode actualNode _ _ _ -> desiredNode == actualNode
814-- EXPR REPORTS
825-- EXPR REPORTS
@@ -823,8 +834,8 @@ toExprReport source context expr startRow startCol =
823 Case _ _ _ ->
834 Case _ _ _ ->
824 error "TODO Case"
835 error "TODO Case"
826− If _ _ _ ->
837+ If if_ row col ->
827− error "TODO If"
838+ toIfReport source context if_ row col
829 List list row col ->
840 List list row col ->
830 toListReport source context list row col
841 toListReport source context list row col
@@ -906,6 +917,10 @@ toExprReport source context expr startRow startCol =
906 InNode NParens r c _ -> (r, c, "some parentheses")
917 InNode NParens r c _ -> (r, c, "some parentheses")
907 InNode NList r c _ -> (r, c, "a list")
918 InNode NList r c _ -> (r, c, "a list")
908 InNode NFunc r c _ -> (r, c, "an anonymous function")
919 InNode NFunc r c _ -> (r, c, "an anonymous function")
920+ InNode NCond r c _ -> (r, c, "an `if` expression")
921+ InNode NThen r c _ -> (r, c, "an `if` expression")
922+ InNode NElse r c _ -> (r, c, "an `if` expression")
923+ -- TODO check if this is actually the best way to get error messages here
910 surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
925 surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
911 region = toRegion row col
926 region = toRegion row col
@@ -1347,7 +1362,7 @@ toOperatorReport source context operator row col =
1347 D.reflow "Maybe you want == instead? To check if two values are equal?"
1362 D.reflow "Maybe you want == instead? To check if two values are equal?"
1349 D.toSimpleNote $
1364 D.toSimpleNote $
1350− if error "TODO is within record?" then
1365+ if isWithin NRecord context then
1351 "Records look like { x = 3, y = 4 } with the equals sign right\
1366 "Records look like { x = 3, y = 4 } with the equals sign right\
1352 \ after the field name. So maybe you forgot a comma?"
1367 \ after the field name. So maybe you forgot a comma?"
@@ -1391,6 +1406,173 @@ toOperatorReport source context operator row col =
1412+toIfReport :: Code.Source -> Context -> If -> Row -> Col -> Report.Report
1413+toIfReport source context if_ startRow startCol =
1415+ IfSpace space row col ->
1416+ toSpaceReport source space row col
1420+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1421+ region = toRegion row col
1423+ Report.Report "UNFINISHED IF" region [] $
1424+ Report.toCodeSnippet source surroundings (Just region)
1427+ "I was expecting to see more of this `if` expression, but I got stuck here:"
1430+ ["I","was","expecting","to","see","the",D.green "then","keyword","next."
1436+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1437+ region = toRegion row col
1439+ Report.Report "UNFINISHED IF" region [] $
1440+ Report.toCodeSnippet source surroundings (Just region)
1443+ "I was expecting to see more of this `if` expression, but I got stuck here:"
1446+ ["I","was","expecting","to","see","the",D.green "else","keyword","next."
1450+ IfElseBranchStart row col ->
1452+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1453+ region = toRegion row col
1455+ Report.Report "UNFINISHED IF" region [] $
1456+ Report.toCodeSnippet source surroundings (Just region)
1459+ "I just saw the start of an `else` branch, but then I got stuck here:"
1462+ "I was expecting to see an expression next. Maybe it is not filled in yet?"
1465+ IfCondition expr row col ->
1466+ toExprReport source (InNode NCond startRow startCol context) expr row col
1468+ IfThenBranch expr row col ->
1469+ toExprReport source (InNode NThen startRow startCol context) expr row col
1471+ IfElseBranch expr row col ->
1472+ toExprReport source (InNode NElse startRow startCol context) expr row col
1474+ IfIndentCondition row col ->
1476+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1477+ region = toRegion row col
1479+ Report.Report "UNFINISHED IF" region [] $
1480+ Report.toCodeSnippet source surroundings (Just region)
1483+ "I was expecting to see more of this `if` expression, but I got stuck here:"
1487+ ["I","was","expecting","to","see","an","expression","like",D.dullyellow "x < 0"
1488+ ,"that","evaluates","to","True","or","False."
1491+ "I can be confused by indentation. Maybe something is not indented enough?"
1495+ IfIndentThen row col ->
1497+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1498+ region = toRegion row col
1500+ Report.Report "UNFINISHED IF" region [] $
1501+ Report.toCodeSnippet source surroundings (Just region)
1504+ "I was expecting to see more of this `if` expression, but I got stuck here:"
1508+ ["I","was","expecting","to","see","the",D.green "then","keyword","next."
1511+ "I can be confused by indentation. Maybe something is not indented enough?"
1515+ IfIndentThenBranch row col ->
1517+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1518+ region = toRegion row col
1520+ Report.Report "UNFINISHED IF" region [] $
1521+ Report.toCodeSnippet source surroundings (Just region)
1524+ "I got stuck after the start of this `then` branch:"
1528+ "I was expecting to see an expression next. Maybe it is not filled in yet?"
1530+ "I can be confused by indentation, so if the `then` branch is already\
1531+ \ present, it may not be indented enough for me to recognize it."
1535+ IfIndentElseBranch row col ->
1537+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1538+ region = toRegion row col
1540+ Report.Report "UNFINISHED IF" region [] $
1541+ Report.toCodeSnippet source surroundings (Just region)
1544+ "I got stuck after the start of this `else` branch:"
1548+ "I was expecting to see an expression next. Maybe it is not filled in yet?"
1550+ "I can be confused by indentation, so if the `else` branch is already\
1551+ \ present, it may not be indented enough for me to recognize it."
1555+ IfIndentElse row col ->
1557+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1558+ region = toRegion row col
1560+ Report.Report "UNFINISHED IF" region [] $
1561+ Report.toCodeSnippet source surroundings (Just region)
1564+ "I was expecting to see an `else` branch after this:"
1568+ "I know what to do when the condition is `True`, but not when it is `False`."
1570+ ["Add","an",D.green "else","branch","to","handle","that","scenario!"]
1394-- RECORD
1576-- RECORD
@@ -1469,7 +1651,7 @@ toRecordReport source context record startRow startCol =
1469 addNoteForRecordError $
1651 addNoteForRecordError $
1470 D.fillSep $
1652 D.fillSep $
1471 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
1653 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
1472− ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign?"
1654+ ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"