Section 17A. (a) An inhabitant of the commonwealth who is a shareholder of an S corporation, as defined under section thirteen hundred and sixty-one of the Code and whether or not such S corporation is subject to tax under chapter sixty-three, shall be subject to the taxes imposed by this chapter on his distributive share of the corporation's items of income, loss or deduction, as provided under subchapter S of the Code, for the shareholder's taxable year in which the taxable year of the S corporation ends, or for the final taxable year of a shareholder who dies before the end of the corporation's taxable year; provided, however, such items of income, loss or deduction are taxable or available to the shareholder under the provisions of chapter sixty-two if realized or incurred directly by the shareholder. He shall include separately in his return his distributive share of the S corporation's income or loss from sources taxable under this chapter and of any item of deduction or credit, including the taxpayer's pro rata share of any tax upon income paid by the S corporation and otherwise allowable as a credit under subsection (a) of section six. Credits under section thirty-one A or thirty-eight E of chapter sixty-three shall not be allowed hereunder.
(b) A nonresident of the commonwealth who is a shareholder of an S corporation, as so defined, which is subject to tax under chapter sixty-three shall be subject to the tax imposed by section five A on his distributive share of the income realized by the S corporation as would be subject to taxation under section five A if realized by a nonresident. Where the S corporation does business both within and without the commonwealth, the income derived from business carried on within the commonwealth shall be determined under the provisions of section thirty-eight and forty-two of chapter sixty-three. The shareholder shall include separately in his return his distributive share of such income or loss and of any item of deduction or credit relating thereto.
(c) The character of any item of income, loss, deduction or credit included in a shareholder's distributive share shall be determined as if such item were realized or incurred directly by the shareholder from the source from which realized by the corporation or incurred in the same manner as incurred by the corporation. Such determinations shall be made under the provisions of chapter sixty-two and of the Code applicable to the shareholders of the S corporation.
(d) Notwithstanding any other provision of this chapter, where a corporation has elected to be an S corporation for federal income tax purposes prior to the effective date of this section, and the basis of such corporation's stock or indebtedness has been adjusted for federal income tax purposes under the provisions of Subchapter S of the Code for S corporation taxable years commencing before nineteen hundred and eighty-six, then such adjustments, limited to the extent they are applicable in determining the basis for the corporation's shareholders as of the last day of the last S corporation taxable year commencing before nineteen hundred and eighty-six, will be modifications to the gain or loss recognized under this chapter on the sale or exchange of such stock or indebtedness. Net positive basis adjustments will reduce the shareholder's federal basis in such corporation's stock. Net negative basis adjustments will increase the shareholders federal basis in such corporation's stock. If stock or indebtedness is transferred and the basis to the transferee is determined by reference to the basis of the transferor, then the modifications made by this section will continue to apply to the transferee.