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

Fix TypeAlias.isRecursive algorithm #87

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

bioball
Copy link
Contributor

@bioball bioball commented Feb 11, 2025

This fixes an issue where a typealias might incorrectly be marked as recurisve.

This fixes an issue where a typealias might incorrectly be
marked as recurisve.
return true
}
seen.add(this)
return body.isRecursive(seen, context).also { seen.remove(this) }
Copy link
Contributor

Choose a reason for hiding this comment

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

That's why mutability is evil :)
Your solution works, but I think using a immutable set is more elegant, and the recursion will never be so deep that performance will matter.

private fun PklTypeAlias.isRecursive(
  seen: Set<PklTypeAlias>,
  context: PklProject?
): Boolean = seen.contains(this) || body.isRecursive(seen + this, context)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered doing this too. Yeah; I'm fine with either approach, and this is a cached operation anyway.

@bioball bioball merged commit af838b8 into apple:main Feb 12, 2025
3 checks passed
@bioball bioball deleted the fix-recursive-typealias branch February 12, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants