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

Mixing named arguments + callback style and getter should not compile #17956

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
14 changes: 13 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4313,7 +4313,19 @@ module TcDeclarations =
for slot in ds do
if isAbstractSlot slot then
match slot with
| SynMemberDefn.AbstractSlot (slotSig = synVal; range = m) ->
| SynMemberDefn.AbstractSlot (slotSig = synVal; flags = flags; range = m) as slot ->
let (SynValSig(ident = SynIdent(id, _); synType = synType)) = synVal
let hasNamedArgs =
match synType with
| SynType.Fun(argType= SynType.Tuple(path = pathSegments); returnType = _) ->
pathSegments
|> List.exists (function SynTupleTypeSegment.Type(SynType.SignatureParameter(id = Some id)) -> true | _ -> false)
| _ -> false

let isGetterSetter = flags.MemberKind = SynMemberKind.PropertyGetSet || flags.MemberKind = SynMemberKind.PropertySet || flags.MemberKind = SynMemberKind.PropertyGet
// Indexed properties uses "Item"y member name and are allowed with get and set
if id.idText <> "Item" && hasNamedArgs && isGetterSetter then
errorR(Error(FSComp.SR.tcAbstractPropertyCannotHaveNamedArgumentsWithGetSet(), m))
CheckDuplicatesArgNames synVal m
| _ -> ()

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1788,3 +1788,4 @@ featureUseTypeSubsumptionCache,"Use type conversion cache during compilation"
featureDontWarnOnUppercaseIdentifiersInBindingPatterns,"Don't warn on uppercase identifiers in binding patterns"
3873,chkDeprecatePlacesWhereSeqCanBeOmitted,"This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}'"
featureDeprecatePlacesWhereSeqCanBeOmitted,"Deprecate places where 'seq' can be omitted"
3874,tcAbstractPropertyCannotHaveNamedArgumentsWithGetSet,"Abstract properties cannot have named arguments with get and set accessors."
edgarfgp marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,23 @@ type MyIndexerClass() =
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Warning 3581, Line 3, Col 14, Line 3, Col 22, "An indexed property's getter and setter must have the same type. Property 'Indexer1' has getter of type 'string' but setter of type 'float'.")

[<Fact>]
let ``Mixing named arguments + callback style and getter should not compile``() =
Fsx """
type MyFunc = string * string option -> unit

type LabeledProperty =
abstract member alert: title:string * message:string option -> unit with get,set
abstract member alert2: string * string option -> unit with get,set
abstract member alert3: (string * string option -> unit) with get,set
abstract member alert4: MyFunc with get,set
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3874, Line 5, Col 5, Line 5, Col 85, "Abstract properties cannot have named arguments with get and set accessors.")
]

[<Fact>]
let ``Indexed2PropertiesSameType_fs preview``() =
Expand Down
Loading