Virgil Language Reference: errors

This page gives an exhaustive list of the semantic errors generated by the Virgil compiler and gives a description of the conditions under each arises in a program. The Virgil compiler treats all semantic errors as fatal; the compilation will not succeed if a semantic error is detected, and the program will be rejected.

Syntactic and Semantic Errors

The Virgil Programming Language Specification defines the criteria for a well-formed Virgil program. The compiler checks a number of properties of the program to ensure compliance with the language specification and generates error messages if the program does not meet the criteria. This help category lists the errors that may be generated by the Virgil compiler and gives a short description of each.

  • ArgumentCountMismatch - Generated when the typechecker analyzes function application expressions (method calls) in the program. The VLS states that the number of arguments to the function must match the signature of the function.
  • ArgumentCountMismatchInNew - Generated when the typechecker analyzes object allocations in the program. The VLS states that the number of arguments to the constructor must match the signature of the constructor.
  • BuiltinRedefined - Generated when the program attempts to redefine a type that is already defined by the Virgil language specification. Some types are considered "built-in" to the language, and cannot be redefined or overridden by the program.
  • CannotAssignToMember - Generated when an assignment to a method member of a class or component is encountered in the program. Methods are not updatable in Virgil; the VLS states that any attempt to assign to a method of an object or component is an error.
  • CannotCompareValues - Generated when the typechecker analyzes comparisons in the program and the types of the two expressions are not directly comparable. The VLS defines the rules for comparable types in more detail.
  • CannotInferEmptyArrayType - Generated when the typechecker encounters a declaration that lacks an explicit type, but the initialization expression is an empty array. The VLS explains that the compiler cannot infer a specific type for the variable, and thus must generate an error.
  • CannotOverrideArity - Generated when the declaration of a class method that overrides a parent class's method attempts to change the number of parameters to the method. The VLS specification states that the number and types of parameters to a method must exactly match those of the overridden method in the parent class.
  • CannotOverrideParamType - Generated when the declaration of a class method that overrides a parent class's method attempts to override the type of a parameter. Virgil does not support contravariant parameter types on overriden methods. The VLS specification states that the number and types of parameters to a method must exactly match those of the overridden method in the parent class.
  • CannotOverrideReturnType - Generated when the declaration of a class method that overrides a parent class's method attempts to override the return type. Virgil does not support covariant return types on overriden methods. The VLS specification states that the return type for a method must exactly match the return type of the overridden method in the parent class.
  • CannotUnifyBranchTypes - Generated when the typecheck attempts to infer the type of a conditional expression but the types of the branches cannot be unified. The VLS defines the unification rules for types.
  • CannotUnifyElemTypes - Generated when the typechecker attempts to infer the type of an array initializer but the element types of the array cannot be unified. The VLS defines the unification rules for types.
  • ConstructorRedefined - Generated when the program attempts to redefine the constructor for a class or component. The VLS specification states that each class and component must declare at most one constructor.
  • CyclicInheritance - Generated when the compiler checks the consistency of the class hierarchy and detects a cycle among the inheritance relation of a set of classes. The VLS states that each class may extend at most one parent class, and that no cycles may exist among the classes.
  • DefaultCaseRedefined - Generated when the typechecker analyzes a switch statement and the program attempts to define the default case more than once.
  • DuplicateCase - Generated when the typechecker analyzes a switch statement and the program attempts to define a duplicate switch case.
  • ExpectedExprType - Generated when the typechecker encounters an identifier that is used an expression, but the identifier refers to a program quantity that does not have a type, such as a component.
  • ExpectedFunction - Generated when the typechecker analyzes function application expressions (method calls) in the program. The VLS states that the receiver expression of an application must have a function type.
  • ExpectedIndexable - Generated when the typechecker analyzes index expressions (e.g. array access). The VLS states that the receiver object or value must be an indexable type.
  • ExpectedObjectType - Generated when the typechecker encounters a construct in the program that requires an object type, but the program uses an expression or type literal that is not an object type. The VLS defines what constructs require an object type.
  • ExpectedReturnType - Generated when the typechecker analyzes method declarations in the program and encounters a declared return type that is not valid.
  • ExpectedVarType - Generated when the typechecker analyzes declarations of fields and local variables in the program. The VLS defines the valid types that a declared field or local may have; variable declarations with a type that is not within this class of types cause an error.
  • ExprCannotBeVoid - Generated when the typechecker detects that an expression has type void but occurs in a situation where a non-void type is expected (e.g. an assignment).
  • InvalidLiteral - Generated for a boolean, integer, character, or string literal that is not legal according to the language specification. This error may be generated if the literal is too large, out of range, or contain invalid characters.
  • InvalidModifier - Generated when the program attempts to use an invalid access modifier on the declaration of a class or component member. The VLS defines the valid modifiers for each kind of declaration.
  • InvalidTypeCast - Generated when the typechecker encounters a type cast expression in the program that is not legal according to the VLS specification.
  • InvalidTypeQuery - Generated when the typechecker encounters a type query expression in the program that is not legal according to the VLS specification.
  • LocalMustHaveTypeOrInit - Generated when the declaration of a local variable does not include either a type or an initializing expression from which the type can be inferred.
  • MemberDefinedInSuper - Generated when the declaration of a member of a class has the same name as a member inherited from a superclass. The VLS states that each member of a class must be given a unique name that does not conflict with members inherited from the super class. Virgil does not support field hiding.
  • MemberRedefined - Generated when the declaration of a class or component contains a declaration of a member (either a field or a method) that conflicts with a previously declared member. The VLS states that each member with in each class or component must have a unique name that is a valid Virgil identifier. Virgil does not support method overloading by overloading parameter types.
  • MissingReturn - Generated when the body of a method that has been declared to return a non-void type does not include a return statement. The VLS states that each method that is declared to return a non-void type must contain at least one return statement at the flow end(s) of the method.
  • NoDefaultConstructor - Generated when a class declaration omits a constructor or when a constructor declaration omits an explicit call to the parent class's constructor, but no default constructor is defined in the parent class. The VLS states that if the parent class has a default (i.e. no arguments) constructor, then the compiler will insert an implicit call to the parent constructor; otherwise the child class must include an explicit call to the appropriate constructor.
  • NonSwitchableType - Generated when the typechecker analyzes a switch statement and the type of the value is not switchable. The VLS defines what types are valid for use in switch statements.
  • NonVoidConstructorReturn - Generated when the body of a constructor contains a return statement includes a value. The VLS states that any return statements that occur within the body of a constructor must not return a value.
  • NonVoidReturn - Generated when the body of a method that has been declared to return void (i.e. without a return type) contains a return statement includes a value. The VLS states that any and all return statements that occur within the body of a void method must not return a value.
  • NoSuperClass - Generated when a constructor declaration for a class attempts to call the super constructor, but the class does not have a parent class. The VLS states that a constructor can include a call to its parent class's constructor only if there is a parent class, and if the number and types of parameters to the parent constructor match.
  • NotAnEqualityType - Generated when the typechecker analyzes comparisons in the program. The VLS states that the operands of the equality operator must both be equality types.
  • NotAnLvalue - Generated when an expression is used as the target of an assignment statement or implicit assignment expression, but the expression does not correspond to a valid location in the program. The VLS defines what expressions constitute valid locations that may be used as the target of an assignment.
  • NotAStatement - Generated during parsing when the compiler is expecting a statement, but parses only an expression. The VLS defines what syntactic forms a statement may take.
  • NotComputable - Generated when the typechecker analyzes a case of a switch statement and the value of the case is not immediately computable. The VLS defines the conditions under which a constant value for a case statement is immediately commutable.
  • ParameterRedefined - Generated when the declaration of a method or constructor attempts to define a parameter with the same name as a previously defined parameter for the method. The VLS states that each parameter to a method must be given a unique name that is a valid Virgil identifier.
  • RedundantModifier - Generated when the declaration of a member of a class or component includes an access modifier that is redundant.
  • StatementMustBeInLoop - Generated when the loop control statements "break" and "continue" do not occur within the body of a loop. In Virgil, these statements can only be placed within statements; "break" is unnecessary for switch statements.
  • SuperClauseMustBeInClass - Generated when a component constructor includes a call to a super constructor. Components do not have super classes; super constructor clauses are only allowed inside the declaration of class constructors.
  • ThisMustBeInClass - Generated when the "this" keyword is incorrectly used anywhere but inside the body of a class method or constructor. The "this" keyword corresponds to the receiver object of the method, which only exists in the body of a class method.
  • TypeMismatch - Generated when the typechecker detects a type error in the program corresponding to a situation where an expression or statement expects a certain type and the program supplies an expression of an incorrect type. The VLS gives a detailed description of the typing rules for Virgil.
  • TypeRedefined - Generated when the program attempts to define a new type that has the same name as a previously defined type. The VLS states that each declared type must be given a unique name that is a valid Virgil identifier.
  • UnexpectedException - Generated when the compiler reduces the expressions of a case statement to a value and the evaluation of the expression results in an exception, such as a DivideByZeroException.
  • UnreachableCode - Generated when the body of a method includes statements beyond the end of control flow structures or statements. See the VLS specification fora more detailed discussion of the flow structures.
  • UnresolvedAssignOp - Generated when the program attempts to use a complex assignment operator that cannot be applied to the type of the destination.
  • UnresolvedBinOp - Generated when the program attempts to use an infix binary operator that is either unknown or cannot be applied to the types of the operands. The VLS describes the procedure by which the compiler resolves infix operators.
  • UnresolvedIdentifier - Generated when the program makes reference to an identifier that cannot be resolved according to the scoping rules of Virgil. The VLS states the scoping rules for resolving identifiers (types and variables) in more detail.
  • UnresolvedMember - Generated when the program makes reference to a member of a type that cannot be resolved.
  • UnresolvedOperator - Generated when the program attempts to use an unknown operator.
  • UnresolvedType - Generated when the program makes reference to a type that cannot be resolved.
  • UnresolvedUnaryOp - Generated when the program attempts to use an unary operator that is either unknown or cannot be applied to the type of the operand. The VLS describes the procedure by which the compiler resolves unary operators.
  • VariableNotInitialized - Generated upon the attempted use of a local variable that has not been initialized before use. The VLS states that all local variables must be assigned a definite value before the first use, either at the point of declaration or at some control flow point that precedes the variable use.
  • VariableRedefined - Generated when the program attempts to define a variable with the same name as a previously defined variable in the same scope. The VLS states that each variable within a scope must be given a unique name that is a valid Virgil identifier.
  • VoidReturn - Generated when the body of a method that has been declared to return a non-void value includes a return statement that does not have a value. The VLS states that each method that is declared to return a non-void type must contain at least one return statement at the flow end(s) of the method that returns a value.