Skip to content

Commit

Permalink
Switch type comparison in BaseFn to use is_types_compatible (#3461)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Jul 4, 2024
1 parent 37c53dd commit 07705c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cfnlint/rules/functions/_BaseFn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import namedtuple
from typing import Any, Tuple

from cfnlint.helpers import ToPy, ensure_list
from cfnlint.helpers import ToPy, ensure_list, is_types_compatible
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
from cfnlint.rules import CloudFormationLintRule

Expand Down Expand Up @@ -118,7 +118,7 @@ def validate_fn_output_types(
) -> ValidationResult:
tS = self.resolve_type(validator, s)
if tS:
if not any(t in self.types for t in tS):
if not is_types_compatible(self.types, tS):
reprs = ", ".join(repr(type) for type in tS)
yield ValidationError(f"{instance!r} is not of type {reprs}")

Expand Down
7 changes: 7 additions & 0 deletions test/unit/rules/functions/test_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ def context(cfn):
{"transforms": Transforms(["AWS::LanguageExtensions"])},
[],
),
(
"Fn::Length output while a number can be a string",
{"Fn::Length": []},
{"type": "string"},
{"transforms": Transforms(["AWS::LanguageExtensions"])},
[],
),
],
)
def test_validate(name, instance, schema, context_evolve, expected, rule, context, cfn):
Expand Down

0 comments on commit 07705c0

Please sign in to comment.