From d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Fri, 2 Aug 2013 11:22:04 -0700 Subject: 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. --- .../scala/tools/nsc/symtab/SymbolTableTest.scala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/junit') 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) + } + } -- cgit v1.2.3