Fsharp: Internal "The lists had different lengths" exception

Created on 7 Aug 2018  Â·  23Comments  Â·  Source: dotnet/fsharp

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

Area-Compiler regression

Most helpful comment

We investigated and know why this is happening. In both cases:

type Test = Test of Unit
let test : Test = Test

and

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

The types are actually mismatched as @jwosty has mentioned. In the first case, Test is the declared type, but what's being written is a partially applied Test constructor. In the second case, parseLoop infers the type to be Body of instruction list, but parseBody is declared to be a partially applied DU constructor.

However, the code never makes it far enough into the compiler to make this apparent, so it just blows up with the internal assertion (and makes the whole editor red squiggles).

@TIHan is working out a proper fix to this so that we can surface the type mismatch error.

We're not yet sure, but this may go back as far as F# 4.0.

All 23 comments

I've managed to get a really small reproducible example:

let rec f1 input =
    match f2 rest with
    | 42 -> ()
and f2 input = Ok

Some variations, some of which exhibit the bug and others of which don't:

// BUG PRESENT
// can be any curried DU constructor
type T = T of int
let rec f1 input =
    match f2 rest with
    | 42 -> ()
and f2 input = T
// BUG NOT PRESENT
// so it has to specifically be a curried DU constructor, not just any curried function...
let ok = Ok
let rec f1 input =
    match f2 rest with
    | 42 -> ()
and f2 input = Ok
// BUG NOT PRESENT
// can't be a wildcard pattern
let rec f1 input =
    match f2 rest with
    | _ -> ()
and f2 input = Ok
// BUG NOT PRESENT
let f2 input = Ok
let rec f1 input =
    match f2 rest with
    | 42 -> ()
// BUG PRESENT
// works when you give it an annotation indicating (f2 rest) isn't a function (but it really is)
let rec f1 input =
    match f2 rest with
    | 42 -> ()
and f2 input: 'Result<_,_> = Ok
// BUG NOT PRESENT
// disappears when you annotate f2 more accurately
let rec f1 input =
    match f2 rest with
    | 42 -> ()
and f2 input: _ -> 'Result<_,_> = Ok

I tried to repro with the first small sample but seems to work. Where is
rest coming from?

John Wostenberg notifications@github.com schrieb am Mi., 8. Aug. 2018,
23:16:

I've managed to get a really small reproducible example:

let rec f1 input =
match f2 rest with
| 42 -> ()and f2 input = Ok

Some variations, some of which exhibit the bug and others of which don't:

// BUG PRESENT// can be any curried DU constructortype T = T of intlet rec f1 input =
match f2 rest with
| 42 -> ()and f2 input = T

// BUG NOT PRESENT// so it has to specifically be a curried DU constructor, not just any curried function...let ok = Oklet rec f1 input =
match f2 rest with
| 42 -> ()and f2 input = Ok

// BUG NOT PRESENT// can't be a wildcard patternlet rec f1 input =
match f2 rest with
| _ -> ()and f2 input = Ok

// BUG NOT PRESENTlet f2 input = Oklet rec f1 input =
match f2 rest with
| 42 -> ()

// BUG PRESENT// works when you give it an annotation indicating (f2 rest) isn't a function (but it really is)let rec f1 input =
match f2 rest with
| 42 -> ()and f2 input: 'Result<_,_> = Ok

// BUG NOT PRESENT// disappears when you annotate f2 more accuratelylet rec f1 input =
match f2 rest with
| 42 -> ()and f2 input: _ -> 'Result<_,_> = Ok

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/visualfsharp/issues/5468#issuecomment-411555228,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNKv6hGal5wTicbGTeFax078hHar-ks5uO1UygaJpZM4VyVWq
.

@forki sorry what are you asking? If you've tried to repro on a newer fsharpc then perhaps it's already been fixed.

Also I've been testing these in the IDE, but my first snippet in my recent comment gives a handy stacktrace. Maybe someone can make sense of this:

Microsoft (R) F# Compiler version 4.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

/Users/jwostenberg/test.fs(2,14): error FS0039: The value or constructor 'rest' is not defined. Maybe you want one of the following:
   Res
   Result

