diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-08-08 18:53:42 +0200 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-08-14 11:45:47 +0200 |
commit | 5439c4c9aa9ef03c061fa9c2c4689a722729b8f9 (patch) | |
tree | 165a208cadc93b505ef5e501358340f32da4606d /test/junit/scala/tools/nsc/symtab | |
parent | 834e29ff7f2047054e4af4c05311943bcbe480a7 (diff) | |
download | scala-5439c4c9aa9ef03c061fa9c2c4689a722729b8f9.tar.gz scala-5439c4c9aa9ef03c061fa9c2c4689a722729b8f9.tar.bz2 scala-5439c4c9aa9ef03c061fa9c2c4689a722729b8f9.zip |
SI-7731 make CannotHaveAttrs more consistent
Previously setPos, pos_=, setType, tpe_= all behaved inconsistently
between each other even though they all represent similar
attributes that cannot be changed on CannotHaveAttrs trees.
In order to simplify handling of such trees in compiler code each
of these fields now supports assignment to its current default
value: NoType for tpe and NoPosition for pos. Such assignments
don't mutate underlying trees.
Diffstat (limited to 'test/junit/scala/tools/nsc/symtab')
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala b/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala new file mode 100644 index 0000000000..5867a9030b --- /dev/null +++ b/test/junit/scala/tools/nsc/symtab/CannotHaveAttrsTest.scala @@ -0,0 +1,70 @@ +package scala.tools.nsc +package symtab + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.testing.AssertUtil.assertThrows +import scala.reflect.internal.util.OffsetPosition + +@RunWith(classOf[JUnit4]) +class CannotHaveAttrsTest { + class CustomSymbolTable extends SymbolTableForUnitTesting { + object CHA extends CannotHaveAttrs { + def canEqual(that: Any): Boolean = ??? + def productArity: Int = ??? + def productElement(n: Int): Any = ??? + } + val attrlessTrees = List(CHA, EmptyTree, emptyValDef, pendingSuperCall) + } + def withCtx(body: CustomSymbolTable => Unit) = body(new CustomSymbolTable) + + @Test + def canHaveAttrsIsFalse = withCtx { st => import st._ + attrlessTrees.foreach { t => + assertFalse(t.canHaveAttrs) + } + } + + @Test + def defaultPosAssignment = withCtx { st => import st._ + attrlessTrees.foreach { t => + assertEquals(t.pos, NoPosition) + t.pos = NoPosition + assertEquals(t.pos, NoPosition) + t.setPos(NoPosition) + assertEquals(t.pos, NoPosition) + } + } + + @Test + def defaultTpeAssignment = withCtx { st => import st._ + attrlessTrees.foreach { t => + assertEquals(t.tpe, NoType) + t.tpe = NoType + assertEquals(t.tpe, NoType) + t.setType(NoType) + assertEquals(t.tpe, NoType) + } + } + + @Test + def nonDefaultPosAssignmentFails = withCtx { st => import st._ + val pos = new OffsetPosition(null, 0) + attrlessTrees.foreach { t => + assertThrows[IllegalArgumentException] { t.pos = pos } + assertThrows[IllegalArgumentException] { t.setPos(pos) } + } + } + + @Test + def nonDefaultTpeAssignmentFails = withCtx { st => import st._ + val tpe = typeOf[Int] + attrlessTrees.foreach { t => + assertThrows[IllegalArgumentException] { t.tpe = tpe } + assertThrows[IllegalArgumentException] { t.setType(tpe) } + } + } +} |