Example #1
0
 private TypeSymbol(string name, ITypeScope enclosingScope, IType type, TypeSymbolKind kind)
     : base(name, type, new ClassScope(enclosingScope))
 {
     _superClass = null;
     Kind = kind;
     ((ClassScope)Scope).Symbol = this;
 }
Example #2
0
 public new bool Define(TypeSymbol sym)
 {
     if (sym.Kind == TypeSymbolKind.Scalar &&
         !MiniJavaInfo.IsBuiltInType(sym.Name) &&
         !(sym.Name == MiniJavaInfo.AnyType))
     {
         UserDefinedTypeNames.Add(sym.Name);
     }
     return base.Define(sym);
 }
 public void SetUp()
 {
     _globalScope = new GlobalScope();
     _superSuperClass = SymbolCreationHelper.CreateAndDefineClass("Foo", _globalScope);
     _superClass = SymbolCreationHelper.CreateAndDefineClass("Bar", _globalScope);
     _superClass.SuperClass = _superSuperClass;
     _testClass = SymbolCreationHelper.CreateAndDefineClass("Baz", _globalScope);
     _testClass.SuperClass = _superClass;
     _someType = TypeSymbol.MakeScalarTypeSymbol("int", _globalScope).Type;
 }
            private void CheckForOverloading(MethodDeclaration node,
                TypeSymbol classSymbol, MethodSymbol superClassMethod)
            {
                var superClassMethodDeclaration = (MethodDeclaration)superClassMethod.Declaration;
                if (OverloadsSuperClassMethod(node, superClassMethodDeclaration))
                {
                    var msg = String.Format("Method {0} in class {1} overloads a method in class {2}. Overloading is not allowed.",
                        node.Name, classSymbol.Name, classSymbol.SuperClass.Name);
                    ReportError(ErrorTypes.InvalidOverride, msg, node);
                }

                // Subclass methods CANNOT have covariant return types with respect to overridden
                // superclass methods, though this is allowed in Java. This is because the .NET runtime
                // does not natively support them. (Reference link can be found in tests and docs.)
                if (node.Type != superClassMethodDeclaration.Type)
                {
                    var msg = String.Format(
                        "Method {0} in class {1} has a different return type from overridden method in class {2}.",
                        node.Name, classSymbol.Name, classSymbol.SuperClass.Name);
                    ReportError(ErrorTypes.InvalidOverride, msg, node);
                }
            }