From ef2272f2e1084acc43039c739fe19a55caee2188 Mon Sep 17 00:00:00 2001 From: Martin Raum Date: Thu, 3 Dec 2020 17:28:07 +0100 Subject: [PATCH 1/2] fix aliasing in matrix algebra constructor --- src/generic/MatrixAlgebra.jl | 2 +- test/generic/MatrixAlgebra-test.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/generic/MatrixAlgebra.jl b/src/generic/MatrixAlgebra.jl index 42a3efcbbc..69a2be204d 100644 --- a/src/generic/MatrixAlgebra.jl +++ b/src/generic/MatrixAlgebra.jl @@ -598,7 +598,7 @@ function (a::MatAlgebra{T})(b::S) where {S <: RingElement, T <: RingElement} if i != j entries[i, j] = zero(R) else - entries[i, j] = rb + entries[i, j] = i == 1 ? rb : deepcopy(rb) end end end diff --git a/test/generic/MatrixAlgebra-test.jl b/test/generic/MatrixAlgebra-test.jl index 4d090c7a86..1d465c31fa 100644 --- a/test/generic/MatrixAlgebra-test.jl +++ b/test/generic/MatrixAlgebra-test.jl @@ -27,6 +27,7 @@ end f = S(t^2 + 1) @test isa(f, MatAlgElem) + @test !(f[1,1] === f[2,2]) g = S(2) From 414553f05b380ea9440e274aa4820d9795171da0 Mon Sep 17 00:00:00 2001 From: Martin Raum Date: Thu, 3 Dec 2020 21:06:45 +0100 Subject: [PATCH 2/2] fix alising also for matrix spaces --- src/generic/Matrix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/Matrix.jl b/src/generic/Matrix.jl index de7ca3454c..7df99310a5 100644 --- a/src/generic/Matrix.jl +++ b/src/generic/Matrix.jl @@ -5856,7 +5856,7 @@ function (a::MatSpace{T})(b::S) where {S <: RingElement, T <: RingElement} if i != j entries[i, j] = zero(R) else - entries[i, j] = rb + entries[i, j] = i == 1 ? rb : deepcopy(rb) end end end