Weird error message for private discriminated tagged type

Consider the following example:

p.ads:

package P is
    type T is tagged private;
private
    type S (B : Boolean) is tagged null record;
    type T is new S (B => True) with null record;
end P;

q.ads:

with P;

package Q is
    type R (B : Boolean) is record
        case B is
            when True =>
                X : P.T;
            when False =>
                null;
        end case;
    end record;
end Q;

Compiling q.ads yields the following error message:

q.ads:4:10: error: expected private type "T" defined at p.ads:2
q.ads:4:10: error: found private type "T" defined at p.ads:2

The error is fixed if we either make T not private, S and T not tagged, or R not discriminated. Also simply removing the tagged keyword from the initial declaration of T. In any event, the error message seems absurd. What is going on here?

GNAT tends to emit errors like that when it has done some internal transformation of the AST. Internally there will be two different types that both relate to P.T or something along those lines.

This does look like a compiler bug though.