Skip to content

Count Form 4797 gains and losses on Massachusetts Schedule D - #9991

Merged
PavelMakarchuk merged 8 commits into
mainfrom
ma-form-4797-schedule-d
Oct 12, 2026
Merged

PavelMakarchuk merged 8 commits into
mainfrom
ma-form-4797-schedule-d

Conversation

@PavelMakarchuk

@PavelMakarchuk PavelMakarchuk commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #9990.

What changes

other_net_gain (Form 4797, line 18b, carried to Schedule 1, line 4) entered ma_gross_income only through irs_gross_income, so a gain stayed in Part B and a loss was dropped. Massachusetts reports Form 4797, Part II amounts on Schedule D, line 7.

  • New ma_long_term_capital_gains: the long-term amount on Massachusetts Schedule D, adding long_term_capital_gains, non_sch_d_capital_gains (line 6) and other_net_gain (line 7). ma_part_c_gross_income and ma_part_a_agi (the Schedule D, line 13 amount for Schedule B, line 25) read it instead of their own lists.
  • ma_part_b_gross_income also subtracts other_net_gain_gross_income, the positive Form 4797 amount that irs_gross_income adds.
  • A Form 4797 loss now reaches Schedule D: it offsets long-term gains, then short-term gains (Schedule B, line 25), then up to $2,000 of dividends (line 32).
  • From the Keep capital gains and losses out of Massachusetts Part B income #9954 review (non-blocking): part_a_and_c_income is now filer_dividends_and_gains, and the Part B and Part C variables cite the Schedule D instructions (page 27) in reference.

other_net_gain is one tax-unit amount, so gains and losses on business property held one year or less (Schedule B, lines 12 and 17) are also counted as Schedule D, line 7 amounts. The ma_long_term_capital_gains documentation says so. Separating them would need a new input.

Tests

New gross_income/ma_long_term_capital_gains.yaml: one case for the new variable and five 2023 returns, each computed line by line from the 2023 Form 1, Schedule B and Schedule D (single, wages 60,000):

Return Amount Main → PR Tax before credits: main → PR
Form 4797 gain 5,000 Part B / Part C gross 65,000 / 0 → 60,000 / 5,000 2,930 → 2,930
Form 4797 gain 5,000, short-term loss 2,000 Part C AGI 0 → 3,000 2,930 → 2,830
Form 4797 loss 3,000, long-term gain 5,000 Part C AGI 5,000 → 2,000 2,930 → 2,780
Form 4797 loss 1,000, short-term gain 3,000 Part A AGI 3,000 → 2,000 2,935 → 2,850
Form 4797 loss 3,000, dividends 1,000 Part A AGI 1,000 → 0 not asserted¹

¹ The form gives 2,680. This PR gives 2,730 until #9906 (#9905) taxes the dividends left after Schedule B, line 32.

The five returns fail on main. All 674 tests under gov/states/ma and 789 other tests with Massachusetts households or other_net_gain pass. With #9976, and separately with #9908, merged in (both change ma_gross_income), all 683 Massachusetts tests pass.

Overlap

🤖 Generated with Claude Code

PavelMakarchuk and others added 3 commits October 6, 2026 21:51
ma_part_b_gross_income subtracted Part A and Part C gross income from
ma_gross_income. Those net capital losses the Schedule B and D way, but
irs_gross_income adds each filer's net capital gain floored at zero, so
the difference stayed in Part B: a long-term loss against a short-term
gain reduced Part B, and one spouse's short-term loss against the other
spouse's long-term gain added phantom Part B income. Subtract the same
dividend and capital gain amounts irs_gross_income adds instead
(M.G.L. c. 62 s. 2(b), s. 2(d)(1)(M)).

Fixes #9953.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
non_sch_d_capital_gains (Form 1040 line 7 distributions without a
federal Schedule D) entered ma_gross_income through irs_gross_income but
neither Part A nor Part C, so it stayed in Part B. Massachusetts reports
them on Schedule D, line 6: add them to the long-term amount in
ma_part_c_gross_income and ma_part_a_agi, and take them out of
ma_part_b_gross_income.

Fixes #9957.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
other_net_gain (Form 4797 line 18b, Schedule 1 line 4) entered
ma_gross_income only through irs_gross_income, so a gain stayed in Part
B and a loss was dropped. Massachusetts reports Form 4797, Part II
amounts on Schedule D, line 7. Add ma_long_term_capital_gains for the
long-term Schedule D amount (long-term gains, line 6 distributions and
line 7 Form 4797 amounts), use it in ma_part_c_gross_income and
ma_part_a_agi, and take other_net_gain_gross_income out of
ma_part_b_gross_income.

Also renames part_a_and_c_income to filer_dividends_and_gains and cites
the Schedule D instructions in the Part B and Part C references, from
the #9954 review.

Fixes #9990.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PavelMakarchuk
PavelMakarchuk requested a review from hua7450 October 7, 2026 14:55
# Conflicts:
#	policyengine_us/variables/gov/states/ma/tax/income/adjusted_gross_income/ma_part_a_agi.py
#	policyengine_us/variables/gov/states/ma/tax/income/gross_income/ma_part_b_gross_income.py
#	policyengine_us/variables/gov/states/ma/tax/income/gross_income/ma_part_c_gross_income.py

@hua7450 hua7450 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. Read all six files at 7c54f35 against main (which now carries 9954), plus other_net_gain, other_net_gain_gross_income, irs_gross_income with gov/irs/gross_income/sources.yaml, loss_ald and the rest of the MA gross income and AGI chain, against the 2023 Schedule D, Schedule B, the Form 1 instructions (page 27) and c. 62 s. 2(b) and (c).

