summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala11
-rw-r--r--test/files/neg/t6336.check4
-rw-r--r--test/files/neg/t6336.scala11
3 files changed, 22 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5200aae8d1..85f260f2b4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1984,18 +1984,21 @@ 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")
for (paramType <- tp.paramTypes) {
val sym = paramType.typeSymbol
if (sym.isAbstractType) {
if (!sym.hasTransOwner(meth.owner))
- fail("Parameter type in structural refinement may not refer to an abstract type defined outside that refinement")
+ failStruct("an abstract type defined outside that refinement")
else if (!sym.hasTransOwner(meth))
- fail("Parameter type in structural refinement may not refer to a type member of that refinement")
+ failStruct("a type member of that refinement")
}
+ if (sym.isDerivedValueClass)
+ failStruct("a user-defined value class")
if (paramType.isInstanceOf[ThisType] && sym == meth.owner)
- fail("Parameter type in structural refinement may not refer to the type of that refinement (self type)")
+ failStruct("the type of that refinement (self type)")
}
}
def typedUseCase(useCase: UseCase) {
diff --git a/test/files/neg/t6336.check b/test/files/neg/t6336.check
new file mode 100644
index 0000000000..f6b35ad232
--- /dev/null
+++ b/test/files/neg/t6336.check
@@ -0,0 +1,4 @@
+t6336.scala:3: error: Parameter type in structural refinement may not refer to a user-defined value class
+ val a = new { def y[T](x: X[T]) = x.i }
+ ^
+one error found
diff --git a/test/files/neg/t6336.scala b/test/files/neg/t6336.scala
new file mode 100644
index 0000000000..a9844ff94f
--- /dev/null
+++ b/test/files/neg/t6336.scala
@@ -0,0 +1,11 @@
+object D {
+ def main(args: Array[String]) {
+ val a = new { def y[T](x: X[T]) = x.i }
+ val x = new X(3)
+ val t = a.y(x)
+ println(t)
+ }
+}
+
+class X[T](val i: Int) extends AnyVal
+