Skip to content
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Fix nullable types formatting in `FSharpType.Format` and tooltips to include parentheses. ([PR #18842](https://github.com/dotnet/fsharp/pull/18842))
* TypeMismatchDiagnosticExtendedData: fix expected and actual types calculation. ([Issue ](https://github.com/dotnet/fsharp/pull/18851))
* Parser: fix range for computed binding expressions ([PR #18903](https://github.com/dotnet/fsharp/pull/18903))
* Checker: fix declaring type for abbreviated types extensions ([PR #18909](https://github.com/dotnet/fsharp/pull/18909))

### Changed
* Use `errorR` instead of `error` in `CheckDeclarations.fs` when possible. ([PR #18645](https://github.com/dotnet/fsharp/pull/18645))
Expand Down
19 changes: 8 additions & 11 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4250,11 +4250,9 @@ module TcDeclarations =
// a) For interfaces, only if it is in the original defn.
// Augmentations to interfaces via partial type defns will always be extensions, e.g. extension members on interfaces.
// b) For other types, if the type is isInSameModuleOrNamespace
let declKind, typars =
if isAtOriginalTyconDefn then
ModuleOrMemberBinding, reqTypars

else
if isAtOriginalTyconDefn then
ModuleOrMemberBinding, tcref, reqTypars
else
let isInSameModuleOrNamespace =
match envForDecls.eModuleOrNamespaceTypeAccumulator.Value.TypesByMangledName.TryGetValue tcref.LogicalName with
| true, tycon -> tyconOrder.Compare(tcref.Deref, tycon) = 0
Expand All @@ -4270,25 +4268,24 @@ module TcDeclarations =
let _tpenv = TcTyparConstraints cenv NoNewTypars CheckCxs ItemOccurrence.UseInType envForTycon emptyUnscopedTyparEnv synTyparCxs
declaredTypars |> List.iter (SetTyparRigid envForDecls.DisplayEnv m)

if isInSameModuleOrNamespace && not isInterfaceOrDelegateOrEnum then
if tcref.TypeAbbrev.IsSome then
ExtrinsicExtensionBinding, tcref, declaredTypars
elif isInSameModuleOrNamespace && not isInterfaceOrDelegateOrEnum then
// For historical reasons we only give a warning for incorrect type parameters on intrinsic extensions
if nReqTypars <> synTypars.Length then
errorR(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
if not (typarsAEquiv g (TypeEquivEnv.EmptyWithNullChecks g) reqTypars declaredTypars) then
warning(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
// Note we return 'reqTypars' for intrinsic extensions since we may only have given warnings
IntrinsicExtensionBinding, reqTypars
IntrinsicExtensionBinding, tcref, reqTypars
else
if isInSameModuleOrNamespace && isDelegateOrEnum then
errorR(Error(FSComp.SR.tcMembersThatExtendInterfaceMustBePlacedInSeparateModule(), tcref.Range))
if nReqTypars <> synTypars.Length then
error(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
if not (typarsAEquiv g (TypeEquivEnv.EmptyWithNullChecks g) reqTypars declaredTypars) then
errorR(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
ExtrinsicExtensionBinding, declaredTypars


declKind, tcref, typars
ExtrinsicExtensionBinding, tcref, declaredTypars


let private isAugmentationTyconDefnRepr = function SynTypeDefnSimpleRepr.General(kind=SynTypeDefnKind.Augmentation _) -> true | _ -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ type FloatAlias with
(Error 909, Line 6, Col 15, Line 6, Col 34, "All implemented interfaces should be declared on the initial declaration of the type")
]

[<Fact>]
let ``Members 04 - Error in expr`` () =
Fsx """
type StringAlias = string

type StringAlias with
member x.Length = x.Length + ""
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 964, Line 4, Col 6, Line 4, Col 17, "Type abbreviations cannot have augmentations")
(Error 895, Line 5, Col 5, Line 5, Col 36, "Type abbreviations cannot have members")
(Error 1, Line 5, Col 34, Line 5, Col 36, "The type 'string' does not match the type 'int'")
(Error 43, Line 5, Col 32, Line 5, Col 33, "The type 'string' does not match the type 'int'")
]

[<Fact>]
let ``Multiple types 01`` () =
Fsx """
Expand Down
Loading