Skip to content

Commit

Permalink
SI-6483 Prohibit super[T] references in value classes.
Browse files Browse the repository at this point in the history
This seems the safest course of action for 2.10.0.
  • Loading branch information
retronym committed Oct 7, 2012
1 parent bfde8c7 commit 1b2ac4e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,9 @@ trait Typers extends Modes with Adaptations with Tags {
case x: ValDef if x.mods.isLazy =>
//see https://issues.scala-lang.org/browse/SI-6358
implRestriction(tree, "lazy val")
case Select(sup @ Super(qual, mix), selector) if selector != nme.CONSTRUCTOR && qual.symbol == clazz && mix != tpnme.EMPTY =>
//see https://issues.scala-lang.org/browse/SI-6483
implRestriction(sup, "qualified super reference")
case _ =>
}
super.traverse(tree)
Expand Down
9 changes: 9 additions & 0 deletions test/files/neg/t6483.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
t6483.scala:7: error: implementation restriction: qualified super reference is not allowed in value class
This restriction is planned to be removed in subsequent releases.
override def foo = super[T].foo // error
^
t6483.scala:20: error: implementation restriction: nested class is not allowed in value class
This restriction is planned to be removed in subsequent releases.
class Inner extends T {
^
two errors found
24 changes: 24 additions & 0 deletions test/files/neg/t6483.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
trait T extends Any {
def foo = 1
type X
}

class C1(val a: Any) extends AnyVal with T {
override def foo = super[T].foo // error
}

class C2(val a: Int) extends AnyVal with T {
override def foo = super.foo + a // okay
}

class C3(val a: Int) extends AnyVal with T {
override def foo = C3.super.foo + a // okay
}

class C4(val a: Int) extends AnyVal with T {
def foo {
class Inner extends T {
override def foo = super[T].foo + a // no (direct) error, other than that a nested class is currently illegal.
}
}
}

0 comments on commit 1b2ac4e

Please sign in to comment.