Skip to content

Illegal syntax in an active pattern produces an internal compiler error #5745

Closed

Description

@misterspeedy

Description: A specific kind of incorrect syntax in an active pattern definition causes an internal compiler error rather than a message specific to the error.

Repro Steps: Add the following code:

open System.Text.RegularExpressions

let (|USZipPlus4Code|_|) s =
    let m = Regex.Match(s, @"^(\d{5})\-(\d{4})$")
    if m.Success then
        USZipPlus4Code(x=m.Groups.[1].Value, 
                       y=m.Groups.[2].Value)
        |> Some
    else
        None

Expected: An error along the lines of:

'Active pattern bindings do not support field names.'

Actual:

'error FS0073: internal error: impossible (Failure)'

Severity: minor.

Version: F# 4.5

Workaround: Use correct active pattern syntax. In this case, omit the x= and y=.

Activity

  1. added this to the 16.0 milestone on Oct 8, 2018
  2. cartermp commented on Oct 8, 2018

    @cartermp
    Contributor

    From F# 4.0:

    exit status 1
    
    /home/runner/main.fs(6,9): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(6,9): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(5,5): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(4,5): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(4,5): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(3,1): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(1,1): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    /home/runner/main.fs(1,1): error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    error FS0193: internal error: The index was outside the range of elements in the list.
    Parameter name: index
    
    error FS0073: internal error: The index was outside the range of elements in the list.
    Parameter name: index (ArgumentException)
    
    error FS0193: internal error: The index was outside the range of elements in the list.
    Parameter name: index
    
    Unhandled Exception:
    System.ArgumentException: The index was outside the range of elements in the list.
    Parameter name: index
      at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) <0x40ad6fe0 + 0x00173> in <filename unknown>:0 
      at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger x, System.Exception exn, range m) <0x40ac22e0 + 0x002e7> in <filename unknown>:0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: The index was outside the range of elements in the list.
    Parameter name: index
      at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ReraiseIfWatsonable (System.Exception exn) <0x40ad6fe0 + 0x00173> in <filename unknown>:0 
      at Microsoft.FSharp.Compiler.ErrorLogger+ErrorLoggerExtensions.ErrorLogger.ErrorRecovery (Microsoft.FSharp.Compiler.ErrorLogger x, System.Exception exn, range m) <0x40ac22e0 + 0x002e7> in <filename unknown>:0 
    

    So the error message is different, but it's still an internal error.

  3. forki commented on Oct 9, 2018

    @forki
    Contributor

    image

    would this make more sense? it says UnionCase USZipPlus4Code doesn't have field y.

  4. forki commented on Oct 9, 2018

    @forki
    Contributor

    I assume we should replace the "UnionCase" with "ActivePattern". But would this be helpful?

  5. added a commit that references this issue on Oct 15, 2018
    39fd7b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions