fsharp
fsharp copied to clipboard
internal error when implementing interface with auto property in record type (Unexpected definition (AutoProperty...)
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
@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
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.
This works, though:
type Foo =
abstract member X : string with get, set
type FooImpl() =
interface Foo with
member val X = "" with get, set
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.
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 Any decision here ? . Happy to help with error reporting
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.
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
@vzarytovskii This can be closed