The present application provides a method and apparatus for
type inference in a
programming language. The method comprises: acquiring an
abstract syntax tree of
source code, wherein the
abstract syntax tree comprises a first node and a subtree of the first node, the first node indicates a first field in the
source code, and the first field is one of the following: a variable, a class, a function or a parameter; constructing or updating a full type tree on the basis of the
abstract syntax tree, wherein the full type tree indicates the types of a plurality of nodes in the
abstract syntax tree and the relationship between the plurality of nodes, and the types of the plurality of nodes are determined on the basis of at least one of the following: the type of a second node in the plurality of nodes is indicated by the
abstract syntax tree, and the type of a third node in the plurality of nodes is obtained from a type map, or the type of a fourth node in the plurality of nodes is based on the type of a fifth node, and the type of the fifth node is indicated by the
abstract syntax tree or obtained from the type map, wherein the type map indicates the mapping relationship between at least one
declaration and at least one type; and outputting an
inference result on the basis of the full type tree, wherein the
inference result comprises the type of the first node. The solution of the present application facilitates quick and accurate
type inference.