Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to release/dev17.13 #17892

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
"commands": [
"dotnet-counters"
],
"version": "8.0.460601"
"version": "8.0.547301"
},
"dotnet-dump": {
"commands": [
"dotnet-dump"
],
"version": "8.0.460601"
"version": "8.0.547301"
},
"dotnet-gcdump": {
"commands": [
"dotnet-gcdump"
],
"version": "8.0.460601"
"version": "8.0.547301"
},
"dotnet-sos": {
"commands": [
"dotnet-sos"
],
"version": "8.0.460601"
"version": "8.0.547301"
},
"dotnet-symbol": {
"commands": [
"dotnet-symbol"
],
"version": "1.0.460401"
"version": "8.0.547301"
},
"dotnet-trace": {
"commands": [
"dotnet-trace"
],
"version": "8.0.460601"
"version": "8.0.547301"
},
"fantomas": {
"commands": [
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 12 additions & 7 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -3333,15 +3333,20 @@ module EstablishTypeDefinitionCores =
| SynTypeDefnKind.Opaque | SynTypeDefnKind.Class | SynTypeDefnKind.Interface -> None
| _ -> error(InternalError("should have inferred tycon kind", m))

| [(ty, m)] ->
if not firstPass && not (match kind with SynTypeDefnKind.Class -> true | _ -> false) then
errorR (Error(FSComp.SR.tcStructsInterfacesEnumsDelegatesMayNotInheritFromOtherTypes(), m))
CheckSuperType cenv ty 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(), 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
else

Some ty
| _ ->
error(Error(FSComp.SR.tcTypesCannotInheritFromMultipleConcreteTypes(), m))
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type TK_I_005 =
abstract M : unit -> unit

[<Struct>]
type TK_I_006b =
inherit TK_I_005

Original file line number Diff line number Diff line change
Expand Up @@ -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.")
]

Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,23 @@ type Class() =
|> withDiagnostics [
(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")
]
8 changes: 4 additions & 4 deletions tests/fsharp/typeProviders/negTests/neg4.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions tests/fsharp/typeProviders/negTests/neg6.bsl
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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() = "" }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading