fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

internal error when implementing interface with auto property in record type (Unexpected definition (AutoProperty...)

Open smoothdeveloper opened this issue 3 years ago • 5 comments

Under .net framework FSI, I'm getting internal error:

Repro steps

type Foo =
  abstract member X : string with get, set

type FooImpl = 
  { name: string }
  interface Foo with
    member val X = "" with get, set

Actual behavior

error FS0073: internal error: Unexpected definition (AutoProperty
   ([], false, X, None, PropertyGetSet, <fun:_fsyacc_reductions@2322-424>,
    PreXmlDoc ((7,4), FSharp.Compiler.Xml.XmlDocCollector), None,
    \test.fsx (7,17--7,18),
    Const
      (String
         ("", Regular,
          \test.fsx (7,19--7,21)),
       \test.fsx (7,19--7,21)),
    Some
      \test.fsx (7,22--7,26),
    Some
      \test.fsx (7,22--7,35),
    \test.fsx (7,4--7,21)),
 ContainerInfo
  (Parent FSI_0002,
   Some
     (MemberOrValContainerInfo
        (FooImpl,
         Some
           (Foo,
            SlotImplSet
              ([RequiredSlot (FSMeth (<TcGlobals>, Foo, X, None), false);
                RequiredSlot (FSMeth (<TcGlobals>, Foo, X, None), false)],
               map
                 [("get_X",
                   [RequiredSlot (FSMeth (<TcGlobals>, Foo, X, None), false)]);
                  ("set_X",
                   [RequiredSlot (FSMeth (<TcGlobals>, Foo, X, None), false)])],
               [], [FSProp (<TcGlobals>, Foo, Some X, Some X)])), None,
         NoSafeInitInfo, []))))

Expected behavior

Compiles.

Known workarounds

To not use a record.

Related information

  • Windows 11
  • .NET Framework 4.8 FSI
  • VS 2022 17.2.6

smoothdeveloper avatar Aug 15 '22 09:08 smoothdeveloper

@nojaf should this also be fixed by https://github.com/dotnet/fsharp/pull/13664 or was it only for exception?

Update: probably not, since the change is specific to Exception, and this one is autoprop

vzarytovskii avatar Aug 15 '22 10:08 vzarytovskii

type Foo =
    abstract member X : string with get, set

type FooImpl = 
    interface Foo with
      member val X = "" with get, set

Also fails but for a different reason:

        member val X = "" with get, set;;
  ---------------------^^

stdin(6,22): error FS0971: Undefined value 'X@'

But this code is weird regardless, since FooImpl doesn't have constructor and won't be able to set the underlying X@ to the default value.

vzarytovskii avatar Aug 15 '22 10:08 vzarytovskii

This works, though:

type Foo =
    abstract member X : string with get, set

type FooImpl() = 
    interface Foo with
      member val X = "" with get, set

vzarytovskii avatar Aug 15 '22 11:08 vzarytovskii

Interesting, it also fails on sharplab, which uses 10 months old FCS. It seems bug is there for some time and unrelated to Florian's changes.

vzarytovskii avatar Aug 15 '22 11:08 vzarytovskii

So, we've checked it, and it's broken since at least 3.1.412, not something we introduced recently. We should probably emit different error if we try to have autoproperties on constructor-less types, since we don't generate implicit constructors and I guess it makes no sense having auto-properties on such types. And we should fix the case for the records, I guess?

cc @dsyme @0101

vzarytovskii avatar Aug 15 '22 12:08 vzarytovskii

@vzarytovskii Any decision here ? . Happy to help with error reporting

edgarfgp avatar Jan 14 '23 22:01 edgarfgp

The internal error reported in this issue has been fixed at some point in F# 8 likely by #15343. We have now an error an error message This declaration element is not permitted in an augmentation.

Screenshot 2023-11-26 at 18 37 25

We could close this issue and raise separate issues for :

  • Raise a new error if we try to have auto properties on constructor-less types,
  • Fix the case for the records supporting auto properties

edgarfgp avatar Nov 26 '23 18:11 edgarfgp

@vzarytovskii This can be closed

edgarfgp avatar Dec 13 '23 13:12 edgarfgp