From 037fa95475f298809d05bdadab7a6a81d72898d5 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 16 Oct 2024 18:36:41 +0100 Subject: [PATCH 1/9] Better ranges for implicit `Inherit` error reporting. --- src/Compiler/Checking/CheckDeclarations.fs | 48 ++++++++++--------- .../GraphChecking/FileContentMapping.fs | 2 +- .../Service/FSharpParseFileResults.fs | 2 +- .../Service/ServiceInterfaceStubGenerator.fs | 2 +- src/Compiler/Service/ServiceParseTreeWalk.fs | 2 +- src/Compiler/Service/ServiceParsedInputOps.fs | 4 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 3 +- .../ErrorMessages/ClassesTests.fs | 35 ++++++++++++++ ...ervice.SurfaceArea.netstandard20.debug.bsl | 4 +- ...vice.SurfaceArea.netstandard20.release.bsl | 4 +- .../data/SyntaxTree/Member/Inherit 02.fs.bsl | 10 ++-- 13 files changed, 81 insertions(+), 39 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 31ce9be573c..6d8cdd6aefe 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -1090,7 +1090,7 @@ module MutRecBindingChecking = [Phase2AIncrClassCtor (staticCtorInfo, Some incrCtorInfo)], innerState - | Some (SynMemberDefn.ImplicitInherit (ty, arg, _baseIdOpt, m)), _ -> + | Some (SynMemberDefn.ImplicitInherit (ty, arg, _baseIdOpt, m, _)), _ -> if tcref.TypeOrMeasureKind = TyparKind.Measure then error(Error(FSComp.SR.tcMeasureDeclarationsRequireStaticMembers(), m)) @@ -3324,7 +3324,6 @@ module EstablishTypeDefinitionCores = else None | SynTypeDefnSimpleRepr.General (kind, inherits, slotsigs, fields, isConcrete, _, _, _) -> let kind = InferTyconKind g (kind, attrs, slotsigs, fields, inSig, isConcrete, m) - match inheritedTys with | [] -> match kind with @@ -3335,9 +3334,9 @@ module EstablishTypeDefinitionCores = | [(ty, m)] -> let inheritRange = - match inherits with - | [] -> m - | (synType, _, _) :: _ -> synType.Range + match inherits with + | [] -> m + | (synType, _, _) :: _ -> synType.Range if not firstPass && not (match kind with SynTypeDefnKind.Class -> true | _ -> false) then errorR (Error(FSComp.SR.tcStructsInterfacesEnumsDelegatesMayNotInheritFromOtherTypes(), inheritRange)) CheckSuperType cenv ty inheritRange @@ -3345,11 +3344,13 @@ module EstablishTypeDefinitionCores = if firstPass then errorR(Error(FSComp.SR.tcCannotInheritFromVariableType(), inheritRange)) Some g.obj_ty_noNulls // a "super" that is a variable type causes grief later - else - + else Some ty - | _ -> - error(Error(FSComp.SR.tcTypesCannotInheritFromMultipleConcreteTypes(), m)) + | _ -> + inherits + |> List.skip 1 + |> List.iter (fun (synType, _, _) -> errorR(Error(FSComp.SR.tcTypesCannotInheritFromMultipleConcreteTypes(), synType.Range))) + None | SynTypeDefnSimpleRepr.Enum _ -> Some(g.system_Enum_ty) @@ -4291,19 +4292,20 @@ module TcDeclarations = let _, ds = ds |> List.takeUntil (function SynMemberDefn.LetBindings _ -> false | _ -> true) // Skip over 'let' and 'do' bindings - let _, ds = ds |> List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isAutoProperty]) - - match ds with - | SynMemberDefn.Member (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have binding", m)) - | SynMemberDefn.AbstractSlot (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have slotsig", m)) - | SynMemberDefn.Interface (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have interface", m)) - | SynMemberDefn.ImplicitCtor (range=m) :: _ -> errorR(InternalError("implicit class construction with two implicit constructions", m)) - | SynMemberDefn.AutoProperty (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have auto property", m)) - | SynMemberDefn.ImplicitInherit (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) - | SynMemberDefn.LetBindings (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) - | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) :: _ -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) - | SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) - | _ -> () + let _, ds = ds |> List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isAutoProperty]) + + for dfn in ds do + match dfn with + | SynMemberDefn.Member (range=m) -> errorR(InternalError("List.takeUntil is wrong, have binding", m)) + | SynMemberDefn.AbstractSlot (range=m) -> errorR(InternalError("List.takeUntil is wrong, have slotsig", m)) + | SynMemberDefn.Interface (range=m) -> errorR(InternalError("List.takeUntil is wrong, have interface", m)) + | SynMemberDefn.ImplicitCtor (range=m) -> errorR(InternalError("implicit class construction with two implicit constructions", m)) + | SynMemberDefn.AutoProperty (range=m) -> errorR(InternalError("List.takeUntil is wrong, have auto property", m)) + | SynMemberDefn.ImplicitInherit (trivia= { InheritKeyword = m }) -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) + | SynMemberDefn.LetBindings (range=m) -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) + | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) + | SynMemberDefn.NestedType (range=m) -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) + | _ -> () | ds -> // Check for duplicated parameters in abstract methods // Check for an interface implementation with auto properties on constructor-less types @@ -4474,7 +4476,7 @@ module TcDeclarations = let inherits = members |> List.choose (function | SynMemberDefn.Inherit (ty, idOpt, m, _) -> Some(ty, m, idOpt) - | SynMemberDefn.ImplicitInherit (ty, _, idOpt, m) -> Some(ty, m, idOpt) + | SynMemberDefn.ImplicitInherit (ty, _, idOpt, m, _) -> Some(ty, m, idOpt) | _ -> None) //let nestedTycons = cspec |> List.choose (function SynMemberDefn.NestedType (x, _, _) -> Some x | _ -> None) diff --git a/src/Compiler/Driver/GraphChecking/FileContentMapping.fs b/src/Compiler/Driver/GraphChecking/FileContentMapping.fs index 938034623ba..cdf02bea39a 100644 --- a/src/Compiler/Driver/GraphChecking/FileContentMapping.fs +++ b/src/Compiler/Driver/GraphChecking/FileContentMapping.fs @@ -212,7 +212,7 @@ let visitSynMemberDefn (md: SynMemberDefn) : FileContentEntry list = yield! collectFromOption visitBinding memberDefnForGet yield! collectFromOption visitBinding memberDefnForSet | SynMemberDefn.ImplicitCtor(ctorArgs = pat) -> yield! visitPat pat - | SynMemberDefn.ImplicitInherit(inheritType, inheritArgs, _, _) -> + | SynMemberDefn.ImplicitInherit(inheritType, inheritArgs, _, _, _) -> yield! visitSynType inheritType yield! visitSynExpr inheritArgs | SynMemberDefn.LetBindings(bindings = bindings) -> yield! List.collect visitBinding bindings diff --git a/src/Compiler/Service/FSharpParseFileResults.fs b/src/Compiler/Service/FSharpParseFileResults.fs index 7b273f71430..612057578f7 100644 --- a/src/Compiler/Service/FSharpParseFileResults.fs +++ b/src/Compiler/Service/FSharpParseFileResults.fs @@ -817,7 +817,7 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput, | SynMemberDefn.Inherit(range = m) -> // can break on the "inherit" clause yield! checkRange m - | SynMemberDefn.ImplicitInherit(_, arg, _, m) -> + | SynMemberDefn.ImplicitInherit(_, arg, _, m, _) -> // can break on the "inherit" clause yield! checkRange m yield! walkExpr true arg diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index f0ddc777b14..fb3e8dfbecc 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -825,7 +825,7 @@ module InterfaceStubGenerator = | SynMemberDefn.Open _ | SynMemberDefn.ImplicitCtor _ | SynMemberDefn.Inherit _ -> None - | SynMemberDefn.ImplicitInherit(_, expr, _, _) -> walkExpr expr + | SynMemberDefn.ImplicitInherit(_, expr, _, _, _) -> walkExpr expr and walkBinding (SynBinding(expr = expr)) = walkExpr expr diff --git a/src/Compiler/Service/ServiceParseTreeWalk.fs b/src/Compiler/Service/ServiceParseTreeWalk.fs index ca1a1c5e657..018cb7663f1 100644 --- a/src/Compiler/Service/ServiceParseTreeWalk.fs +++ b/src/Compiler/Service/ServiceParseTreeWalk.fs @@ -958,7 +958,7 @@ module SyntaxTraversal = | SynMemberDefn.ImplicitCtor(ctorArgs = pat) -> traverseSynSimplePats path pat - | SynMemberDefn.ImplicitInherit(synType, synExpr, _identOption, range) -> + | SynMemberDefn.ImplicitInherit(synType, synExpr, _identOption, range, _) -> [ dive () synType.Range (fun () -> match traverseInherit (synType, range) with diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index cfbefd49ade..44f00e278ce 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -905,7 +905,7 @@ module ParsedInput = | SynMemberDefn.ImplicitCtor(attributes = Attributes attrs; ctorArgs = pat) -> List.tryPick walkAttribute attrs |> Option.orElseWith (fun _ -> walkPat pat) - | SynMemberDefn.ImplicitInherit(t, e, _, _) -> walkType t |> Option.orElseWith (fun () -> walkExpr e) + | SynMemberDefn.ImplicitInherit(t, e, _, _, _) -> walkType t |> Option.orElseWith (fun () -> walkExpr e) | SynMemberDefn.LetBindings(bindings, _, _, _) -> List.tryPick walkBinding bindings @@ -2233,7 +2233,7 @@ module ParsedInput = | SynMemberDefn.ImplicitCtor(attributes = Attributes attrs; ctorArgs = pat) -> List.iter walkAttribute attrs walkPat pat - | SynMemberDefn.ImplicitInherit(t, e, _, _) -> + | SynMemberDefn.ImplicitInherit(t, e, _, _, _) -> walkType t walkExpr e | SynMemberDefn.LetBindings(bindings, _, _, _) -> List.iter walkBinding bindings diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index 81e893592b8..dfe89d66cc4 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -1488,7 +1488,7 @@ type SynMemberDefn = range: range * trivia: SynMemberDefnImplicitCtorTrivia - | ImplicitInherit of inheritType: SynType * inheritArgs: SynExpr * inheritAlias: Ident option * range: range + | ImplicitInherit of inheritType: SynType * inheritArgs: SynExpr * inheritAlias: Ident option * range: range * trivia: SynMemberDefnInheritTrivia | LetBindings of bindings: SynBinding list * isStatic: bool * isRecursive: bool * range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 379362f407c..e50e3afdf3e 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -1654,7 +1654,7 @@ type SynMemberDefn = trivia: SynMemberDefnImplicitCtorTrivia /// An implicit inherit definition, 'inherit (args...) as base' - | ImplicitInherit of inheritType: SynType * inheritArgs: SynExpr * inheritAlias: Ident option * range: range + | ImplicitInherit of inheritType: SynType * inheritArgs: SynExpr * inheritAlias: Ident option * range: range * trivia: SynMemberDefnInheritTrivia /// A 'let' definition within a class | LetBindings of bindings: SynBinding list * isStatic: bool * isRecursive: bool * range: range diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index fac3f30a073..2c4b4d6ff42 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -2321,7 +2321,8 @@ inheritsDefn: | INHERIT atomTypeNonAtomicDeprecated opt_HIGH_PRECEDENCE_APP atomicExprAfterType optBaseSpec { let mDecl = unionRanges (rhs parseState 1) $4.Range - SynMemberDefn.ImplicitInherit($2, $4, $5, mDecl) } + let trivia = { InheritKeyword = rhs parseState 1 } + SynMemberDefn.ImplicitInherit($2, $4, $5, mDecl, trivia) } | INHERIT ends_coming_soon_or_recover { let mDecl = (rhs parseState 1) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index f902fa14369..f323d20ce85 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -849,4 +849,39 @@ type C5 = class inherit System.MulticastDelegate override x.ToString() = "" end (Error 771, Line 4, Col 25, Line 4, Col 36, "The types System.ValueType, System.Enum, System.Delegate, System.MulticastDelegate and System.Array cannot be used as super types in an object expression or class") (Error 771, Line 5, Col 25, Line 5, Col 40, "The types System.ValueType, System.Enum, System.Delegate, System.MulticastDelegate and System.Array cannot be used as super types in an object expression or class"); (Error 771, Line 6, Col 25, Line 6, Col 49, "The types System.ValueType, System.Enum, System.Delegate, System.MulticastDelegate and System.Array cannot be used as super types in an object expression or class") + ] + + + [] + let ``Types can inherit from a single concrete type`` () = + Fsx """ +type ClassA() = class end + +type Class() = + inherit ClassA() + """ + |> typecheck + |> shouldSucceed + + [] + let ``Types cannot inherit from multiple concrete types.`` () = + Fsx """ +type ClassA() = class end + +type ClassB() = class end + +type ClassC() = class end + +type Class() = + inherit ClassA() + inherit ClassB() + inherit ClassC() + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 959, Line 10, Col 5, Line 10, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration") + (Error 959, Line 11, Col 5, Line 11, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration") + (Error 932, Line 10, Col 13, Line 10, Col 19, "Types cannot inherit from multiple concrete types") + (Error 932, Line 11, Col 13, Line 11, Col 19, "Types cannot inherit from multiple concrete types") ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index f08d67883b7..5740a2169e8 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -8150,7 +8150,9 @@ FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewAb FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewAutoProperty(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynAttributeList], Boolean, FSharp.Compiler.Syntax.Ident, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynType], FSharp.Compiler.Syntax.SynMemberKind, FSharp.Compiler.Syntax.SynMemberFlags, FSharp.Compiler.Syntax.SynMemberFlags, FSharp.Compiler.Xml.PreXmlDoc, FSharp.Compiler.Syntax.SynValSigAccess, FSharp.Compiler.Syntax.SynExpr, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnAutoPropertyTrivia) FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewGetSetMember(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynBinding], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynBinding], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberGetSetTrivia) FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewImplicitCtor(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynAccess], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynAttributeList], FSharp.Compiler.Syntax.SynPat, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Xml.PreXmlDoc, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnImplicitCtorTrivia) -FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewImplicitInherit(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynExpr, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynMemberDefn+ImplicitInherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia get_trivia() +FSharp.Compiler.Syntax.SynMemberDefn+ImplicitInherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia trivia +FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewImplicitInherit(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynExpr, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia) FSharp.Compiler.Syntax.SynMemberDefn+Inherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia get_trivia() FSharp.Compiler.Syntax.SynMemberDefn+Inherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia trivia FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewInherit(FSharp.Compiler.Syntax.SynType, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index f08d67883b7..5740a2169e8 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -8150,7 +8150,9 @@ FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewAb FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewAutoProperty(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynAttributeList], Boolean, FSharp.Compiler.Syntax.Ident, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynType], FSharp.Compiler.Syntax.SynMemberKind, FSharp.Compiler.Syntax.SynMemberFlags, FSharp.Compiler.Syntax.SynMemberFlags, FSharp.Compiler.Xml.PreXmlDoc, FSharp.Compiler.Syntax.SynValSigAccess, FSharp.Compiler.Syntax.SynExpr, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnAutoPropertyTrivia) FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewGetSetMember(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynBinding], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynBinding], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberGetSetTrivia) FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewImplicitCtor(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynAccess], Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynAttributeList], FSharp.Compiler.Syntax.SynPat, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Xml.PreXmlDoc, FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnImplicitCtorTrivia) -FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewImplicitInherit(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynExpr, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynMemberDefn+ImplicitInherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia get_trivia() +FSharp.Compiler.Syntax.SynMemberDefn+ImplicitInherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia trivia +FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewImplicitInherit(FSharp.Compiler.Syntax.SynType, FSharp.Compiler.Syntax.SynExpr, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia) FSharp.Compiler.Syntax.SynMemberDefn+Inherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia get_trivia() FSharp.Compiler.Syntax.SynMemberDefn+Inherit: FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia trivia FSharp.Compiler.Syntax.SynMemberDefn: FSharp.Compiler.Syntax.SynMemberDefn NewInherit(FSharp.Compiler.Syntax.SynType, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range, FSharp.Compiler.SyntaxTrivia.SynMemberDefnInheritTrivia) diff --git a/tests/service/data/SyntaxTree/Member/Inherit 02.fs.bsl b/tests/service/data/SyntaxTree/Member/Inherit 02.fs.bsl index 51185750c32..3a9482667e2 100644 --- a/tests/service/data/SyntaxTree/Member/Inherit 02.fs.bsl +++ b/tests/service/data/SyntaxTree/Member/Inherit 02.fs.bsl @@ -13,11 +13,11 @@ ImplFile (Unspecified, [ImplicitInherit (LongIdent (SynLongIdent ([T2], [], [None])), - Const (Unit, (4,14--4,16)), None, (4,4--4,16))], - (4,4--4,16)), [], None, (3,5--4,16), - { LeadingKeyword = Type (3,0--3,4) - EqualsRange = Some (3,8--3,9) - WithKeyword = None })], (3,0--4,16))], + Const (Unit, (4,14--4,16)), None, (4,4--4,16), + { InheritKeyword = (4,4--4,11) })], (4,4--4,16)), [], + None, (3,5--4,16), { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,8--3,9) + WithKeyword = None })], (3,0--4,16))], PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, (1,0--4,16), { LeadingKeyword = Module (1,0--1,6) })], (true, true), { ConditionalDirectives = [] From 5e007892c398ec9c3f6bb1c706e7ae2469ae6955 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 16 Oct 2024 18:38:57 +0100 Subject: [PATCH 2/9] release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index a7d549b23bd..e81354d935f 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -22,5 +22,6 @@ * Better ranges for CE `use` error reporting. ([PR #17811](https://github.com/dotnet/fsharp/pull/17811)) * Better ranges for `inherit` error reporting. ([PR #17879](https://github.com/dotnet/fsharp/pull/17879)) * Better ranges for `inherit` `struct` error reporting. ([PR #17886](https://github.com/dotnet/fsharp/pull/17886)) +* Better ranges for implicit `inherit` error reporting. ([PR #17893](https://github.com/dotnet/fsharp/pull/17893)) ### Breaking Changes From f9506bd3cb67cac9f830d26bf82ecfae82cf0b19 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 16 Oct 2024 18:44:33 +0100 Subject: [PATCH 3/9] format --- src/Compiler/SyntaxTree/SyntaxTree.fs | 7 ++++++- src/Compiler/SyntaxTree/SyntaxTree.fsi | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index dfe89d66cc4..b43f213e1f5 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -1488,7 +1488,12 @@ type SynMemberDefn = range: range * trivia: SynMemberDefnImplicitCtorTrivia - | ImplicitInherit of inheritType: SynType * inheritArgs: SynExpr * inheritAlias: Ident option * range: range * trivia: SynMemberDefnInheritTrivia + | ImplicitInherit of + inheritType: SynType * + inheritArgs: SynExpr * + inheritAlias: Ident option * + range: range * + trivia: SynMemberDefnInheritTrivia | LetBindings of bindings: SynBinding list * isStatic: bool * isRecursive: bool * range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index e50e3afdf3e..1aaaf37898c 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -1654,7 +1654,12 @@ type SynMemberDefn = trivia: SynMemberDefnImplicitCtorTrivia /// An implicit inherit definition, 'inherit (args...) as base' - | ImplicitInherit of inheritType: SynType * inheritArgs: SynExpr * inheritAlias: Ident option * range: range * trivia: SynMemberDefnInheritTrivia + | ImplicitInherit of + inheritType: SynType * + inheritArgs: SynExpr * + inheritAlias: Ident option * + range: range * + trivia: SynMemberDefnInheritTrivia /// A 'let' definition within a class | LetBindings of bindings: SynBinding list * isStatic: bool * isRecursive: bool * range: range From 3e40e1d5d13aac6b3bf778ed27926574e3b9155f Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 16 Oct 2024 21:59:40 +0100 Subject: [PATCH 4/9] Better check --- src/Compiler/Checking/CheckDeclarations.fs | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 6d8cdd6aefe..2ae202a3ac2 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -4291,21 +4291,24 @@ module TcDeclarations = // Skip over 'let' and 'do' bindings let _, ds = ds |> List.takeUntil (function SynMemberDefn.LetBindings _ -> false | _ -> true) - // Skip over 'let' and 'do' bindings - let _, ds = ds |> List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isAutoProperty]) - - for dfn in ds do - match dfn with - | SynMemberDefn.Member (range=m) -> errorR(InternalError("List.takeUntil is wrong, have binding", m)) - | SynMemberDefn.AbstractSlot (range=m) -> errorR(InternalError("List.takeUntil is wrong, have slotsig", m)) - | SynMemberDefn.Interface (range=m) -> errorR(InternalError("List.takeUntil is wrong, have interface", m)) - | SynMemberDefn.ImplicitCtor (range=m) -> errorR(InternalError("implicit class construction with two implicit constructions", m)) - | SynMemberDefn.AutoProperty (range=m) -> errorR(InternalError("List.takeUntil is wrong, have auto property", m)) - | SynMemberDefn.ImplicitInherit (trivia= { InheritKeyword = m }) -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) - | SynMemberDefn.LetBindings (range=m) -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) - | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) - | SynMemberDefn.NestedType (range=m) -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) - | _ -> () + // Skip over member bindings, abstract slots, interfaces and auto properties + let _, ds = ds |> List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isAutoProperty]) + + match ds with + | SynMemberDefn.Member (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have binding", m)) + | SynMemberDefn.AbstractSlot (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have slotsig", m)) + | SynMemberDefn.Interface (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have interface", m)) + | SynMemberDefn.ImplicitCtor (range=m) :: _ -> errorR(InternalError("implicit class construction with two implicit constructions", m)) + | SynMemberDefn.AutoProperty (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have auto property", m)) + | SynMemberDefn.LetBindings (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) + | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) :: _ -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) + | SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) + | rest -> + for dfn in rest do + match dfn with + | SynMemberDefn.ImplicitInherit (trivia= { InheritKeyword = m }) -> + errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) + | _ -> () | ds -> // Check for duplicated parameters in abstract methods // Check for an interface implementation with auto properties on constructor-less types From cffa0ccdbdfc03c67c80b93e25e498b8d79ea99a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 17 Oct 2024 11:02:25 +0100 Subject: [PATCH 5/9] Update src/Compiler/Checking/CheckDeclarations.fs Co-authored-by: Tomas Grosup --- src/Compiler/Checking/CheckDeclarations.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 2ae202a3ac2..772d3d331e9 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -3336,7 +3336,7 @@ module EstablishTypeDefinitionCores = let inheritRange = match inherits with | [] -> m - | (synType, _, _) :: _ -> synType.Range + | (synType, _, _) :: _ -> synType.Range if not firstPass && not (match kind with SynTypeDefnKind.Class -> true | _ -> false) then errorR (Error(FSComp.SR.tcStructsInterfacesEnumsDelegatesMayNotInheritFromOtherTypes(), inheritRange)) CheckSuperType cenv ty inheritRange From bcad1cbd36e3167ea20968bb824d5d97a39cb13b Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 17 Oct 2024 13:10:56 +0100 Subject: [PATCH 6/9] PR comments --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 2 +- src/Compiler/Checking/CheckDeclarations.fs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index e81354d935f..09e63c3d2b2 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -22,6 +22,6 @@ * Better ranges for CE `use` error reporting. ([PR #17811](https://github.com/dotnet/fsharp/pull/17811)) * Better ranges for `inherit` error reporting. ([PR #17879](https://github.com/dotnet/fsharp/pull/17879)) * Better ranges for `inherit` `struct` error reporting. ([PR #17886](https://github.com/dotnet/fsharp/pull/17886)) -* Better ranges for implicit `inherit` error reporting. ([PR #17893](https://github.com/dotnet/fsharp/pull/17893)) +* Better ranges for `inherit` objects error reporting. ([PR #17893](https://github.com/dotnet/fsharp/pull/17893)) ### Breaking Changes diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 2ae202a3ac2..508e5da8456 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -3347,9 +3347,11 @@ module EstablishTypeDefinitionCores = else Some ty | _ -> - inherits - |> List.skip 1 - |> List.iter (fun (synType, _, _) -> errorR(Error(FSComp.SR.tcTypesCannotInheritFromMultipleConcreteTypes(), synType.Range))) + match inherits with + | [] -> () + | _ :: inherits -> + for synType, _, _ in inherits do + errorR(Error(FSComp.SR.tcTypesCannotInheritFromMultipleConcreteTypes(), synType.Range)) None | SynTypeDefnSimpleRepr.Enum _ -> From 306a15fe32584ff86da0ef38421505b0edafdb29 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 19 Oct 2024 15:59:34 +0100 Subject: [PATCH 7/9] do not use 959 --- src/Compiler/Checking/CheckDeclarations.fs | 7 +------ .../ErrorMessages/ClassesTests.fs | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index dd4b68b765e..1b49a35b09b 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -4305,12 +4305,7 @@ module TcDeclarations = | SynMemberDefn.LetBindings (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) :: _ -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) | SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) - | rest -> - for dfn in rest do - match dfn with - | SynMemberDefn.ImplicitInherit (trivia= { InheritKeyword = m }) -> - errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) - | _ -> () + | _ -> () | ds -> // Check for duplicated parameters in abstract methods // Check for an interface implementation with auto properties on constructor-less types diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index f323d20ce85..070d7dd416b 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -880,8 +880,6 @@ type Class() = |> typecheck |> shouldFail |> withDiagnostics [ - (Error 959, Line 10, Col 5, Line 10, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration") - (Error 959, Line 11, Col 5, Line 11, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration") (Error 932, Line 10, Col 13, Line 10, Col 19, "Types cannot inherit from multiple concrete types") (Error 932, Line 11, Col 13, Line 11, Col 19, "Types cannot inherit from multiple concrete types") ] \ No newline at end of file From 7d024036449f7bd1d3ecfc59b19676faf9f58401 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 24 Oct 2024 13:48:28 +0100 Subject: [PATCH 8/9] fix PR comments and add more tests --- src/Compiler/Checking/CheckDeclarations.fs | 3 +- .../ErrorMessages/ClassesTests.fs | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index cbe4a48a865..2eea27911f1 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -4302,6 +4302,7 @@ module TcDeclarations = | SynMemberDefn.Interface (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have interface", m)) | SynMemberDefn.ImplicitCtor (range=m) :: _ -> errorR(InternalError("implicit class construction with two implicit constructions", m)) | SynMemberDefn.AutoProperty (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have auto property", m)) + | SynMemberDefn.ImplicitInherit (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) | SynMemberDefn.LetBindings (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) :: _ -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) | SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) @@ -4476,7 +4477,7 @@ module TcDeclarations = let inherits = members |> List.choose (function | SynMemberDefn.Inherit (Some ty, idOpt, m, _) -> Some(ty, m, idOpt) - | SynMemberDefn.ImplicitInherit (ty, _, idOpt, m) -> Some(ty, m, idOpt) + | SynMemberDefn.ImplicitInherit (ty, _, idOpt, m, _) -> Some(ty, m, idOpt) | _ -> None) //let nestedTycons = cspec |> List.choose (function SynMemberDefn.NestedType (x, _, _) -> Some x | _ -> None) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index 2bf7c8f7bae..6adb49bbd72 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -892,6 +892,52 @@ type Class() = |> typecheck |> shouldFail |> withDiagnostics [ + (Error 959, Line 10, Col 5, Line 10, Col 21, "Type definitions may only have one 'inherit' specification and it must be the first declaration") (Error 932, Line 10, Col 13, Line 10, Col 19, "Types cannot inherit from multiple concrete types") (Error 932, Line 11, Col 13, Line 11, Col 19, "Types cannot inherit from multiple concrete types") + ] + + [] + let ``Types cannot inherit from multiple concrete types. Type name cannot be empty.`` () = + Fsx """ +type IA = interface end + +type I = + inherit IA + inherit + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 3159, Line 6, Col 5, Line 6, Col 12, "Type name cannot be empty.") + ] + + [] + let ``Inheriting multiple base interfaces`` () = + Fsx """ +type IA = interface end +type IB = interface end + +type I = + inherit IA + inherit IB + """ + |> typecheck + |> shouldSucceed + + [] + let ``Class inheriting multiple base interfaces`` () = + Fsx """ +type IA = interface end +type IB = interface end + +type I() = + inherit IA + inherit IB + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 961, Line 6, Col 5, Line 6, Col 12, "This 'inherit' declaration specifies the inherited type but no arguments. Consider supplying arguments, e.g. 'inherit BaseType(args)'.") + (Error 932, Line 7, Col 13, Line 7, Col 15, "Types cannot inherit from multiple concrete types") ] \ No newline at end of file From eff563514c5cb3c3317fa26e5ac24201e03182aa Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 25 Oct 2024 13:28:18 +0100 Subject: [PATCH 9/9] moving 959 to type definition range --- src/Compiler/Checking/CheckDeclarations.fs | 6 +++--- .../ErrorMessages/ClassesTests.fs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 2eea27911f1..80c1a656c2d 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -4281,7 +4281,7 @@ module TcDeclarations = // multiple (binding or slotsig or field or interface or inherit). // i.e. not local-bindings, implicit ctor or implicit inherit (or tycon?). // atMostOne inherit. - let private CheckMembersForm ds = + let private CheckMembersForm ds m = match ds with | d :: ds when isImplicitCtor d -> // Implicit construction @@ -4302,7 +4302,7 @@ module TcDeclarations = | SynMemberDefn.Interface (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have interface", m)) | SynMemberDefn.ImplicitCtor (range=m) :: _ -> errorR(InternalError("implicit class construction with two implicit constructions", m)) | SynMemberDefn.AutoProperty (range=m) :: _ -> errorR(InternalError("List.takeUntil is wrong, have auto property", m)) - | SynMemberDefn.ImplicitInherit (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) + | SynMemberDefn.ImplicitInherit _ :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveOneInherit(), m)) | SynMemberDefn.LetBindings (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypeDefinitionsWithImplicitConstructionMustHaveLocalBindingsBeforeMembers(), m)) | SynMemberDefn.Inherit (trivia= { InheritKeyword = m }) :: _ -> errorR(Error(FSComp.SR.tcInheritDeclarationMissingArguments(), m)) | SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m)) @@ -4470,7 +4470,7 @@ module TcDeclarations = | SynTypeDefnRepr.ObjectModel(kind, members, m) -> let members = desugarGetSetMembers members - CheckMembersForm members + CheckMembersForm members synTyconInfo.Range let fields = members |> List.choose (function SynMemberDefn.ValField (fieldInfo = f) -> Some f | _ -> None) let implements2 = members |> List.choose (function SynMemberDefn.Interface (interfaceType=ty) -> Some(ty, ty.Range) | _ -> None) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index 6adb49bbd72..e86621d7093 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -892,7 +892,7 @@ type Class() = |> typecheck |> shouldFail |> withDiagnostics [ - (Error 959, Line 10, Col 5, Line 10, Col 21, "Type definitions may only have one 'inherit' specification and it must be the first declaration") + (Error 959, Line 8, Col 6, Line 8, Col 11, "Type definitions may only have one 'inherit' specification and it must be the first declaration") (Error 932, Line 10, Col 13, Line 10, Col 19, "Types cannot inherit from multiple concrete types") (Error 932, Line 11, Col 13, Line 11, Col 19, "Types cannot inherit from multiple concrete types") ]