P-type AlInN layers lattice-matched to GaN are achieved by Mg doping. The net acceptor concentration N-A-N-D is 5 x 10(18) cm(-3) at a Mg concentration [Mg] of similar to 2 x 10(19) cm(-3). Mg acceptors are partly compensated and one of the compensating defects is related to the occurrence of surface pits. At [Mg] < 2 x 10(19) cm(-3), the pit density is independent of [Mg] and N-A-N-D increases together with increasing [Mg]. At [Mg] > 2 x 10(19) cm(-3), as [Mg] increases, the pit density increases and the N-A-N-D decreases. By decreasing the pit density, a higher N-A-N-D value is obtained and light-emitting diodes with p-type AlInN layer show improved emission intensity. (C) 2012 American Institute of Physics. [http://dx.doi.org/10.1063/1.4747524]