func (this VarDecl) TypeCheck(typeCheckArgs interfaces.TypeCheckArgs) { // store type for identifier so when we find VarExpr with this VarID we know its real type (used during typechecking) typeCheckArgs.Symbols().SetTypeForVarID(this.ValueType(), this.VariableIdentifier()) // we mark it as known to indicate that earlier references to this VarID are valid typeCheckArgs.TypeChecker().MarkVarIDAsKnown(this.VariableIdentifier()) }
// checkQuestionForRedeclarationWithDifferentTypes checks if the passed question has been declared before with a different type, and if so, adds an error to the typechecker func checkQuestionForRedeclarationWithDifferentTypes(question interfaces.Question, typeCheckArgs interfaces.TypeCheckArgs) { varDecl := question.VarDecl() varID := varDecl.VariableIdentifier() if typeCheckArgs.Symbols().IsTypeSetForVarID(varID) && typeCheckArgs.Symbols().TypeForVarID(varID) != varDecl.ValueType() { typeCheckArgs.TypeChecker().AddEncounteredError(errors.NewQuestionRedeclaredWithDifferentTypesError(varDecl.ValueType(), typeCheckArgs.Symbols().TypeForVarID(varID))) } }
func (this VarExpr) TypeCheck(typeCheckArgs interfaces.TypeCheckArgs) interfaces.ValueType { typeCheckArgs.TypeChecker().AddDependencyForVarDecl(this.VarIdentifier(), typeCheckArgs.CurrentVarDeclVisited()) // Return the true type of the VarExpr; the type of the Expr referred to if typeCheckArgs.Symbols().IsTypeSetForVarID(this.VarIdentifier()) { return typeCheckArgs.Symbols().TypeForVarID(this.VarIdentifier()).(interfaces.ValueType) } // We don't already mark it as an error; because there is only one scope, the VarDecl may be simply declared later on typeCheckArgs.TypeChecker().MarkVarIDAsUnknown(this.VarIdentifier()) // No type info in symbol table (reference to undefined question) return NewUnknownType() }