From a4db0dd21949328ea499c84be077961e735a8bca Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 14 Sep 2022 05:51:28 +1300 Subject: [PATCH] add a guard that checks if the lenght of fittedArgs is accesible by index --- src/Compiler/Checking/CheckExpressions.fs | 5 +++-- .../Conformance/UnionTypes/E_UnionConstructorBadFieldName.fs | 4 +++- .../Conformance/UnionTypes/UnionTypes.fs | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 537887747d6..a3e8421274f 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -8258,8 +8258,9 @@ and TcUnionCaseOrExnCaseOrActivePatternResultItemThen (cenv: cenv) overallTy env // first: put all positional arguments let mutable currentIndex = 0 for arg in unnamedArgs do - fittedArgs[currentIndex] <- arg - currentIndex <- currentIndex + 1 + if currentIndex < fittedArgs.Length then + fittedArgs[currentIndex] <- arg + currentIndex <- currentIndex + 1 let SEEN_NAMED_ARGUMENT = -1 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_UnionConstructorBadFieldName.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_UnionConstructorBadFieldName.fs index f9ebb74b26f..01a238ecd76 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_UnionConstructorBadFieldName.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_UnionConstructorBadFieldName.fs @@ -14,4 +14,6 @@ match y with | Case1(V3 = "") -> () | _ -> () -let (Case1(V4 = z)) = y \ No newline at end of file +let (Case1(V4 = z)) = y + +let z a = Some ("", "", a = "") \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs index b4c14f7b201..bd0382befeb 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs @@ -261,6 +261,7 @@ module UnionTypes = (Error 3174, Line 14, Col 9, Line 14, Col 11, "The union case 'Case1' does not have a field named 'V3'.") (Warning 26, Line 15, Col 3, Line 15, Col 10, "This rule will never be matched") (Error 3174, Line 17, Col 12, Line 17, Col 14, "The union case 'Case1' does not have a field named 'V4'.") + (Error 3174, Line 19, Col 25, Line 19, Col 26, "The union case 'Some' does not have a field named 'a'.") ] //SOURCE=E_UnionFieldConflictingName.fs SCFLAGS="--test:ErrorRanges" # E_UnionFieldConflictingName.fs