/Users/jwostenberg/test.fs(2,11): warning FS0025: Incomplete pattern matches on this expression. For example, the value '0' may indicate a case not covered by the pattern(s).

/Users/jwostenberg/test.fs(4,16): error FS0001: This expression was expected to have type
    'int'    
but here has type
    ''a -> Result<'a,'b>'    

/Users/jwostenberg/test.fs(1,1): error FS0073: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2 (ArgumentException)

/Users/jwostenberg/test.fs(1,1): error FS0073: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2 (ArgumentException)

/Users/jwostenberg/test.fs(1,1): error FS0073: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2 (ArgumentException)

error FS0193: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2

error FS0073: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2 (ArgumentException)

error FS0193: internal error: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2

Unhandled Exception:
System.ArgumentException: The lists had different lengths.
list2 is 1 element shorter than list1
Parameter name: list2
  at Microsoft.FSharp.Core.DetailedExceptions.invalidArgDifferentListLength[?] (System.String arg1, System.String arg2, System.Int32 diff) [0x00064] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Primitives.Basics.List.zipToFreshConsTail[a,b] (Microsoft.FSharp.Collections.FSharpList`1[T] cons, Microsoft.FSharp.Collections.FSharpList`1[T] xs1, Microsoft.FSharp.Collections.FSharpList`1[T] xs2) [0x00024] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Primitives.Basics.List.zip[T1,T2] (Microsoft.FSharp.Collections.FSharpList`1[T] xs1, Microsoft.FSharp.Collections.FSharpList`1[T] xs2) [0x0005b] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Collections.ListModule.Zip[T1,T2] (Microsoft.FSharp.Collections.FSharpList`1[T] list1, Microsoft.FSharp.Collections.FSharpList`1[T] list2) [0x00000] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Compiler.Tastops.InferArityOfExpr (Microsoft.FSharp.Compiler.TcGlobals+TcGlobals g, Microsoft.FSharp.Compiler.Tastops+AllowTypeDirectedDetupling allowTypeDirectedDetupling, Microsoft.FSharp.Compiler.Tast+TType ty, Microsoft.FSharp.Collections.FSharpList`1[T] partialArgAttribsL, Microsoft.FSharp.Collections.FSharpList`1[T] retAttribs, Microsoft.FSharp.Compiler.Tast+Expr e) [0x0004c] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker.CombineSyntacticAndInferredArities (Microsoft.FSharp.Compiler.TcGlobals+TcGlobals g, Microsoft.FSharp.Compiler.TypeChecker+DeclKind declKind, Microsoft.FSharp.Compiler.Tast+Expr rhsExpr, Microsoft.FSharp.Compiler.TypeChecker+PrelimValScheme2 prelimScheme) [0x000b9] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker.TcLetrecGeneralizeBinding (Microsoft.FSharp.Compiler.TypeChecker+cenv cenv, Microsoft.FSharp.Compiler.Tastops+DisplayEnv denv, Microsoft.FSharp.Collections.FSharpList`1[T] generalizedTypars, Microsoft.FSharp.Compiler.TypeChecker+PreGeneralizationRecursiveBinding pgrbind) [0x000e6] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker+TcIncrementalLetRecGeneralization@11556.Invoke (Microsoft.FSharp.Collections.FSharpList`1[T] generalizedTypars, Microsoft.FSharp.Compiler.TypeChecker+PreGeneralizationRecursiveBinding pgrbind) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Primitives.Basics.List.map2[T1,T2,TResult] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] mapping, Microsoft.FSharp.Collections.FSharpList`1[T] xs1, Microsoft.FSharp.Collections.FSharpList`1[T] xs2) [0x00052] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Collections.ListModule.Map2[T1,T2,TResult] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] mapping, Microsoft.FSharp.Collections.FSharpList`1[T] list1, Microsoft.FSharp.Collections.FSharpList`1[T] list2) [0x00000] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker.TcIncrementalLetRecGeneralization (Microsoft.FSharp.Compiler.TypeChecker+cenv cenv, Microsoft.FSharp.Compiler.Range+range scopem, Microsoft.FSharp.Compiler.TypeChecker+TcEnv envNonRec, Microsoft.FSharp.Collections.FSharpList`1[T] generalizedRecBinds, Microsoft.FSharp.Collections.FSharpList`1[T] preGeneralizationRecBinds, Microsoft.FSharp.Compiler.TypeChecker+SyntacticUnscopedTyparEnv tpenv, Microsoft.FSharp.Collections.FSharpMap`2[TKey,TValue] uncheckedRecBindsTable) [0x000ac] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker.TcLetrecBinding (Microsoft.FSharp.Compiler.TypeChecker+cenv cenv, Microsoft.FSharp.Compiler.TypeChecker+TcEnv envRec, Microsoft.FSharp.Compiler.Range+range scopem, Microsoft.FSharp.Collections.FSharpList`1[T] extraGeneralizableTypars, Microsoft.FSharp.Core.FSharpOption`1[T] reqdThisValTyOpt, Microsoft.FSharp.Compiler.TypeChecker+TcEnv envNonRec, Microsoft.FSharp.Collections.FSharpList`1[T] generalizedRecBinds, Microsoft.FSharp.Collections.FSharpList`1[T] preGeneralizationRecBinds, Microsoft.FSharp.Compiler.TypeChecker+SyntacticUnscopedTyparEnv tpenv, Microsoft.FSharp.Collections.FSharpMap`2[TKey,TValue] uncheckedRecBindsTable, Microsoft.FSharp.Compiler.TypeChecker+PreCheckingRecursiveBinding rbind) [0x00280] in <5ab831e1f1806346a7450383e131b85a>:0 
  at [email protected] (Microsoft.FSharp.Compiler.TypeChecker+PreCheckingRecursiveBinding rbind) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Core.OptimizedClosures+Adapt@2812[T1,T2,TResult].Invoke (T1 t, T2 u) [0x0000c] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Collections.ListModule.Fold[T,TState] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] folder, TState state, Microsoft.FSharp.Collections.FSharpList`1[T] list) [0x0002a] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker.TcLetrec (Microsoft.FSharp.Compiler.TypeChecker+OverridesOK overridesOK, Microsoft.FSharp.Compiler.TypeChecker+cenv cenv, Microsoft.FSharp.Compiler.TypeChecker+TcEnv env, Microsoft.FSharp.Compiler.TypeChecker+SyntacticUnscopedTyparEnv tpenv, Microsoft.FSharp.Collections.FSharpList`1[T] binds, Microsoft.FSharp.Compiler.Range+range bindsm, Microsoft.FSharp.Compiler.Range+range scopem) [0x0008c] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker+TcModuleOrNamespaceElementNonMutRec@16584-1.Invoke (Microsoft.FSharp.Core.Unit unitVar) [0x002e7] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+delay@906-1[T].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken _ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+catch@900-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) [0x0003f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger x, System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x000d8] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker+TcModuleOrNamespaceElementNonMutRec@16583-19.Invoke (System.Exception _arg3) [0x00011] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+tryWith@917-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+ResultOrException`1[TResult] _arg1) [0x0000f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule.bind[a,b] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] k, Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+Eventually`1[T] e) [0x0002a] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00012] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+catch@900-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) [0x0003f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger x, System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x000d8] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker+TcModuleOrNamespaceElementNonMutRec@16583-19.Invoke (System.Exception _arg3) [0x00011] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+tryWith@917-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+ResultOrException`1[TResult] _arg1) [0x0000f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule.bind[a,b] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] k, Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+Eventually`1[T] e) [0x0002a] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00012] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+catch@900-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) [0x0003f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger x, System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x000d8] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.TypeChecker+TcModuleOrNamespaceElementNonMutRec@16583-19.Invoke (System.Exception _arg3) [0x00011] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+tryWith@917-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+ResultOrException`1[TResult] _arg1) [0x0000f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule.bind[a,b] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] k, Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+Eventually`1[T] e) [0x0002a] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00012] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+catch@900-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) [0x0003f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger x, System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x000d8] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.CompileOps+TypeCheckOneInputEventually@5397-13.Invoke (System.Exception _arg5) [0x0000b] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+tryWith@917-1[a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+ResultOrException`1[TResult] _arg1) [0x0000f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule.bind[a,b] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] k, Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+Eventually`1[T] e) [0x0002a] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule+bind@891-1[b,a].Invoke (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok) [0x00012] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule.forceWhile[a] (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] check, Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+Eventually`1[T] e) [0x00021] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+EventuallyModule.force[a] (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+Eventually`1[T] e) [0x00006] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.CompileOps.TypeCheckOneInput (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] checkForErrors, Microsoft.FSharp.Compiler.CompileOps+TcConfig tcConfig, Microsoft.FSharp.Compiler.CompileOps+TcImports tcImports, Microsoft.FSharp.Compiler.TcGlobals+TcGlobals tcGlobals, Microsoft.FSharp.Core.FSharpOption`1[T] prefixPathOpt, Microsoft.FSharp.Compiler.CompileOps+TcState tcState, Microsoft.FSharp.Compiler.Ast+ParsedInput inp) [0x0002f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.CompileOps+TypeCheckMultipleInputs@5528.Invoke (Microsoft.FSharp.Compiler.CompileOps+TcState tcState, Microsoft.FSharp.Compiler.Ast+ParsedInput inp) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Core.FSharpFunc`2[T,TResult].InvokeFast[V] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] func, T arg1, TResult arg2) [0x0000c] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] f, TState acc, Microsoft.FSharp.Collections.FSharpList`1[T] xs) [0x00021] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Collections.ListModule.MapFold[T,TState,TResult] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] mapping, TState state, Microsoft.FSharp.Collections.FSharpList`1[T] list) [0x00000] in <5ab83181dff9fae1a74503838131b85a>:0 
  at Microsoft.FSharp.Compiler.CompileOps.TypeCheckMultipleInputs (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] checkForErrors, Microsoft.FSharp.Compiler.CompileOps+TcConfig tcConfig, Microsoft.FSharp.Compiler.CompileOps+TcImports tcImports, Microsoft.FSharp.Compiler.TcGlobals+TcGlobals tcGlobals, Microsoft.FSharp.Core.FSharpOption`1[T] prefixPathOpt, Microsoft.FSharp.Compiler.CompileOps+TcState tcState, Microsoft.FSharp.Collections.FSharpList`1[T] inputs) [0x0000d] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.CompileOps.TypeCheckClosedInputSet (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] checkForErrors, Microsoft.FSharp.Compiler.CompileOps+TcConfig tcConfig, Microsoft.FSharp.Compiler.CompileOps+TcImports tcImports, Microsoft.FSharp.Compiler.TcGlobals+TcGlobals tcGlobals, Microsoft.FSharp.Core.FSharpOption`1[T] prefixPathOpt, Microsoft.FSharp.Compiler.CompileOps+TcState tcState, Microsoft.FSharp.Collections.FSharpList`1[T] inputs) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.Driver.TypeCheck (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Compiler.CompileOps+TcConfig tcConfig, Microsoft.FSharp.Compiler.CompileOps+TcImports tcImports, Microsoft.FSharp.Compiler.TcGlobals+TcGlobals tcGlobals, Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger errorLogger, System.String assemblyName, Microsoft.FSharp.Compiler.Ast+NiceNameGenerator niceNameGen, Microsoft.FSharp.Compiler.TypeChecker+TcEnv tcEnv0, Microsoft.FSharp.Collections.FSharpList`1[T] inputs, Microsoft.FSharp.Compiler.ErrorLogger+Exiter exiter) [0x00049] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) [0x0003f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger x, System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x000d8] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.Driver.TypeCheck (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, Microsoft.FSharp.Compiler.CompileOps+TcConfig tcConfig, Microsoft.FSharp.Compiler.CompileOps+TcImports tcImports, Microsoft.FSharp.Compiler.TcGlobals+TcGlobals tcGlobals, Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger errorLogger, System.String assemblyName, Microsoft.FSharp.Compiler.Ast+NiceNameGenerator niceNameGen, Microsoft.FSharp.Compiler.TypeChecker+TcEnv tcEnv0, Microsoft.FSharp.Collections.FSharpList`1[T] inputs, Microsoft.FSharp.Compiler.ErrorLogger+Exiter exiter) [0x00069] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.Driver.main0[a] (a ctok, System.String[] argv, Microsoft.FSharp.Compiler.ReferenceResolver+Resolver legacyReferenceResolver, System.Boolean bannerAlreadyPrinted, System.Boolean openBinariesInMemory, System.Boolean defaultCopyFSharpCore, Microsoft.FSharp.Compiler.ErrorLogger+Exiter exiter, Microsoft.FSharp.Compiler.Driver+ErrorLoggerProvider errorLoggerProvider, Microsoft.FSharp.Compiler.Driver+DisposablesTracker disposables) [0x00495] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.Driver.typecheckAndCompile (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, System.String[] argv, Microsoft.FSharp.Compiler.ReferenceResolver+Resolver legacyReferenceResolver, System.Boolean bannerAlreadyPrinted, System.Boolean openBinariesInMemory, System.Boolean defaultCopyFSharpCore, Microsoft.FSharp.Compiler.ErrorLogger+Exiter exiter, Microsoft.FSharp.Compiler.Driver+ErrorLoggerProvider loggerProvider, Microsoft.FSharp.Core.FSharpOption`1[T] tcImportsCapture, Microsoft.FSharp.Core.FSharpOption`1[T] dynamicAssemblyCreator) [0x0000c] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.Driver.mainCompile (Microsoft.FSharp.Compiler.AbstractIL.Internal.Library+CompilationThreadToken ctok, System.String[] argv, Microsoft.FSharp.Compiler.ReferenceResolver+Resolver legacyReferenceResolver, System.Boolean bannerAlreadyPrinted, System.Boolean openBinariesInMemory, System.Boolean defaultCopyFSharpCore, Microsoft.FSharp.Compiler.ErrorLogger+Exiter exiter, Microsoft.FSharp.Compiler.Driver+ErrorLoggerProvider loggerProvider, Microsoft.FSharp.Core.FSharpOption`1[T] tcImportsCapture, Microsoft.FSharp.Core.FSharpOption`1[T] dynamicAssemblyCreator) [0x00000] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.CommandLineMain+Driver.main (System.String[] argv) [0x0003d] in <5ab831ecc960099ba7450383ec31b85a>:0 
  at Microsoft.FSharp.Compiler.CommandLineMain.main (System.String[] argv) [0x00041] in <5ab831ecc960099ba7450383ec31b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) [0x0003f] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger+ErrorLogger x, System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x000d8] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.ErrorLogger.errorRecovery (System.Exception exn, Microsoft.FSharp.Compiler.Range+range m) [0x00005] in <5ab831e1f1806346a7450383e131b85a>:0 
  at Microsoft.FSharp.Compiler.CommandLineMain.main (System.String[] argv) [0x00055] in <5ab831ecc960099ba7450383ec31b85a>:0 

Can you please create a code snippet that repros in fsi? I tried to repro
with the stuff you put in last comment and didn't get that internal error

John Wostenberg notifications@github.com schrieb am Do., 9. Aug. 2018,
16:24:

@forki https://github.com/forki sorry what are you asking?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/visualfsharp/issues/5468#issuecomment-411775861,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNArSIGqLZDzepmkzuTRhhc09mkdHks5uPEYTgaJpZM4VyVWq
.

@forki ah. I can't get it to happen in fsi either. It only crashes fsc.

Ok. That's weird. I guess it's still happening, but fsi is not showing it.

John Wostenberg notifications@github.com schrieb am Do., 9. Aug. 2018,
16:31:

@forki https://github.com/forki ah. I can't get it to happen in fsi
either.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/visualfsharp/issues/5468#issuecomment-411778280,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNLaO2PonUImR7e14aLgAFwloryMpks5uPEewgaJpZM4VyVWq
.

Yes, interesting -- I can still continue the session after the bad code so maybe it's swallowing the exception somewhere. That would make sense

Ok. Can you please upload a minimal fs file that repros for you?

John Wostenberg notifications@github.com schrieb am Do., 9. Aug. 2018,
16:35:

Yes, interesting -- I can still continue the session after the bad code so
maybe it's swallowing the exception somewhere.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/visualfsharp/issues/5468#issuecomment-411779884,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNIGixac_-_JI-yhGiQGTFnK_NDnMks5uPEjIgaJpZM4VyVWq
.

Yikes... I've gotten it even smaller. Just paste this into a test.fs file and run fsharpc test.fs:

let f x : _ option = Some

If this is a real issue and not just something wrong with my environment then this is really bad...

ok I can repro.

Am Do., 9. Aug. 2018 um 16:41 Uhr schrieb John Wostenberg <
[email protected]>:

Yikes... I've gotten it even smaller. Just paste this into a .fs file and
try to compile it:

let f x : _ option = Some

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/visualfsharp/issues/5468#issuecomment-411781697,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNIwi1o1JltApL4qLqpI0cpf22VxMks5uPEoLgaJpZM4VyVWq
.

@forki well that's good and bad. Would you mind perhaps trying it on F# 4.5?

image

that assertion is not holding

@dsyme I looked at it, but I don't know how this is supposed to work. sorry

I also came across this "The lists had different lengths" error. I don't know it's the same one, but the repro is really tiny:

type Test = Test of Unit
let test : Test = Test

error

I updated to VS 15.8 today, so I can't test if this happened in F# 4.1 also...

@nikonthethird yes, this seems to be the same bug. Also, I've been testing this on Mono + F# 4.1, so it's been there and hasn't been fixed yet.

@kevinransom @dsyme I looked at this code, but it's really hard to tell why
the assertion is in place and why it's not using a safe error handler
instead. Also I'm sure the root cause is somewhere else and it's just that
it breaks the assumptions here.

John Wostenberg notifications@github.com schrieb am Mi., 15. Aug. 2018,
19:53:

@nikonthethird https://github.com/nikonthethird yes, this seems to be
the same bug. Also, I've been testing this on Mono + F# 4.1, so it's been
there and hasn't been fixed yet.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/visualfsharp/issues/5468#issuecomment-413280226,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNK4Iu-argFDBXhucRkgnKxMs2W6cks5uRGA1gaJpZM4VyVWq
.

We investigated and know why this is happening. In both cases:

type Test = Test of Unit
let test : Test = Test

and

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

The types are actually mismatched as @jwosty has mentioned. In the first case, Test is the declared type, but what's being written is a partially applied Test constructor. In the second case, parseLoop infers the type to be Body of instruction list, but parseBody is declared to be a partially applied DU constructor.

However, the code never makes it far enough into the compiler to make this apparent, so it just blows up with the internal assertion (and makes the whole editor red squiggles).

@TIHan is working out a proper fix to this so that we can surface the type mismatch error.

We're not yet sure, but this may go back as far as F# 4.0.

Actually, it looks like some change between F# 4.0 and now has caused this assertion to trigger: https://repl.it/@cartermp/GlisteningBoilingQuagga

"F# Compiler for F# 4.0 (Open Source Edition)

exit status 1

/home/runner/main.fs(2,19): error FS0001: This expression was expected to have type
    Test    
but here has type
    Unit -> Test 

No. The type error is emitted as well. Actually if you run it in fsi you only see the type error. I think this is running in some error recovering scenario.

Yep, you're right - that's what's going on. Something was fiddled with in there. Another oddity:

let doot : int = fun () -> 1

This doesn't give a type mismatch error, it gives:

This function takes too many arguments, or is used in a context where a function is not expected

Which I would argue is unexpected, since this is really a type mismatch.

Tested in FSI, I only see the type error. This is interesting.

I have a possible fix. I need to look a bit more at it before I make PR though.

I know the PR that caused this: https://github.com/Microsoft/visualfsharp/pull/1568

At this line here: https://github.com/Microsoft/visualfsharp/pull/1568/files#diff-5b9ab9dd9d7133aaf23add1048742031R8100

It's basically eating the exception when type checking fails and we continue to do what we need to do, basically to fix this: https://github.com/Microsoft/visualfsharp/issues/629

We should review this PR again to make sure this is the right thing to do. But I still have a potential fix that doesn't involve messing with those changes.

Closing as #5524 is merged.

Was this page helpful?
0 / 5 - 0 ratings