diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala | 17 | ||||
-rw-r--r-- | test/files/neg/t4417.check | 7 | ||||
-rw-r--r-- | test/files/neg/t4417.scala | 17 |
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) +} + + + + + |