fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Improve error recovery for: alias a struct anonymous record

Open cartermp opened this issue 6 years ago • 5 comments

type R = struct {| S: string |}

Expected: this works

Actual: image

cartermp avatar Jan 18 '19 18:01 cartermp

Does struct keyword work with records at all?

majocha avatar Jan 18 '19 19:01 majocha

Nope, for that you use the attribute on the definition. But struct { |...|} is the anon record syntax, so it's sort of an odd point.

cartermp avatar Jan 18 '19 19:01 cartermp

Indeed. Somehow the struct {| … |} syntax works in Visual Studio but not in command line fsi on my PC. Hmm.

majocha avatar Jan 18 '19 19:01 majocha

This is by design. Parentheses are required. There is a type declaration form type R - struct ... end and that takes precedence. I'll note this for clarification in the language spec or RFC

type R = (struct {| S: string |})

dsyme avatar Aug 26 '20 15:08 dsyme

Re-opening and reclassifying since the error recovery here is really, really awful:

image

There is no hint at all that you need to add parentheses and it destroys your editor afterwards.

cartermp avatar Aug 26 '20 15:08 cartermp