R=randn(2,2), (a general square matrix) then
U = UpperTriangular(R) or
L = LowerTriangular(R) would sucessfully return triangular matrices. Also,
D = Diagonal(R) works similarly. In all these cases, some (in general) non-zero elements of the original R have been effectively zeroed, without throwing errors. (You can verify they are zero by doing
ArgumentError: matrix cannot be represented as Diagonal because of the non-zero off-diagonal elements in the triangular inputs.
While the error can be avoided by explicitly doing
Diagonal(diag(L)) , I would argue that this behaviour of the
Diagonal constructor is inconsistent between full and triangular arguments. It is also inconsistent with the UpperTriangular and LowerTriangular constructors.
My vote would be to resolve the inconsistencies by e.g.:
Diagonal(Tr::AbstractTriangular) = Diagonal(diag(Tr))
or something equivalent.