From a83586a4815acd35df0801ed0e9f067e113c8664 Mon Sep 17 00:00:00 2001 From: Aleksandar Prokopec Date: Mon, 18 Jun 2012 19:33:06 +0200 Subject: Fix SI-4541. Catch type errors when duplicating trees. In this case, to access a protected member from a specialized class is an error, so we would have to make the member public anyway. Better it is then to report an error and have the user make the field public explicitly. Review by @dragos. --- test/files/neg/t4541.check | 7 +++++++ test/files/neg/t4541.scala | 16 ++++++++++++++++ test/files/neg/t4541b.check | 7 +++++++ test/files/neg/t4541b.scala | 16 ++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 test/files/neg/t4541.check create mode 100644 test/files/neg/t4541.scala create mode 100644 test/files/neg/t4541b.check create mode 100644 test/files/neg/t4541b.scala (limited to 'test') diff --git a/test/files/neg/t4541.check b/test/files/neg/t4541.check new file mode 100644 index 0000000000..c01226685f --- /dev/null +++ b/test/files/neg/t4541.check @@ -0,0 +1,7 @@ +t4541.scala:11: error: scala.reflect.internal.Types$TypeError: variable data in class Sparse cannot be accessed in Sparse[Int] + Access to protected method data not permitted because + prefix type Sparse[Int] does not conform to + class Sparse$mcI$sp where the access take place + that.data + ^ +one error found \ No newline at end of file diff --git a/test/files/neg/t4541.scala b/test/files/neg/t4541.scala new file mode 100644 index 0000000000..744af1c288 --- /dev/null +++ b/test/files/neg/t4541.scala @@ -0,0 +1,16 @@ + + + + + + +@SerialVersionUID(1L) +final class Sparse[@specialized(Int) T](d: Array[T]) extends Serializable { + protected var data: Array[T] = d + def set(that: Sparse[T]) = { + that.data + } +} + + + diff --git a/test/files/neg/t4541b.check b/test/files/neg/t4541b.check new file mode 100644 index 0000000000..54d9c3d1ee --- /dev/null +++ b/test/files/neg/t4541b.check @@ -0,0 +1,7 @@ +t4541b.scala:13: error: scala.reflect.internal.Types$TypeError: variable data in class SparseArray cannot be accessed in SparseArray[Int] + Access to protected method data not permitted because + prefix type SparseArray[Int] does not conform to + class SparseArray$mcI$sp where the access take place + use(that.data.clone) + ^ +one error found \ No newline at end of file diff --git a/test/files/neg/t4541b.scala b/test/files/neg/t4541b.scala new file mode 100644 index 0000000000..7a21ffc156 --- /dev/null +++ b/test/files/neg/t4541b.scala @@ -0,0 +1,16 @@ + + + + + +@SerialVersionUID(1L) +final class SparseArray[@specialized(Int) T](private var data: Array[T]) extends Serializable { + def use(inData: Array[T]) = { + data = inData; + } + + def set(that: SparseArray[T]) = { + use(that.data.clone) + } +} + -- cgit v1.2.3