diff options
author | Martin Odersky <odersky@gmail.com> | 2012-09-18 17:21:35 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2012-09-18 17:21:35 +0200 |
commit | 8c69f4da333f17290da26c3951fa9c8805014e47 (patch) | |
tree | d6d9b237e6664f2842c2c8a797f0cc745050d3bd /src/compiler | |
parent | 61480eb14a07c78a6746d2a6dc1e302d5baa112f (diff) | |
download | scala-8c69f4da333f17290da26c3951fa9c8805014e47.tar.gz scala-8c69f4da333f17290da26c3951fa9c8805014e47.tar.bz2 scala-8c69f4da333f17290da26c3951fa9c8805014e47.zip |
SI-6336 Now also catches return types
As Mark's comments on SI-6336 shows, we also need to disallow value classes
as return types of structural types.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 089245e124..6ecd7911fd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1977,6 +1977,8 @@ trait Typers extends Modes with Adaptations with Tags { * - the self-type of the refinement * - a type member of the refinement * - an abstract type declared outside of the refinement. + * - an instance of a value class + * Furthermore, the result type may not be a value class either */ def checkMethodStructuralCompatible(meth: Symbol): Unit = { def fail(msg: String) = unit.error(meth.pos, msg) @@ -1986,8 +1988,8 @@ trait Typers extends Modes with Adaptations with Tags { case PolyType(_, restpe) => restpe case _ => NoType } - def failStruct(what: String) = - fail(s"Parameter type in structural refinement may not refer to $what") + def failStruct(what: String, where: String = "Parameter") = + fail(s"$where type in structural refinement may not refer to $what") for (paramType <- tp.paramTypes) { val sym = paramType.typeSymbol @@ -2002,7 +2004,10 @@ trait Typers extends Modes with Adaptations with Tags { if (paramType.isInstanceOf[ThisType] && sym == meth.owner) failStruct("the type of that refinement (self type)") } + if (tp.resultType.typeSymbol.isDerivedValueClass) + failStruct("a user-defined value class", where = "Result") } + def typedUseCase(useCase: UseCase) { def stringParser(str: String): syntaxAnalyzer.Parser = { val file = new BatchSourceFile(context.unit.source.file, str) { |