[Next] [Previous] [Up] [Top] [Contents] [Index]

3 Static Types

3.7 Type Checking Expressions, Statements, and Declarations

Type checking an expression or statement determines whether it is type-correct, and if type-correct also determines the type of its result. Type checking a declaration simply checks for type correctness. All constructs are type-checked in a typing context containing the following information:

The type checking rules for expressions are as follows:

	role-annotation object inherits parent1, ..., parentK
	                  subtypes supertype1, ..., supertypeL
	                  isa parent-and-supertype1, ..., parent-and-supertypeM
	                  { field1@obj1 := expr1, ..., fieldN@objN := exprN }
	&(x1:type1, ..., xN:typeN):typeR { body }
	&(type1, ..., typeN):typeR.
	resend(..., xi@parenti, ..., exprj, ...)

The following rules define type-correctness of statements:

The body of a method, closure, or parenthetical expression is type-correct iff its statements are type-correct. The type of the result of a body is the type of its last statement, if present, or void, otherwise.

The following rules define type-correctness of declarations:

	type name subtypes supertype1, ..., supertypeN
	role-annotation kind name inherits parent1, ..., parentK
	                    subtypes supertype1, ..., supertypeL
	                    isa parent-and-supertype1, ..., parent-and-supertypeM
	                    { field1@obj1 := expr1, ..., fieldN@objN := exprN }
	extend type name subtypes supertype1, ..., supertypeN
	extend kind name inherits parent1, ..., parentK
	   					subtypes supertype1, ..., supertypeL
						isa parent-and-supertype1, ..., parent-and-supertypeM
					 	{ field1@obj1 := expr1, ..., fieldN@objN := exprN }
	signature name(x1:type1,...,xN:typeN):typeR
	var field signature name(x:type):typeR
	signature name(type):typeR
	signature set_name(type,typeR):void
	method kind name(x1@obj1:type1,...,xN@objN:typeN):typeR { body }
	signature name(type1,...,typeN):typeR
	shared var field kind name(x@obj:type):typeR := expr;

[13] The check that the argument type is not void is not strictly necessary, since no signature will have an argument type that is a supertype of void.