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

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

Closed
abelbraaksma opened this issue May 26, 2020 · 5 comments · Fixed by #10187
Assignees
Labels
Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Regression
Milestone

Comments

@abelbraaksma
Copy link
Contributor

abelbraaksma commented May 26, 2020

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"

@auduchinok
Copy link
Member

auduchinok commented May 28, 2020

@abelbraaksma The assertion error was introduced in #7711 and there was no reports about it up until very recently.
I didn't manage to find a stable repro yet, so thank you so much for it, I can reliably reproduce it in Rider too (which presumably uses FCS that is similar to FCP in Visual Studio you're using), and I'm going to look into it.

@cartermp
Copy link
Contributor

Thanks @auduchinok!

@cartermp
Copy link
Contributor

@auduchinok have you had a chance to look into this?

@auduchinok
Copy link
Member

@cartermp I've looked into it once but didn't find the cause. I'm going to try again during this release cycle. I've also found new cases where recovery is missing in pattern matching, and perhaps digging deeper into it can help finding what's going wrong.

@dsyme dsyme added Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Sep 1, 2020
@cartermp cartermp added this to the Backlog milestone Sep 1, 2020
@TIHan TIHan self-assigned this Sep 21, 2020
@abelbraaksma
Copy link
Contributor Author

abelbraaksma commented Sep 26, 2020

Great to have this solved! Thanks @TIHan.

@cartermp cartermp modified the milestones: Backlog, 16.9 Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants