diff --git a/src/Compiler/Checking/PostInferenceChecks.fs b/src/Compiler/Checking/PostInferenceChecks.fs
index 427854b58d5..62c5a2f5f11 100644
--- a/src/Compiler/Checking/PostInferenceChecks.fs
+++ b/src/Compiler/Checking/PostInferenceChecks.fs
@@ -2414,11 +2414,14 @@ let CheckEntityDefn cenv env (tycon: Entity) =
// Check to see if the signatures of the both getter and the setter imply the same property type
- if pinfo.HasGetter && pinfo.HasSetter && not pinfo.IsIndexer then
+ if pinfo.HasGetter && pinfo.HasSetter then
let ty1 = pinfo.DropSetter().GetPropertyType(cenv.amap, m)
let ty2 = pinfo.DropGetter().GetPropertyType(cenv.amap, m)
if not (typeEquivAux EraseNone cenv.amap.g ty1 ty2) then
- errorR(Error(FSComp.SR.chkGetterAndSetterHaveSamePropertyType(pinfo.PropertyName, NicePrint.minimalStringOfType cenv.denv ty1, NicePrint.minimalStringOfType cenv.denv ty2), m))
+ if g.langVersion.SupportsFeature(LanguageFeature.WarningIndexedPropertiesGetSetSameType) && pinfo.IsIndexer then
+ warning(Error(FSComp.SR.chkIndexedGetterAndSetterHaveSamePropertyType(pinfo.PropertyName, NicePrint.minimalStringOfType cenv.denv ty1, NicePrint.minimalStringOfType cenv.denv ty2), m))
+ if not pinfo.IsIndexer then
+ errorR(Error(FSComp.SR.chkGetterAndSetterHaveSamePropertyType(pinfo.PropertyName, NicePrint.minimalStringOfType cenv.denv ty1, NicePrint.minimalStringOfType cenv.denv ty2), m))
hashOfImmediateProps[nm] <- pinfo :: others
diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt
index 92e7cda05de..23ebc9e4c7c 100644
--- a/src/Compiler/FSComp.txt
+++ b/src/Compiler/FSComp.txt
@@ -1588,6 +1588,7 @@ featureChkNotTailRecursive,"Raises warnings if a member or function has the 'Tai
featureWhileBang,"'while!' expression"
featureExtendedFixedBindings,"extended fixed bindings for byref and GetPinnableReference"
featurePreferStringGetPinnableReference,"prefer String.GetPinnableReference in fixed bindings"
+featureWarningIndexedPropertiesGetSetSameType,"Indexed properties getter and setter must have the same type"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3355,tcNotAnIndexerNamedIndexingNotYetEnabled,"The value '%s' is not a function and does not support index notation."
@@ -1724,6 +1725,7 @@ featureUnmanagedConstraintCsharpInterop,"Interop between C#'s and F#'s unmanaged
3578,chkCopyUpdateSyntaxInAnonRecords,"This expression is an anonymous record, use {{|...|}} instead of {{...}}."
3579,alwaysUseTypedStringInterpolation,"Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended."
3580,tcUnexpectedFunTypeInUnionCaseField,"Unexpected function type in union case field definition. If you intend the field to be a function, consider wrapping the function signature with parens, e.g. | Case of a -> b into | Case of (a -> b)."
+3581,chkIndexedGetterAndSetterHaveSamePropertyType,"An indexed property's getter and setter must have the same type. Property '%s' has getter of type '%s' but setter of type '%s'."
3582,tcInfoIfFunctionShadowsUnionCase,"This is a function definition that shadows a union case. If this is what you want, ignore or suppress this warning. If you want it to be a union case deconstruction, add parentheses."
3583,unnecessaryParentheses,"Parentheses can be removed."
3584,tcDotLambdaAtNotSupportedExpression,"Shorthand lambda syntax is only supported for atomic expressions, such as method, property, field or indexer on the implied '_' argument. For example: 'let f = _.Length'."
diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs
index 0cc5370d570..b17f1671200 100644
--- a/src/Compiler/Facilities/LanguageFeatures.fs
+++ b/src/Compiler/Facilities/LanguageFeatures.fs
@@ -79,6 +79,7 @@ type LanguageFeature =
| WhileBang
| ExtendedFixedBindings
| PreferStringGetPinnableReference
+ | WarningIndexedPropertiesGetSetSameType
/// LanguageVersion management
type LanguageVersion(versionText) =
@@ -185,6 +186,7 @@ type LanguageVersion(versionText) =
// F# preview
LanguageFeature.FromEndSlicing, previewVersion
LanguageFeature.UnmanagedConstraintCsharpInterop, previewVersion
+ LanguageFeature.WarningIndexedPropertiesGetSetSameType, previewVersion
]
static let defaultLanguageVersion = LanguageVersion("default")
@@ -321,6 +323,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.WhileBang -> FSComp.SR.featureWhileBang ()
| LanguageFeature.ExtendedFixedBindings -> FSComp.SR.featureExtendedFixedBindings ()
| LanguageFeature.PreferStringGetPinnableReference -> FSComp.SR.featurePreferStringGetPinnableReference ()
+ | LanguageFeature.WarningIndexedPropertiesGetSetSameType -> FSComp.SR.featureWarningIndexedPropertiesGetSetSameType ()
/// Get a version string associated with the given feature.
static member GetFeatureVersionString feature =
diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi
index c1cb2378d4e..e3d7e7232bc 100644
--- a/src/Compiler/Facilities/LanguageFeatures.fsi
+++ b/src/Compiler/Facilities/LanguageFeatures.fsi
@@ -69,6 +69,7 @@ type LanguageFeature =
| WhileBang
| ExtendedFixedBindings
| PreferStringGetPinnableReference
+ | WarningIndexedPropertiesGetSetSameType
/// LanguageVersion management
type LanguageVersion =
diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf
index 0de0dda3fcb..f101b4c9151 100644
--- a/src/Compiler/xlf/FSComp.txt.cs.xlf
+++ b/src/Compiler/xlf/FSComp.txt.cs.xlf
@@ -82,6 +82,11 @@
Pokud typ používá atributy [<Sealed>] i [<AbstractClass>], znamená to, že je statický. Implementace rozhraní není povolena.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ Použití := z knihovny F# je zastaralé. Více informací: https://aka.ms/fsharp-refcell-ops. Změňte prosím například cell := expr na cell.Value <- expr.
@@ -482,6 +487,11 @@
Interoperabilita mezi neřízeným obecným omezením jazyka C# a F# (emitovat další modreq)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Vyvolá upozornění, když výraz záznamu kopírování a aktualizace změní všechna pole záznamu.
diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf
index ace9ad92933..3697859d684 100644
--- a/src/Compiler/xlf/FSComp.txt.de.xlf
+++ b/src/Compiler/xlf/FSComp.txt.de.xlf
@@ -82,6 +82,11 @@
Wenn ein Typ sowohl das Attribute [<Sealed>] wie auch [<AbstractClass>] verwendet, bedeutet dies, dass er statisch ist. Das Implementieren von Schnittstellen ist nicht zulässig.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ Die Verwendung von ":=" aus der F#-Bibliothek ist veraltet. Siehe https://aka.ms/fsharp-refcell-ops. Ändern Sie z. B. "cell := expr" in "cell.Value <- expr".
@@ -482,6 +487,11 @@
Interop zwischen nicht verwalteter generischer Einschränkung in C# und F# (zusätzlicher ModReq ausgeben)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Löst Warnungen aus, wenn ein Ausdruck zum Kopieren und Aktualisieren von Datensätzen alle Felder eines Datensatzes ändert.
diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf
index 286598c9988..0d6054100c1 100644
--- a/src/Compiler/xlf/FSComp.txt.es.xlf
+++ b/src/Compiler/xlf/FSComp.txt.es.xlf
@@ -82,6 +82,11 @@
Si un tipo utiliza ambos atributos [<Sealed>] y [<AbstractClass>], significa que es estático. No se permite implementar interfaces.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ El uso de ":=" de la biblioteca de F# está en desuso. Vea https://aka.ms/fsharp-refcell-ops. Por ejemplo, cambie "cell := expr" a "cell.Value <- expr".
@@ -482,6 +487,11 @@
Interoperabilidad entre la restricción genérica no administrada de C# y F# (emitir modreq adicional)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Emite advertencias cuando una expresión de copiar y actualizar registros cambia todos los campos de un registro.
diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf
index e3f9f534475..14306dddc9e 100644
--- a/src/Compiler/xlf/FSComp.txt.fr.xlf
+++ b/src/Compiler/xlf/FSComp.txt.fr.xlf
@@ -82,6 +82,11 @@
Si un type utilise à la fois les attributs [<Sealed>] et [<AbstractClass>], cela signifie qu'il est statique. L'implémentation d'interfaces n'est pas autorisée.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ L’utilisation de « := » à partir de la bibliothèque F# est déconseillée. Voir https://aka.ms/fsharp-refcell-ops. Par exemple, veuillez remplacer « cell := expr » par « cell.Value <- expr ».
@@ -482,6 +487,11 @@
Interopérabilité entre les contraintes génériques non gérées de C# et F# (émettre un modreq supplémentaire)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Génère des avertissements lorsqu'une expression d'enregistrement de copie et de mise à jour modifie tous les champs d'un enregistrement.
diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf
index fefdc56090c..cab10c51095 100644
--- a/src/Compiler/xlf/FSComp.txt.it.xlf
+++ b/src/Compiler/xlf/FSComp.txt.it.xlf
@@ -82,6 +82,11 @@
Se un tipo usa entrambi gli attributi [<Sealed>] e [<AbstractClass>], significa che è statico. Non è consentita l'implementazione di interfacce.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ L'uso di ':=' dalla libreria F # è deprecato. Vedere https://aka.ms/fsharp-refcell-ops. Ad esempio, modificare 'cell:= expr' in 'cell.Value <- expr'.
@@ -482,6 +487,11 @@
Interoperabilità tra il vincolo generico non gestito di C# e di F# (crea un modreq aggiuntivo)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Genera avvisi quando un'espressione di record di copia e aggiornamento modifica tutti i campi di un record.
diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf
index 547baf049f7..8aab74f4e4f 100644
--- a/src/Compiler/xlf/FSComp.txt.ja.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ja.xlf
@@ -82,6 +82,11 @@
型が [<Sealed>] と [<AbstractClass>] の両方の属性を使用する場合、それは静的であることを意味します。インターフェイスの実装は許可されません。
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ F# ライブラリからの ':=' の使用は非推奨です。https://aka.ms/fsharp-refcell-ops を参照してください。たとえば、'cell : = expr' を 'cell.Value <- expr' に変更してください。
@@ -482,6 +487,11 @@
C# と F# のアンマネージド ジェネリック制約の間の相互運用 (追加の modreq を出力)
+
+
+ Indexed properties getter and setter must have the same type
+
+ copy-and-update レコード式によってレコードのすべてのフィールドが変更されたときに警告を表示します。
diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf
index 51ed5cd562a..9b3582eb4f8 100644
--- a/src/Compiler/xlf/FSComp.txt.ko.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ko.xlf
@@ -82,6 +82,11 @@
형식이 [<Sealed>] 및 [<AbstractClass>] 특성을 모두 사용하는 경우 정적임을 의미합니다. 인터페이스 구현은 허용되지 않습니다.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ F# 라이브러리의 ':=' 사용은 더 이상 사용되지 않습니다. https://aka.ms/fsharp-refcell-ops를 참조하세요. 예를 들어 'cell := expr'을 'cell.Value <- expr'로 변경하세요.
@@ -482,6 +487,11 @@
C#과 F#의 관리되지 않는 제네릭 제약 조건 간의 Interop(추가 modreq 내보내기)
+
+
+ Indexed properties getter and setter must have the same type
+
+ 레코드 복사 및 업데이트 식이 레코드의 모든 필드를 변경할 때 경고를 발생합니다.
diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf
index 4fe31c3a96b..89867c0f85d 100644
--- a/src/Compiler/xlf/FSComp.txt.pl.xlf
+++ b/src/Compiler/xlf/FSComp.txt.pl.xlf
@@ -82,6 +82,11 @@
Jeśli typ używa obu atrybutów [<Sealed>] i [< AbstractClass>], oznacza to, że jest on statyczny. Wdrażanie interfejsów jest niedozwolone.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ Użycie elementu „:=” z biblioteki języka F# jest przestarzałe. Sprawdź stronę https://aka.ms/fsharp-refcell-ops. Na przykład zmień wyrażenie „cell := expr” na „cell.Value <- expr”.
@@ -482,6 +487,11 @@
Międzyoperacyjnie między niezarządzanym ograniczeniem ogólnym języka C# i F# (emituj dodatkowe modreq)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Zgłasza ostrzeżenia, gdy wyrażenie rekordu kopiowania i aktualizacji zmieni wszystkie pola rekordu.
diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf
index b80b7cb1665..cff08b64683 100644
--- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf
+++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf
@@ -82,6 +82,11 @@
Se um tipo usar os atributos [<Sealed>] e [<AbstractClass>], isso significará que ele é estático. A implementação de interfaces não é permitida.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ O uso de ':=' da biblioteca F# foi preterido. Consulte https://aka.ms/fsharp-refcell-ops. Por exemplo, altere 'cell := expr' para 'cell.Value <- expr'.
@@ -482,6 +487,11 @@
Interoperabilidade entre a restrição genérica não gerenciada de C# e F# (emitir modreq adicional)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Gera avisos quando uma expressão de registro de cópia e atualização altera todos os campos de um registro.
diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf
index a70e6137577..3349417fdf5 100644
--- a/src/Compiler/xlf/FSComp.txt.ru.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ru.xlf
@@ -82,6 +82,11 @@
Если тип использует оба атрибута [<Sealed>] и [<AbstractClass>], это означает, что он статический. Реализация интерфейсов не допускается.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ Использование ":=" из библиотеки F# является нерекомендуемым. См. https://aka.ms/fsharp-refcell-ops. Например, замените "cell := expr" на "cell.Value <- expr".
@@ -482,6 +487,11 @@
Взаимодействие между универсальным ограничением "unmanaged" C# и F#(создание дополнительного modreq)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Создает предупреждения, когда выражение копирования и обновления записи изменяет все поля записи.
diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf
index b5588a963ff..53aa7e0df1b 100644
--- a/src/Compiler/xlf/FSComp.txt.tr.xlf
+++ b/src/Compiler/xlf/FSComp.txt.tr.xlf
@@ -82,6 +82,11 @@
Bir tür, hem [<Sealed>] hem de [< AbstractClass>] özniteliklerini kullanıyorsa bu statik olduğu anlamına gelir. Arabirim uygulamaya izin verilmez.
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ F# kitaplığından gelen ':=' kullanımı kullanım dışı. https://aka.ms/fsharp-refcell-ops’a bakın. Örneğin, lütfen 'cell := expr' ifadesini 'cell.Value <- expr' olarak değiştirin.
@@ -482,6 +487,11 @@
C# ile F#' arasında yönetilmeyen genel kısıtlama (ek modreq yayın)
+
+
+ Indexed properties getter and setter must have the same type
+
+ Bir kopyalama ve güncelleştirme kayıt ifadesi bir kaydın tüm alanlarını değiştirdiğinde uyarı oluşturur.
diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
index 804aefd5e43..097bc9c2e0b 100644
--- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
+++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
@@ -82,6 +82,11 @@
如果类型同时使用 [<Sealed>] 和 [<AbstractClass>] 属性,则表示它是静态的。不允许实现接口。
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ 已弃用 F# 库中的“:=”。请参阅 https://aka.ms/fsharp-refcell-ops。 例如,请将“cell := expr”更改为“cell.Value <- expr”。
@@ -482,6 +487,11 @@
C# 和 F# 的非托管泛型约束之间的互操作(发出额外的 modreq)
+
+
+ Indexed properties getter and setter must have the same type
+
+ 复制和更新记录表达式更改记录的所有字段时引发警告。
diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
index 3e5f30fb7a6..f9e2e228c79 100644
--- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
+++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
@@ -82,6 +82,11 @@
如果類型同時使用 [<Sealed>] 和 [<AbstractClass>] 屬性,表示其為靜態。不允許實作介面。
+
+
+ An indexed property's getter and setter must have the same type. Property '{0}' has getter of type '{1}' but setter of type '{2}'.
+
+ 透過 F# 程式庫使用 ':=' 的方式已淘汰。請參閱 https://aka.ms/fsharp-refcell-ops。舉例來說,請將 'cell := expr' 變更為 'cell.Value <- expr'。
@@ -482,6 +487,11 @@
C# 與 F# 的非受控泛型條件約束之間的 Interop (發出額外的 modreq)
+
+
+ Indexed properties getter and setter must have the same type
+
+ 當複製和更新記錄運算式變更記錄的所有欄位時引發警告。
diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/IndexedPropertiesSameType.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/IndexedPropertiesSameType.fs
new file mode 100644
index 00000000000..7869e2b4218
--- /dev/null
+++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/IndexedPropertiesSameType.fs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
+
+type MyIndexerClass() =
+ member x.Indexer1
+ with get (index: int): string = ""
+ and set (index: int) (value: float) = ()
+
+ member x.Indexer2
+ with get (index) = 1
+ and set (index) (value: float) = ()
+
+ member x.Indexer3
+ with get index = 1
+ member x.Indexer3
+ with set index (value: float) = ()
+
+ member x.Indexer4
+ with get (index: int, index2: int): float = 0.0
+ and set (index1: int, index2: int) (value: string) = ()
+
+ member x.Indexer5
+ with get (index, index2) = 0.0
+ and set (index1, index2) value = ()
+
+type GenericIndexer<'indexerArgs,'indexerOutput,'indexerInput>() =
+ let mutable m_lastArgs = Unchecked.defaultof<'indexerArgs>
+ let mutable m_lastInput = Unchecked.defaultof<'indexerInput>
+
+ member this.LastArgs = m_lastArgs
+ member this.LastInput = m_lastInput
+
+ member this.Item with get (args : 'indexerArgs) =
+ m_lastArgs <- args;
+ Unchecked.defaultof<'indexerOutput>
+ and set (args : 'indexerArgs) (input : 'indexerInput) =
+ m_lastArgs <- args
+ m_lastInput <- input
\ No newline at end of file
diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/MethodsAndProperties.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/MethodsAndProperties.fs
index 47b05507538..d4e8d302dd9 100644
--- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/MethodsAndProperties.fs
+++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/MethodsAndProperties.fs
@@ -26,7 +26,7 @@ module MemberDefinitions_MethodsAndProperties =
compilation
|> verifyCompileAndRun
|> shouldSucceed
-
+
// SOURCE=E_AbstractAndConcereteProp.fs SCFLAGS="--test:ErrorRanges" # E_AbstractAndConcereteProp.fs
[]
let ``E_AbstractAndConcereteProp_fs`` compilation =
@@ -573,4 +573,98 @@ type I =
(Error 3550, Line 7, Col 5, Line 7, Col 54, "Duplicate parameter. The parameter 'i' has been used more that once in this method.")
(Error 3550, Line 7, Col 5, Line 7, Col 54, "Duplicate parameter. The parameter 'j' has been used more that once in this method.")
]
-
+
+ []
+ let ``IndexedPropertiesSameType_fs`` compilation =
+ compilation
+ |> withLangVersion70
+ |> verifyCompileAndRun
+ |> shouldSucceed
+
+ []
+ let ``Indexed1PropertiesSameType preview``() =
+ Fsx """
+type MyIndexerClass() =
+ member x.Indexer1
+ with get (index: int): string = ""
+ and set (index: int) (value: float) = ()
+"""
+ |> withLangVersionPreview
+ |> typecheck
+ |> shouldFail
+ |> withSingleDiagnostic (Warning 3581, Line 4, Col 14, Line 4, Col 17, "An indexed property's getter and setter must have the same type. Property 'Indexer1' has getter of type 'string' but setter of type 'float'.")
+
+ []
+ let ``Indexed2PropertiesSameType_fs preview``() =
+ Fsx """
+type MyIndexerClass() =
+ member x.Indexer2
+ with get (index) = 1
+ and set (index) (value: float) = ()
+"""
+ |> withLangVersionPreview
+ |> typecheck
+ |> shouldFail
+ |> withSingleDiagnostic (Warning 3581, Line 4, Col 14, Line 4, Col 17, "An indexed property's getter and setter must have the same type. Property 'Indexer2' has getter of type 'int' but setter of type 'float'.")
+
+ []
+ let ``Indexed3PropertiesSameType_fs preview``() =
+ Fsx """
+type MyIndexerClass() =
+ member x.Indexer3
+ with get index = 1
+ member x.Indexer3
+ with set index (value: float) = ()
+"""
+ |> withLangVersionPreview
+ |> 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 'Indexer3' has getter of type 'int' but setter of type 'float'.")
+
+ []
+ let ``Indexed4PropertiesSameType_fs preview``() =
+ Fsx """
+type MyIndexerClass() =
+ member x.Indexer4
+ with get (index: int, index2: int): float = 0.0
+ and set (index1: int, index2: int) (value: string) = ()
+"""
+ |> withLangVersionPreview
+ |> typecheck
+ |> shouldFail
+ |> withSingleDiagnostic (Warning 3581, Line 4, Col 14, Line 4, Col 17, "An indexed property's getter and setter must have the same type. Property 'Indexer4' has getter of type 'float' but setter of type 'string'.")
+
+ []
+ let ``Indexed5PropertiesSameType_fs preview``() =
+ Fsx """
+type MyIndexerClass() =
+ member x.Indexer5
+ with get (index, index2) = 0.0
+ and set (index1, index2) value = ()
+"""
+ |> withLangVersionPreview
+ |> typecheck
+ |> shouldFail
+ |> withSingleDiagnostic (Warning 3581, Line 4, Col 14, Line 4, Col 17, "An indexed property's getter and setter must have the same type. Property 'Indexer5' has getter of type 'float' but setter of type 'obj'.")
+
+ []
+ let ``GenericIndexerPropertiesSameType_fs preview``() =
+ Fsx """
+type GenericIndexer<'indexerArgs,'indexerOutput,'indexerInput>() =
+ let mutable m_lastArgs = Unchecked.defaultof<'indexerArgs>
+ let mutable m_lastInput = Unchecked.defaultof<'indexerInput>
+
+ member this.LastArgs = m_lastArgs
+ member this.LastInput = m_lastInput
+
+ member this.Item with get (args : 'indexerArgs) =
+ m_lastArgs <- args;
+ Unchecked.defaultof<'indexerOutput>
+ and set (args : 'indexerArgs) (input : 'indexerInput) =
+ m_lastArgs <- args
+ m_lastInput <- input
+"""
+ |> withLangVersionPreview
+ |> typecheck
+ |> shouldFail
+ |> withSingleDiagnostic (Warning 3581, Line 9, Col 27, Line 9, Col 30, "An indexed property's getter and setter must have the same type. Property 'Item' has getter of type ''indexerOutput' but setter of type ''indexerInput'.")
\ No newline at end of file