dotnet / dotnet/fsharp

error recovery in complex array expression is confusing

Open
#19,671 2 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Syntax
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

```fsharp

type RoundtripError =
| SheetCountMismatch of expected: int * actual: int
| MissingSheet of sheetName: string
| RowCountMismatch of sheetName: string * expected: int * actual: int
| ColumnCountMismatch of sheetName: string * rowIndex: int * expected: int * actual: int
| ValueMismatch of sheetName: string * rowIndex: int * colIndex: int * expected: string * actual: string

let validateRoundtrip originalCsvData (readData: IDictionary<_,string list list>) =
let originalData = Dictionary<_, _>()
[|
for KeyValue(sheetName, sheetValue) in originalCsvData do
if originalData.Count <> readData.Count then
SheetCountMismatch(originalData.Count, readData.Count)

for KeyValue(sheetName, sheetValue) in originalData do
if readData.ContainsKey sheetName then
let originalRow= [||]
let originalSheetData = [||]
let readSheetData = readData[sheetName]
RowCountMismatch(sheetName, originalSheetData.Length, readSheetData.Length)
for rowIndex in 0 .. min originalSheetData.Length readSheetData.Length - 1 do
let originalRow = [||]
let readRow = readSheetData[rowIndex]

if originalRow.Length <> readRow.Length then
ColumnCountMismatch(sheetName, rowIndex, originalRow.Length, readRow.Length)
//for colIndex in 0 .. 1 do
// if originalRow[colIndex] <> readRow[colIndex] then
// ValueMismatch(sheetName, rowIndex, colIndex,originalRow[colIndex], readRow[colIndex])) // extra closing paren here
else
MissingSheet(sheetName)
|]
```

if you uncomment the last part of this array expression, it is not able to compile with a swath of errors:

> This 'if' expression is missing an 'else' branch. Because 'if' is an expression, and not a statement, add an 'else' branch which also returns a value of type 'RoundtripError'.

> Unexpected end of input in 'for' expression. Expected 'for in do '.

> This 'if' expression is missing an 'else' branch. Because 'if' is an expression, and not a statement, add an 'else' branch which also returns a value of type 'RoundtripError'.

> Unexpected symbol ')' in expression. Expected incomplete structured construct at or before this point or other token.

> Incomplete structured construct at or before this point in expression. Expected incomplete structured construct at or before this point or other token.

> Unexpected keyword 'else' in expression

upon close inspection, it is all tied to the mismatched closing paren in `ValueMismatch` constructor, but it was difficult to identify on first glance while working out which code to isolate.

Just reporting it in case we think there is an appropriate solution to improve error reporting for similar cases, but this is mostly user issue for me not looking at all reported errors to spot this particular one.

Maybe the array expression / CE related type errors should get lower priority in the reporting, if the construct itself has some other syntactical error which are a bigger deal for type checking to complete?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.