зеркало из https://github.com/dotnet/fsharp.git
Better error range for `struct` and restricted super types `inherit` (#17886)
* Better error range for struct inherit * CheckSuperType * release notes * E_RestrictedSuperTypes * neg6.bsl * neg4.bsl
This commit is contained in:
Родитель
a89514e448
Коммит
346a59f93e
|
@ -21,5 +21,6 @@
|
|||
* Better ranges for CE `match!`. ([PR #17789](https://github.com/dotnet/fsharp/pull/17789))
|
||||
* 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))
|
||||
|
||||
### Breaking Changes
|
||||
|
|
|
@ -3322,7 +3322,7 @@ module EstablishTypeDefinitionCores =
|
|||
| SynTypeDefnSimpleRepr.Record _ ->
|
||||
if tycon.IsStructRecordOrUnionTycon then Some(g.system_Value_ty)
|
||||
else None
|
||||
| SynTypeDefnSimpleRepr.General (kind, _, slotsigs, fields, isConcrete, _, _, _) ->
|
||||
| SynTypeDefnSimpleRepr.General (kind, inherits, slotsigs, fields, isConcrete, _, _, _) ->
|
||||
let kind = InferTyconKind g (kind, attrs, slotsigs, fields, inSig, isConcrete, m)
|
||||
|
||||
match inheritedTys with
|
||||
|
@ -3334,14 +3334,19 @@ module EstablishTypeDefinitionCores =
|
|||
| _ -> error(InternalError("should have inferred tycon kind", m))
|
||||
|
||||
| [(ty, m)] ->
|
||||
let inheritRange =
|
||||
match inherits with
|
||||
| [] -> m
|
||||
| (synType, _, _) :: _ -> synType.Range
|
||||
if not firstPass && not (match kind with SynTypeDefnKind.Class -> true | _ -> false) then
|
||||
errorR (Error(FSComp.SR.tcStructsInterfacesEnumsDelegatesMayNotInheritFromOtherTypes(), m))
|
||||
CheckSuperType cenv ty m
|
||||
errorR (Error(FSComp.SR.tcStructsInterfacesEnumsDelegatesMayNotInheritFromOtherTypes(), inheritRange))
|
||||
CheckSuperType cenv ty inheritRange
|
||||
if isTyparTy g ty then
|
||||
if firstPass then
|
||||
errorR(Error(FSComp.SR.tcCannotInheritFromVariableType(), m))
|
||||
errorR(Error(FSComp.SR.tcCannotInheritFromVariableType(), inheritRange))
|
||||
Some g.obj_ty_noNulls // a "super" that is a variable type causes grief later
|
||||
else
|
||||
|
||||
Some ty
|
||||
| _ ->
|
||||
error(Error(FSComp.SR.tcTypesCannotInheritFromMultipleConcreteTypes(), m))
|
||||
|
|
|
@ -7140,7 +7140,7 @@ and CheckSuperType (cenv: cenv) ty m =
|
|||
typeEquiv g ty g.system_Array_ty ||
|
||||
typeEquiv g ty g.system_MulticastDelegate_ty ||
|
||||
typeEquiv g ty g.system_Delegate_ty then
|
||||
error(Error(FSComp.SR.tcPredefinedTypeCannotBeUsedAsSuperType(), m))
|
||||
errorR(Error(FSComp.SR.tcPredefinedTypeCannotBeUsedAsSuperType(), m))
|
||||
|
||||
if isErasedType g ty then
|
||||
errorR(Error(FSComp.SR.tcCannotInheritFromErasedType(), m))
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
type TK_I_005 =
|
||||
abstract M : unit -> unit
|
||||
|
||||
[<Struct>]
|
||||
type TK_I_006b =
|
||||
inherit TK_I_005
|
||||
|
|
@ -38,3 +38,15 @@ module StructTypes =
|
|||
|> shouldSucceed
|
||||
|> ignore
|
||||
|
||||
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_Inheritance.fs"|])>]
|
||||
let ``StructTypes - E_Inheritance.fs`` compilation =
|
||||
compilation
|
||||
|> asFsx
|
||||
|> withOptions ["--warnaserror+"; "--nowarn:988"]
|
||||
|> typecheck
|
||||
|> shouldFail
|
||||
|> withDiagnostics [
|
||||
(Error 931, Line 6, Col 12, Line 6, Col 20, "Structs, interfaces, enums and delegates cannot inherit from other types");
|
||||
(Error 946, Line 6, Col 12, Line 6, Col 20, "Cannot inherit from interface type. Use interface ... with instead.")
|
||||
]
|
||||
|
||||
|
|
|
@ -831,3 +831,22 @@ type Class() =
|
|||
(Error 961, Line 5, Col 5, Line 5, Col 12, "This 'inherit' declaration specifies the inherited type but no arguments. Consider supplying arguments, e.g. 'inherit BaseType(args)'.")
|
||||
(Error 946, Line 5, Col 13, Line 5, Col 15, "Cannot inherit from interface type. Use interface ... with instead.")
|
||||
]
|
||||
|
||||
[<Fact>]
|
||||
let ``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.`` () =
|
||||
Fsx """
|
||||
type C1 = class inherit System.ValueType override x.ToString() = "" end
|
||||
type C2 = class inherit System.Array override x.ToString() = "" end
|
||||
type C3 = class inherit System.Enum override x.ToString() = "" end
|
||||
type C4 = class inherit System.Delegate override x.ToString() = "" end
|
||||
type C5 = class inherit System.MulticastDelegate override x.ToString() = "" end
|
||||
"""
|
||||
|> typecheck
|
||||
|> shouldFail
|
||||
|> withDiagnostics [
|
||||
(Error 771, Line 2, Col 25, Line 2, Col 41, "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 3, Col 25, Line 3, Col 37, "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 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")
|
||||
]
|
|
@ -17,12 +17,12 @@ neg4.fsx(30,5,30,22): typecheck error FS3062: This type test with a provided typ
|
|||
|
||||
neg4.fsx(36,5,36,28): typecheck error FS3060: This type test or downcast will erase the provided type 'HelloWorldType' to the type 'System.Object'
|
||||
|
||||
neg4.fsx(42,8,42,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg4.fsx(42,16,42,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg4.fsx(42,8,42,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg4.fsx(42,16,42,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg4.fsx(47,8,47,35): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg4.fsx(47,16,47,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg4.fsx(47,8,47,35): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg4.fsx(47,16,47,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg4.fsx(52,25,52,42): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
neg6.fsx(8,3,8,27): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg6.fsx(8,11,8,25): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg6.fsx(8,3,8,27): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg6.fsx(8,11,8,25): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg6.fsx(11,3,11,30): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg6.fsx(11,11,11,28): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg6.fsx(11,3,11,30): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg6.fsx(11,11,11,28): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg6.fsx(14,3,14,35): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg6.fsx(14,11,14,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
||||
neg6.fsx(14,3,14,35): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
neg6.fsx(14,11,14,33): typecheck error FS3063: Cannot inherit from erased provided type
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
//<Expects id="FS0771" span="(22,16)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(23,16)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(24,16)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(26,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(26,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(27,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(27,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(28,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(28,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(29,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(29,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(30,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(30,17)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(26,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(26,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(27,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(27,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(28,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(28,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(29,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(29,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(30,25)" status="error">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</Expects>
|
||||
//<Expects id="FS0771" span="(30,25)" status="error">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</Expects>
|
||||
|
||||
#light
|
||||
let o1 = { new System.ValueType with member x.ToString() = "" }
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// #Regression #Conformance #ObjectOrientedTypes #TypeInference
|
||||
// attribute must match inferred type
|
||||
//<Expects id="FS0927" span="(16,6-16,15)" status="error">The kind of the type specified by its attributes does not match the kind implied by its definition</Expects>
|
||||
//<Expects id="FS0931" span="(20,4-20,20)" status="error">Structs, interfaces, enums and delegates cannot inherit from other types</Expects>
|
||||
//<Expects id="FS0931" span="(20,12-20,20)" status="error">Structs, interfaces, enums and delegates cannot inherit from other types</Expects>
|
||||
//<Expects id="FS0946" span="(20,12-20,20)" status="error">Cannot inherit from interface type\. Use interface \.\.\. with instead</Expects>
|
||||
//<Expects id="FS0927" span="(28,6-28,15)" status="error">The kind of the type specified by its attributes does not match the kind implied by its definition</Expects>
|
||||
//<Expects id="FS0931" span="(32,4-32,20)" status="error">Structs, interfaces, enums and delegates cannot inherit from other types</Expects>
|
||||
//<Expects id="FS0931" span="(32,12-32,20)" status="error">Structs, interfaces, enums and delegates cannot inherit from other types</Expects>
|
||||
//<Expects id="FS0946" span="(32,12-32,20)" status="error">Cannot inherit from interface type\. Use interface \.\.\. with instead</Expects>
|
||||
|
||||
// An interface
|
||||
|
|
Загрузка…
Ссылка в новой задаче