Skip to content

fix: use bare return instead of return undef in list-context methods#255

Draft
toddr-bot wants to merge 2 commits intomainfrom
koan.toddr.bot/fix-return-undef-list-context
Draft

fix: use bare return instead of return undef in list-context methods#255
toddr-bot wants to merge 2 commits intomainfrom
koan.toddr.bot/fix-return-undef-list-context

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

@toddr-bot toddr-bot commented Apr 11, 2026

What

Replace return undef with bare return in ContentModel::children() and expand_ns_prefix().

Why

return undef in list context produces (undef) — a one-element list — not an empty list. This means my @kids = $model->children on an EMPTY or ANY model gives a truthy result, silently breaking code that checks @kids for emptiness. This is Perl::Critic policy Subroutines::ProhibitExplicitReturnUndef.

How

Bare return gives () in list context and undef in scalar context — fixing the list-context bug while preserving scalar-context backward compatibility.

Testing

  • New t/return_undef_list_context.t (6 tests) — first commit demonstrates the bug (fails), second commit fixes it (passes).
  • Full test suite passes.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 65 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

toddr-bot and others added 2 commits April 11, 2026 10:57
ContentModel::children() uses "return undef" which returns (undef) in
list context instead of an empty list. This means @kids = $model->children
yields a one-element list for EMPTY/ANY models, causing silent bugs in
code that checks @kids for emptiness.

This test fails against the current code, proving the bug exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ContentModel::children() and expand_ns_prefix() used "return undef"
which produces (undef) — a one-element list — in list context. This is
a classic Perl footgun: code like "my @kids = $model->children" gets a
truthy list for EMPTY/ANY models that have no children.

Bare "return" correctly gives () in list context and undef in scalar
context, preserving backward compatibility for scalar callers while
fixing the list-context bug.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.73%. Comparing base (45216a7) to head (bffcd44).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #255   +/-   ##
=======================================
  Coverage   75.73%   75.73%           
=======================================
  Files           1        1           
  Lines        1092     1092           
  Branches      342      342           
=======================================
  Hits          827      827           
  Misses         59       59           
  Partials      206      206           
Flag Coverage Δ
perl 75.73% <ø> (ø)
xs 75.73% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant