Skip to content

Commit 80c3d34

Browse files
authored
Compiler error for signature/implementation files when declaring multiple parameters with the same name in abstract methods (#14084)
1 parent 5f54b69 commit 80c3d34

File tree

16 files changed

+254
-4
lines changed

16 files changed

+254
-4
lines changed

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,22 @@ let CheckDuplicates (idf: _ -> Ident) k elems =
395395
errorR (Duplicate(k, id1.idText, id1.idRange))))
396396
elems
397397

398-
398+
let private CheckDuplicatesArgNames (synVal: SynValSig) m =
399+
let argNames = synVal.SynInfo.ArgNames |> List.duplicates
400+
for name in argNames do
401+
errorR(Error((FSComp.SR.chkDuplicatedMethodParameter(name), m)))
402+
403+
let private CheckDuplicatesAbstractMethodParmsSig (typeSpecs: SynTypeDefnSig list) =
404+
for SynTypeDefnSig(typeRepr= trepr) in typeSpecs do
405+
match trepr with
406+
| SynTypeDefnSigRepr.ObjectModel(_, synMemberSigs, _) ->
407+
for sms in synMemberSigs do
408+
match sms with
409+
| SynMemberSig.Member(synValSig, _, m) ->
410+
CheckDuplicatesArgNames synValSig m
411+
| _ -> ()
412+
| _ -> ()
413+
399414
module TcRecdUnionAndEnumDeclarations =
400415

401416
let CombineReprAccess parent vis =
@@ -3946,6 +3961,14 @@ module TcDeclarations =
39463961
| SynMemberDefn.NestedType (range=m) :: _ -> errorR(Error(FSComp.SR.tcTypesCannotContainNestedTypes(), m))
39473962
| _ -> ()
39483963
| ds ->
3964+
// Check for duplicated parameters in abstract methods
3965+
for slot in ds do
3966+
if isAbstractSlot slot then
3967+
match slot with
3968+
| SynMemberDefn.AbstractSlot (synVal, _, m) ->
3969+
CheckDuplicatesArgNames synVal m
3970+
| _ -> ()
3971+
39493972
// Classic class construction
39503973
let _, ds = List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isInherit;isField;isTycon]) ds
39513974
match ds with
@@ -4351,7 +4374,8 @@ let rec TcSignatureElementNonMutRec (cenv: cenv) parent typeNames endm (env: TcE
43514374
let _, _, _, env = TcExceptionDeclarations.TcExnSignature cenv env parent emptyUnscopedTyparEnv (edef, scopem)
43524375
return env
43534376

4354-
| SynModuleSigDecl.Types (typeSpecs, m) ->
4377+
| SynModuleSigDecl.Types (typeSpecs, m) ->
4378+
CheckDuplicatesAbstractMethodParmsSig typeSpecs
43554379
let scopem = unionRanges m endm
43564380
let mutRecDefns = typeSpecs |> List.map MutRecShape.Tycon
43574381
let env = TcDeclarations.TcMutRecSignatureDecls cenv env parent typeNames emptyUnscopedTyparEnv m scopem None mutRecDefns
@@ -4521,7 +4545,8 @@ and TcSignatureElementsMutRec cenv parent typeNames m mutRecNSInfo envInitial (d
45214545
let rec loop isNamespace moduleRange defs: MutRecSigsInitialData =
45224546
((true, true), defs) ||> List.collectFold (fun (openOk, moduleAbbrevOk) def ->
45234547
match def with
4524-
| SynModuleSigDecl.Types (typeSpecs, _) ->
4548+
| SynModuleSigDecl.Types (typeSpecs, _) ->
4549+
CheckDuplicatesAbstractMethodParmsSig typeSpecs
45254550
let decls = typeSpecs |> List.map MutRecShape.Tycon
45264551
decls, (false, false)
45274552

src/Compiler/FSComp.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,4 +1656,5 @@ reprStateMachineInvalidForm,"The state machine has an unexpected form"
16561656
3546,parsExpectingPatternInTuple,"Expecting pattern"
16571657
3547,parsExpectedPatternAfterToken,"Expected a pattern after this point"
16581658
3548,matchNotAllowedForUnionCaseWithNoData,"Pattern discard is not allowed for union case that takes no data."
1659-
3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration"
1659+
3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration"
1660+
3550,chkDuplicatedMethodParameter,"Duplicate parameter. The parameter '%s' has been used more that once in this method."

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">Soubor {0} má nerozpoznanou příponu. Zdrojové soubory musí mít příponu .fs, .fsi, .fsx nebo .fsscript.</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">Funkce {0} není v jazyce F# {1} dostupná. Použijte prosím jazyk verze {2} nebo vyšší.</target>

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">Die Dateierweiterung von „{0}“ wurde nicht erkannt. Quelldateien müssen die Erweiterung .fs, .fsi, .fsx oder .fsscript haben</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">Das Feature "{0}" ist in F# {1} nicht verfügbar. Verwenden Sie Sprachversion {2} oder höher.</target>

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">No se reconoce la extensión de archivo de '{0}'. Los archivos de código fuente deben tener las extensiones .fs, .fsi, .fsx o .fsscript</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">La característica "{0}" no está disponible en F# {1}. Use la versión {2} del lenguaje o una posterior.</target>

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">L'extension de fichier de '{0}' n'est pas reconnue. Les fichiers sources doivent avoir l'extension .fs, .fsi, .fsx, ou .fsscript.</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">La fonctionnalité '{0}' n'est pas disponible en F# {1}. Utilisez la version de langage {2} ou une version ultérieure.</target>

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">Estensione di file di '{0}' non riconosciuta. I file di origine devono avere estensione .fs, .fsi, .fsx or .fsscript</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">La funzionalità '{0}' non è disponibile in F# {1}. Usare la versione {2} o versioni successive del linguaggio.</target>

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">'{0}' のファイル拡張子は認識されません。ソース ファイルの拡張子は .fs、.fsi、.fsx、または .fsscript にする必要があります。</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">機能 '{0}' は F# {1} では使用できません。{2} 以上の言語バージョンをお使いください。</target>

src/Compiler/xlf/FSComp.txt.ko.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">'{0}'의 파일 확장명을 인식할 수 없습니다. 원본 파일의 확장명은 .fs, .fsi, .fsx 또는 .fsscript여야 합니다.</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">'{0}' 기능은 F# {1}에서 사용할 수 없습니다. {2} 이상의 언어 버전을 사용하세요.</target>

src/Compiler/xlf/FSComp.txt.pl.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<target state="translated">Rozszerzenie pliku "{0}" nie zostało rozpoznane. Pliki źródłowe muszą mieć rozszerzenie .fs, .fsi, .fsx lub .fsscript</target>
1313
<note />
1414
</trans-unit>
15+
<trans-unit id="chkDuplicatedMethodParameter">
16+
<source>Duplicate parameter. The parameter '{0}' has been used more that once in this method.</source>
17+
<target state="new">Duplicate parameter. The parameter '{0}' has been used more that once in this method.</target>
18+
<note />
19+
</trans-unit>
1520
<trans-unit id="chkFeatureNotLanguageSupported">
1621
<source>Feature '{0}' is not available in F# {1}. Please use language version {2} or greater.</source>
1722
<target state="translated">Funkcja „{0}” nie jest dostępna w języku F# {1}. Użyj języka w wersji {2} lub nowszej.</target>

0 commit comments

Comments
 (0)