Tab expansion with indented code

Can someone help me understand how tab expansion is supposed to work, particular w.r.t. indented code blocks?

4.4 says:

An indented chunk is a sequence of non-blank lines, each indented four or more spaces. The contents of the code block are the literal contents of the lines, including trailing line endings, minus four spaces of indentation.

(emphasis mine)

2.2 says:

in contexts where whitespace helps to define block structure, tabs behave as if they were replaced by spaces with a tab stop of 4 characters.

If I have an indented code block with 4 leading spaces or one with a single leading tab then I get a code block with no leading spaces. Simple enough.

If I have an indented code block with 6 leading spaces I get a code block with 2 leading spaces. Makes sense.

However, if I have an indented code block with 2 leading spaces followed by a tab I get a code block with no leading spaces. Why? I would expect a code block containing 2 leading spaces. Curiously, if I have an indented code block with a tab followed by two leading spaces I get the desired behavior, a code block containing 2 leading spaces.

Can anyone help me understand what’s going on here? An implementation bug or something I’m just not understanding in the spec?

Sorry, after posting this I remembered how tab stops are supposed to work ;).

That said, the Vanilla MD specification does a very good job of explaining how this is supposed to be implemented. Perhaps the CommonMark spec would benefit from similar verbiage?

However, [4]if I have an indented code block with 2 leading spaces
followed by a tab I get a code block with no leading spaces. Why? I
would expect a code block containing 2 leading spaces.

If you have a tab stop of 4, then SPACE + SPACE + TAB puts you at the same position as a single TAB (equivalent to four spaces). SPACE + SPACE + TAB is not equivalent to TAB + SPACE + SPACE, because TAB means “go forward to the nearest tab stop,” not “go forward 4 spaces.”