Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
misterspeedy opened this issue Oct 8, 2018 · 3 comments · Fixed by #5746
Closed

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

misterspeedy opened this issue Oct 8, 2018 · 3 comments · Fixed by #5746
Labels
Milestone

Comments

@misterspeedy
Copy link

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=.

@cartermp cartermp added this to the 16.0 milestone Oct 8, 2018
@cartermp
Copy link
Contributor

cartermp commented Oct 8, 2018

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.

@forki
Copy link
Contributor

forki commented Oct 9, 2018

image

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

@forki
Copy link
Contributor

forki commented Oct 9, 2018

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

forki added a commit to forki/visualfsharp that referenced this issue Oct 9, 2018
forki added a commit to forki/visualfsharp that referenced this issue Oct 9, 2018
forki added a commit to forki/visualfsharp that referenced this issue Oct 9, 2018
forki added a commit to forki/visualfsharp that referenced this issue Oct 9, 2018
forki added a commit to forki/visualfsharp that referenced this issue Oct 9, 2018
forki added a commit to forki/visualfsharp that referenced this issue Oct 10, 2018
forki added a commit to forki/visualfsharp that referenced this issue Oct 10, 2018
KevinRansom pushed a commit that referenced this issue Oct 15, 2018
* Remove one "impossible" error - fixes #5745

* Fix tests

* Add test for #5745

* Fix "build from source"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants