-
Notifications
You must be signed in to change notification settings - Fork 844
Closed
Labels
Milestone
Description
I was in the process of writing a piece of code when at a certain state it started crashing the F# compiler. The code is not syntactically complete or well-typed F# code, but it shouldn't cause:
error FS0193 : internal error : The lists had different lengths.list2 is 1 element shorter than list1Parameter name: list2 [/Users/jwostenberg/Code/BF.Net/BF.Net/BF.Net.fsproj]
error FS0073 : internal error : The lists had different lengths.list2 is 1 element shorter than list1Parameter name: list2 (ArgumentException) [/Users/jwostenberg/Code/BF.Net/BF.Net/BF.Net.fsproj]
error FS0193 : internal error : The lists had different lengths.list2 is 1 element shorter than list1Parameter name: list2 [/Users/jwostenberg/Code/BF.Net/BF.Net/BF.Net.fsproj]
parser.fs:
module BF.Net
open System
open FSharp.Core.Printf
let Errorf format = ksprintf (fun x -> (Error x)) format
type SimpleInstruction = | Right | Left | Inc | Dec | Read | Print
type Instruction = SimpleInstruction of SimpleInstruction | Loop of Body
and Body = Body of Instruction list
let validChars = ['>'; '<'; '+'; '-'; '.'; ','; '['; ']']
let lex input = input |> Seq.filter (fun chr -> List.contains chr validChars) |> Seq.toList
let parseSimpleInstruction input =
match input with
| '>'::rest -> Ok (Right, rest)
| '<'::rest -> Ok (Left, rest)
| '+'::rest -> Ok (Inc, rest)
| '-'::rest -> Ok (Dec, rest)
| '.'::rest -> Ok (Print, rest)
| ','::rest -> Ok (Read, rest)
| symbol::_ -> Errorf "Unexpected token '%c'; expecting symbol." symbol
| [] -> Errorf "Unexpected end of input; expecting symbol."
let rec parseLoop input =
match input with
| [] -> Body []
| '['::rest ->
match parseBody rest with
| Error _ as err -> err
| Ok (contents, rest) ->
match input with
| ']'::rest -> ()
and parseBody input = Body(at the moment of error I had been working on the parseLoop and parseBody functions)
Additionally the IDE (VSfM) is highlighting the entire file in red.
The complete solution/project is here: BF.Net.zip
Expected behavior
Expected: type/parsing errors, but no internal errors.
Actual behavior
Error present.
Known workarounds
Finish the code I'm writing and ignore the errors.
Related information
MacOS
F# compiler 4.1
FSharp.Core 4.3.3
Mono
Visual Studio for Mac