Skip to content

Commit 4478f9e

Browse files
Copilotandrewbranch
andcommitted
Implement iterator parameter validation
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
1 parent a31c03a commit 4478f9e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

internal/checker/checker.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6065,10 +6065,18 @@ func (c *Checker) getIterationTypesOfIterableSlow(t *Type, r *IterationTypesReso
60656065
if IsTypeAny(methodType) {
60666066
return IterationTypes{c.anyType, c.anyType, c.anyType}
60676067
}
6068-
if signatures := c.getSignaturesOfType(methodType, SignatureKindCall); len(signatures) != 0 {
6069-
iteratorType := c.getIntersectionType(core.Map(signatures, c.getReturnTypeOfSignature))
6070-
return c.getIterationTypesOfIteratorWorker(iteratorType, r, errorNode, diagnosticOutput)
6068+
allSignatures := c.getSignaturesOfType(methodType, SignatureKindCall)
6069+
validSignatures := core.Filter(allSignatures, func(sig *Signature) bool {
6070+
return c.getMinArgumentCount(sig) == 0
6071+
})
6072+
if len(validSignatures) == 0 {
6073+
if errorNode != nil && len(allSignatures) > 0 {
6074+
c.checkTypeAssignableToEx(t, r.getGlobalIterableType(), errorNode, nil /*headMessage*/, diagnosticOutput)
6075+
}
6076+
return IterationTypes{}
60716077
}
6078+
iteratorType := c.getIntersectionType(core.Map(validSignatures, c.getReturnTypeOfSignature))
6079+
return c.getIterationTypesOfIteratorWorker(iteratorType, r, errorNode, diagnosticOutput)
60726080
}
60736081
return IterationTypes{}
60746082
}

0 commit comments

Comments
 (0)