Skip to content

Fix Incorrect cycle error#2170

Merged
amitu merged 3 commits intomainfrom
fix/auto-var-to-list
Jul 8, 2025
Merged

Fix Incorrect cycle error#2170
amitu merged 3 commits intomainfrom
fix/auto-var-to-list

Conversation

@siddhantk232
Copy link
Copy Markdown
Contributor

This fixes #2169

Avoids infinite loop for the following code snippet:

-- test:
a: Hello

-- component test:
string a:

-- ftd.text: Test
classes: $test.a

-- end: test

classes of ftd.text component takes a list of string but ftd has a feature that turns T -> List<T> if expected kind is List<T> and found kind is T.

This works for single literals, like:

-- ftd.text: something
classes: one

The string literal one is converted to List<String> because classes expects that.

This, for some reason, does not work when we use a variable reference instead of literals. This change fixes this case.

NOTE: This change does not support mixing of two styles, you can't do:

-- test:
a: two

-- component test:
string a:

-- ftd.text: Test
classes: one, $test.a ;; SEE THIS!

-- end: test

This still results in a Cycle Detection error:

failed to parse FoundCycle { message: \"test#test:4 => test#test:4 => test#test:4\", line_number: 4 }

Simply removing this match branch and failing with a "expected_kind and found_kind mismatch" error is not an option here as it'll break so many existing packages in the world.

Avoids infinite loop for the following code snippet:

```ftd
-- test:
a: Hello

-- component test:
string a:

-- ftd.text: Test
classes: $test.a

-- end: test
```

`classes` of `ftd.text` component takes a list of string but ftd has a
feature that turns T -> List<T> if expected kind is List<T> and found
kind is T.

This works for single literals, like:

```
-- ftd.text: something
classes: one
```

The string literal `one` is converted to List<String> because `classes`
expects that.

This, for some reason, does not work when we use a variable reference
instead of literals. This changes fixes this case.

NOTE: This change does not support mixing of two styles, you can't do:

```ftd
-- test:
a: two

-- component test:
string a:

-- ftd.text: Test
classes: one, $test.a ;; SEE THIS!

-- end: test
```

This still results in a Cycle Detection error:

```
failed to parse FoundCycle { message: \"test#test:4 => test#test:4 => test#test:4\", line_number: 4 }
```

Simply removing this match branch and failing with a "expected_kind and
found_kind mismatch" error is not an option here as it'll break so many
existing packages in the world.
@siddhantk232 siddhantk232 requested review from amitu and Copilot July 8, 2025 07:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an infinite loop when wrapping a variable reference into a list for a property that expects List<T> by returning a single-element list containing the reference instead of an empty value.

  • Converts a reference to a List<T> when expected_kind is a list and found_kind matches the inner type.
  • Uses get_reference_name and get_kind to construct the wrapped list value.
  • Maintains existing behavior for literals and avoids breaking other use cases.

@amitu amitu merged commit 6da44f8 into main Jul 8, 2025
1 check passed
@amitu amitu deleted the fix/auto-var-to-list branch July 8, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

FoundCycle error for code that does not have any cycles

3 participants