Esempio n. 1
0
 def testOverrideWithImplicitTypeParameters(self):
     source = "class A[static T]\n" + \
              "  def to-string = \"A\"\n"
     info = self.analyzeFromSource(source)
     A = info.package.findClass(name="A")
     toString = A.getMethod("to-string")
     self.assertIs(A, toString.clas)
     self.assertIs(toString.override, getRootClass().getMethod("to-string"))
Esempio n. 2
0
 def testSupertypes(self):
     source = "class Foo\n" + \
              "class Bar <: Foo"
     info = self.analyzeFromSource(source)
     fooClass = info.package.findClass(name="Foo")
     self.assertEquals([ClassType(getRootClass(), ())], fooClass.supertypes)
     barClass = info.package.findClass(name="Bar")
     self.assertEquals([ClassType(fooClass, ())], barClass.supertypes)
Esempio n. 3
0
 def testOverrideBuiltin(self):
     source = "class Foo\n" + \
              "  override def to-string = \"Foo\""
     info = self.analyzeFromSource(source)
     scope = info.getScope(info.ast.modules[0].definitions[0])
     self.assertEquals(1, len(scope.getDefinition("to-string").overloads))
     overrides = scope.getDefinition("to-string").overloads[0].irDefn.overrides
     self.assertEquals([getRootClass().findMethodBySourceName("to-string").id],
                       [o.id for o in overrides])
Esempio n. 4
0
 def testMethodOverriddenOnceAlongMultiplePaths(self):
     source = "trait Foo\n" + \
              "class Bar <: Object, Foo\n" + \
              "  public override def to-string = \"Bar\""
     info = self.analyzeFromSource(source)
     ObjectToString = getRootClass().findMethodBySourceName("to-string")
     Bar = info.package.findClass(name="Bar")
     BarToString = info.package.findFunction(name="Bar.to-string")
     self.assertEquals(1, len(BarToString.overrides))
     self.assertIs(ObjectToString, BarToString.overrides[0])
     self.assertIs(BarToString, ObjectToString.overriddenBy[Bar.id])
Esempio n. 5
0
 def testOverloadOnTypeParameterBounds(self):
     source = "class A\n" + \
              "def f[static T] = {}\n" + \
              "def f[static T <: A] = {}\n" + \
              "def g = f[Object]"
     info = self.analyzeFromSource(source)
     use = info.getUseInfo(info.ast.definitions[3].body)
     A = info.package.findClass(name="A")
     pred = lambda fn: len(fn.typeParameters) == 1 and \
                       fn.typeParameters[0].upperBound.clas is getRootClass()
     f = info.package.findFunction(name="f", pred=pred)
     self.assertIs(use.defnInfo.irDefn, f)
Esempio n. 6
0
 def visitAstPartialFunctionExpression(self, expr, mode, ty, doneBlock, failBlock):
     self.dup()
     typeofMethod = getRootClass().getMethod("typeof")
     self.buildCallSimpleMethod(typeofMethod, COMPILE_FOR_VALUE)
     for case in expr.cases[:-1]:
         nextBlock = self.newBlock()
         self.visitAstPartialFunctionCase(case, mode, ty, doneBlock, nextBlock)
         self.setCurrentBlock(nextBlock)
     self.visitAstPartialFunctionCase(expr.cases[-1], mode, ty, doneBlock, failBlock)
     self.setCurrentBlock(failBlock)
     self.drop()
     self.setCurrentBlock(None)
Esempio n. 7
0
 def testOverrideGrandParent(self):
     source = "abstract class A\n" + \
              "  abstract def to-string: String\n" + \
              "class B <: A\n" + \
              "  def to-string = \"B\""
     info = self.analyzeFromSource(source)
     Object = getRootClass()
     ObjectToString = Object.getMethod("to-string")
     A = info.package.findClass(name="A")
     AToString = info.package.findFunction(name="to-string", clas=A)
     B = info.package.findClass(name="B")
     BToString = info.package.findFunction(name="to-string", clas=B)
     self.assertIs(ObjectToString, AToString.override)
     self.assertIs(AToString, BToString.override)
Esempio n. 8
0
def getRootClassType():
    return ClassType(builtins.getRootClass(), ())
Esempio n. 9
0
 def testExternalizeBuiltinDefn(self):
     rootClass = builtins.getRootClass()
     externClass = externalizeDefn(self.info, rootClass)
     self.assertIs(rootClass, externClass)
Esempio n. 10
0
 def testClassInfoForBuiltin(self):
     info = self.analyzeFromSource("")
     rootClassInfo = info.getClassInfo(BUILTIN_ROOT_CLASS_ID)
     self.assertIs(getRootClass(), rootClassInfo.irDefn)
     self.assertIs(None, rootClassInfo.superclassInfo)
Esempio n. 11
0
 def testExternalizeBuiltinDefn(self):
     rootClass = builtins.getRootClass()
     externClass = externalizeDefn(self.info, rootClass)
     self.assertIs(rootClass, externClass)
Esempio n. 12
0
 def testNullableType(self):
     info = self.analyzeFromSource("var g: Object?")
     expected = ClassType(getRootClass(), (), frozenset([NULLABLE_TYPE_FLAG]))
     self.assertEquals(expected, info.package.findGlobal(name="g").type)
Esempio n. 13
0
 def testRootClassType(self):
     info = self.analyzeFromSource("var g: Object")
     rootClass = getRootClass()
     self.assertEquals(ClassType(rootClass, ()), info.package.findGlobal(name="g").type)
Esempio n. 14
0
 def testConstructRootClass(self):
     info = self.analyzeFromSource("def f = Object")
     rootClass = getRootClass()
     self.assertEquals(ClassType(rootClass, ()), info.getType(info.ast.definitions[0].body))