# The following code is run with a custom module exporting these symbols:
#     role In { … }
#     role File { … }
#     role Directory { … }
#     class File::In does File does In { … }
#     class Directory::In does Directory does In { … }
# The purpose of &recurse is to run the given code block recursively for
# the given file/directory and all of its children, if any. The method
# ‘children’ comes from the Directory role.

multi sub recurse(File $node, Code $code) { $code($node) }
multi sub recurse(Directory $node, Code $code) {
	$code($node);
	samewith($_, $code) for $node.children;
}

# ↑ These definitions run perfectly fine by themselves.

recurse File::In.new(path => ‘root’.IO, :root), { say $^file.path };

# ↑ However, this line throws an error with the given definitions:
#     Circularity detected in multi sub types for &recurse
#
# If the signatures of &recurse are altered in the following manner:
#     File → File::In
#     Directory → Directory::In
# The line suddenly works. I do not see how checking for the role File,
# rather than for the class File::In (which does File), should prevent
# the code in question from functioning correctly. Much less where the
# circularity is coming from and what it means.