Schedule D line 7 is "Massachusetts long-term capital gains and losses from U.S. Form 4797, Part II", and the instructions say to enter the Part II amounts "treated as capital gains or losses for Massachusetts purposes"; Part I section 1231 gains already reach Schedule D through line 4 (federal Schedule D line 11). other_net_gain is the model's Form 4797 line 18b / Schedule 1 line 4 amount, so ma_long_term_capital_gains summing it with long_term_capital_gains and the line 6 distributions is the right reading, and the holding-period caveat (property held one year or less belongs on Schedule B lines 12 and 17 at the short-term rate) is a documented limitation with no input to fix it. Part B subtracts other_net_gain_gross_income exactly as irs_gross_income adds it (same filer allocation and floor), so a Form 4797 gain leaves Part B and a loss never reduces it, and the loss ordering through the new variable (long-term gains, then Schedule B line 25, then up to 2,000 of dividends at line 32) matches s. 2(c)(2) and (c)(4).

All six cases recompute from the 2023 forms: base tax 5% x (60,000 - 4,400 - 2,000) = 2,680, then 2,930 / 2,830 / 2,780 (Part C 5,000 / 3,000 / 2,000) and 2,850 (Part A 2,000 at 8.5%); the dividend case gives Part A and Part C of 0 and, on the form, 2,680, which the model reaches once PR 9906 taxes the dividends left after line 32.

CI: three of the four red checks never started ("failed to be acquired (5 attempts)"), and states-shard-3 is the Mississippi HSA test that PR 9992 fixed on main after this branch's merge of main. Nothing is caused by this PR.

Merge interaction with PR 9906 (I re-approved it at bae9b4c): whichever lands second should read tax_unit("ma_long_term_capital_gains", period) in ma_part_a_agi.py, in 9906's new ma_part_c_agi.py and in ma_long_term_loss_against_dividends.py; 9906's expected values do not change. For 9894 / 9939 the dependent exclusion would move into ma_long_term_capital_gains as a tax_unit_non_dep_add formula.

Nits, not blocking:

  1. The ma_part_a_agi comment says "(line 13)"; the variable is lines 1 to 7 before the line 12 subtraction.
  2. After 9906 merges, assert the 2,680 in the dividend case so the line 32 path is pinned.
  3. The documentation string could say the practical effect of the holding-period limitation in one clause: short-held business property is taxed at 5% here instead of the Schedule B 8.5%.

PavelMakarchuk and others added 2 commits October 7, 2026 14:51
Resolve ma_part_a_agi with main's #9906 structure (Schedule B loss order
variables), and read Schedule D line 13 from ma_long_term_capital_gains
in ma_part_a_agi, ma_part_c_agi and ma_long_term_loss_against_dividends,
so Form 4797 Part II amounts reach every line 13 use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PavelMakarchuk

Copy link
Copy Markdown
Collaborator Author

Merged main to clear the conflict with #9906 (Schedule B loss order), which landed today.

Resolution in ma_part_a_agi: kept main's structure (the new ma_short_term_loss_against_dividends / ma_long_term_loss_against_dividends variables). #9906 reads Schedule D line 13 as long_term_capital_gains + non_sch_d_capital_gains in three places: ma_part_a_agi, ma_part_c_agi and ma_long_term_loss_against_dividends. All three now read ma_long_term_capital_gains from this PR, which is those two plus other_net_gain (Schedule D line 7), so the Form 4797 amounts reach every line 13 use and not only ma_part_c_gross_income.

The Massachusetts tests pass (690). Since this changes code after your approval, please take another look.

@hua7450 hua7450 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-approving at f557b33. Against main the PR is exactly the eight files it should be, and relative to the head I approved the only new code is the conflict resolution onto 9906's structure plus the repointed reads: ma_part_a_agi, ma_part_c_agi and ma_long_term_loss_against_dividends all take Schedule D line 13 from ma_long_term_capital_gains, and a grep of the Massachusetts tree at head finds no remaining two-item or bare long_term_capital_gains read where line 13 is meant, so the Form 4797 amounts reach every use, not only ma_part_c_gross_income. Walked the ordering with a Form 4797 loss under the merged structure (line 20, line 22 / Schedule D line 14, line 25, line 32 with the combined 2,000 cap, line 33, Part C = line 13 minus the remaining short-term loss) against the 2023 Schedules B and D and instructions pages 25 to 28: intact. All six cases in ma_long_term_capital_gains.yaml and all ten in 9906's ma_schedule_b_capital_losses.yaml recompute at head, and cases 3 to 6 each fail on main's reads, so every repointed read is pinned.

CI: 25 of 26 green; the red Contrib (congress) job is "hosted runner lost communication with the server" with the test step never concluded, not this PR.

Nits carried from the first round, still optional: the dividend case now yields the form's 2,680 in the model, so asserting it (and the line 32 intermediates) would pin the path; the "(line 13)" comment in ma_part_a_agi is shorthand for lines 1 to 7; and the documentation string could say the holding-period effect in one clause. Follow-ups for a later PR: ma_part_c_gross_income is now unread after 9954 and 9906, and the dependent exclusion for the new variable belongs with 9894 / 9939.

@PavelMakarchuk
PavelMakarchuk merged commit 00ce228 into main Oct 12, 2026
26 checks passed
@PavelMakarchuk
PavelMakarchuk deleted the ma-form-4797-schedule-d branch October 12, 2026 20:03
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.

Massachusetts puts Form 4797 gains in Part B and drops Form 4797 losses instead of using Schedule D, line 7

2 participants