summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-09-20 14:03:44 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-09-20 14:03:44 +0000
commitf6d4d84dd7eb5de3e7f698c7f627d483b6999142 (patch)
treef2ec89f0ab9ce26fb110863e57c86d4fc6110ca7
parentc22bc18ab6a6b91c30a6e9dde6797d7db94e22e0 (diff)
downloadscala-f6d4d84dd7eb5de3e7f698c7f627d483b6999142.tar.gz
scala-f6d4d84dd7eb5de3e7f698c7f627d483b6999142.tar.bz2
scala-f6d4d84dd7eb5de3e7f698c7f627d483b6999142.zip
Fixes #4417.
Review by Dragos.
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala17
-rw-r--r--test/files/neg/t4417.check7
-rw-r--r--test/files/neg/t4417.scala17
3 files changed, 36 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index 14bfa65335..89d50f4cc3 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -1241,12 +1241,19 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
tree match {
case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
if (findSpec(tpt.tpe).typeSymbol ne tpt.tpe.typeSymbol) {
+ // the ctor can be specialized
log("** instantiated specialized type: " + findSpec(tpt.tpe))
- atPos(tree.pos)(
- localTyper.typed(
- Apply(
- Select(New(TypeTree(findSpec(tpt.tpe))), nme.CONSTRUCTOR),
- transformTrees(args))))
+ try {
+ atPos(tree.pos)(
+ localTyper.typed(
+ Apply(
+ Select(New(TypeTree(findSpec(tpt.tpe))), nme.CONSTRUCTOR),
+ transformTrees(args))))
+ } catch {
+ case te: TypeError =>
+ reporter.error(tree.pos, te.msg)
+ super.transform(tree)
+ }
} else super.transform(tree)
case TypeApply(Select(qual, name), targs)
diff --git a/test/files/neg/t4417.check b/test/files/neg/t4417.check
new file mode 100644
index 0000000000..0a5ea2265b
--- /dev/null
+++ b/test/files/neg/t4417.check
@@ -0,0 +1,7 @@
+t4417.scala:11: error: constructor Pixel$mcD$sp in class Pixel$mcD$sp cannot be accessed in object Pixel
+ Access to protected constructor Pixel$mcD$sp not permitted because
+ enclosing object Pixel is not a subclass of
+ class Pixel$mcD$sp where target is defined
+ def apply(v: Double): Pixel1d = new Pixel1d(v)
+ ^
+one error found \ No newline at end of file
diff --git a/test/files/neg/t4417.scala b/test/files/neg/t4417.scala
new file mode 100644
index 0000000000..3f6ddc8153
--- /dev/null
+++ b/test/files/neg/t4417.scala
@@ -0,0 +1,17 @@
+
+
+
+
+class Pixel[@specialized T] protected (var v: T)
+
+
+object Pixel {
+ type Pixel1d = Pixel[Double]
+
+ def apply(v: Double): Pixel1d = new Pixel1d(v)
+}
+
+
+
+
+