From 8c69f4da333f17290da26c3951fa9c8805014e47 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 18 Sep 2012 17:21:35 +0200 Subject: 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. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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) { -- cgit v1.2.3