Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch type comparison in BaseFn to use is_types_compatible #3461

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading