Skip to content

FS0192 Internal Error with trivial code: DecisionTreeTest.Error should only be used during pattern match compilation #9296

@abelbraaksma

Description

@abelbraaksma

The following code creates the errors FS0192, FS0073 and again FS0192 in VS IDE Preview. I found this while creating a repro for the "40 min delay during between keystrokes"-bug (see #9201). This may be a regression, as earlier versions of VS 2019 do not exhibit this behavior.

namespace FSharpBug

type TestItemSeq = 
    static member foo item = item
    static member bar item = match item with Typo2 x -> x

image

When compiling, it shows:

1>D:\Projects\FSharpBug9201\BaseForTest.fs(5,46): error FS0039: The pattern discriminator 'Typo2' is not defined.
1>D:\Projects\FSharpBug9201\BaseForTest.fs(5,36): warning FS0025: Incomplete pattern matches on this expression.
1>typecheck error FS0192: error : DecisionTreeTest.Error should only be used during pattern match compilation
1>typecheck error FS0073: error : DecisionTreeTest.Error should only be used during pattern match compilation (Failure)
1>parameter error FS0192: error : DecisionTreeTest.Error should only be used during pattern match compilation

The first error is expected, the warning is surprising, it normally doesn't show when the line has an error. The latter three errors are certainly unexpected ;).

FSC does not show this behavior, nor do earlier non-preview versions of the VS IDE.

Repro steps

  • Create a new project (I used .NET Framework 4.6.2 and 4.8, but I think other configs will show the same error)
  • Paste the code segment above in the main *.fs file.
  • Compile

Expected behavior

Only two errors should be shown.

Actual behavior

Three internal errors are also shown. Internal errors are generally unexpected and, I believe, typically mean that something is wrong with the compiler. The internal errors are:

typecheck error FS0192: error : DecisionTreeTest.Error should only be used during pattern match compilation
typecheck error FS0073: error : DecisionTreeTest.Error should only be used during pattern match compilation (Failure)
parameter error FS0192: error : DecisionTreeTest.Error should only be used during pattern match compilation

Known workarounds

If you fix the typo in your code, the internal error disappears. I noticed this behavior most prominently when doing solution-wide renames. Since the Rename Feature doesn't catch all cases, it can lead to this error. Above code is the smallest repro I could find.

Related information

  • Seen in: VS IDE 2019, 16.7.0 Preview 1.0
  • The behavior is normal (only first error shown, no warning) with VS IDE Version 16.5.4 Community Ed. (RTM version).
  • The internal error disappears if you remove the first line with static member foo.

EDIT: it seems remarkably similar to this line, but the text is slightly different:

| DecisionTreeTest.Error _ -> pfailwith st "DecisionTreeTest.Error: only used during pattern match compilation"

Metadata

Metadata

Assignees

Labels

BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.Regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions