fsharp
fsharp copied to clipboard
Improve diagnostic: member val in interface
Automatically implemented property occurs internal error.
Repro steps
// fsi
> type I =
abstract member X: int with get, set
type R =
{ x: int }
interface I with
member val X = 0 with get, set;;
member val X = 0 with get, set;;
-----------^^^^^^^^^
stdin(7,12): error FS0073: internal error: Unexpected definition
Expected behavior
No compile errors.
Actual behavior
Internal error.
Known workarounds
// fsi
> type I =
abstract member X: int with get, set
type R =
{ mutable x: int }
interface I with
member this.X with get() = this.x and set(v) = this.x <- v;;
type I =
interface
abstract member X : int
abstract member X : int with set
end
type R =
{mutable x: int;}
with
interface I
end
>
Related information
- Operating system: Windows 10
- Visual F# Tools: 15.4.1.17052902
- Editing Tools: Visual Studio 2017
This error happens in TypeChecker.fs in TcMutRecBindings_Phase2A_CreateRecursiveValuesAndCheckArgumentPatterns.
There is a match classMemberDef, containerInfo with
which doesn't match SynMemberDefn.AutoProperty and just fails. @KevinRansom I don't know to implement that matching case.
@forki @bleis-tift Just to note that the member val
isn't allowed in an interface implementation on a record or union type (because it implies a let
definition in the type, which is not allowed). So this is "just" a poor error message
Just ran into that one:
error FS0073: internal error: Unexpected definition (AutoProperty
([],false,X,None,Member,<fun:_fsyacc_reductions@2046-415>,
PreXmlDoc ((20,24),FSharp.Compiler.Ast+XmlDocCollector),None,
Const (Int32 10,_.fs (20,25--20,27) IsSynthetic=false),None,
_.fs (20,8--20,27) IsSynthetic=false),
ContainerInfo
(Parent _,
Some
(MemberOrValContainerInfo
(DogData,
Some
(IPosition,
SlotImplSet
([RequiredSlot (FSMeth (<TcGlobals>,IPosition,X,None),false);
RequiredSlot (FSMeth (<TcGlobals>,IPosition,Y,None),false)],
map
[("get_X",
[RequiredSlot (FSMeth (<TcGlobals>,IPosition,X,None),false)]);
("get_Y",
[RequiredSlot (FSMeth (<TcGlobals>,IPosition,Y,None),false)])],
[],
[FSProp (<TcGlobals>,IPosition,Some Y,None);
FSProp (<TcGlobals>,IPosition,Some X,None)])),None,
NoSafeInitInfo,[]))))
Well even if it's a bad error message it still is a bad error message which really needs to be fixed.
This seems to be fixed in F# 8 as it not longer throws an internal error
but now shows This declaration element is not permitted in an augmentation
cc @vzarytovskii