diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-08-02 11:22:04 -0700 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-08-02 11:22:04 -0700 |
commit | d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d (patch) | |
tree | c9c9a2703f58052705f8eb6f3be6fe45db03ae67 /test/junit | |
parent | 3cb3c8e35c3df31a7f661903eca48cca557d5a49 (diff) | |
download | scala-d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d.tar.gz scala-d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d.tar.bz2 scala-d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d.zip |
Add sample to SymbolTableTest using custom symbols and type.
Add a test which demonstrates how one can create symbols and types
from scratch and perform sub type check using them.
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala b/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala index 166e0382f7..537cb93ef3 100644 --- a/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala +++ b/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala @@ -26,4 +26,25 @@ class SymbolTableTest { assertTrue("List should be subclass of Seq", listClassTpe <:< seqClassTpe) } + /** + * Demonstrates how one can create symbols and type completely + * from scratch and perform sub type check. + */ + @Test + def customClassesSubTypeCheck: Unit = { + val symbolTable = createSymbolTable + import symbolTable._ + symbolTable.definitions.init() + val rootClass = symbolTable.rootMirror.RootClass + val fooSymbol = rootClass.newClassSymbol("Foo": TypeName, NoPosition, 0) + val fooType = new ClassInfoType(Nil, EmptyScope, fooSymbol) + fooSymbol.info = fooType + val barSymbol = rootClass.newClassSymbol("Bar": TypeName, NoPosition, 0) + val fooTypeRef = TypeRef(fooSymbol.owner.tpe, fooSymbol, Nil) + val barType = new ClassInfoType(List(fooTypeRef), EmptyScope, barSymbol) + barSymbol.info = barType + assertTrue("Bar should be subclass of Foo", barSymbol.tpe <:< fooSymbol.tpe) + assertFalse("Foo should be a superclass of Foo", fooSymbol.tpe <:< barSymbol.tpe) + } + } |