Buggy code:
public final class CodeGeneration { private final ModuleLoader loader ; private final GlobalResolver resolver ; private GlobalGenerator globalGenerator ; private LocalGenerator localGenerator ; private Stack < CodeGeneration . Scope > scopes = new Stack < CodeGeneration . Scope > ( ) ; private FunctionOrMethodOrMessage currentFunDecl ; private final HashMap < String , Integer > shadows = new HashMap < String , Integer > ( ) ; public CodeGeneration ( ModuleLoader loader , GlobalResolver resolver ) { } public List < Module > generate ( CompilationGroup files ) { } private Module generate ( WhileyFile wf ) { } private ConstDef generate ( Constant cd ) { } private TypeDef generate ( TypeDef td ) throws ResolveError { Block constraint = null ; if ( ( td . constraint ) != null ) { localGenerator = new LocalGenerator ( globalGenerator , td ) ; NameID nid = new NameID ( td . file ( ) . module , td . name ) ; <START_BUG> constraint = globalGenerator . generate ( nid , td ) ; <END_BUG> } return new Module . TypeDef ( td . modifiers , td . name ( ) , td . resolvedType . raw ( ) , constraint ) ; } private Method generate ( FunctionOrMethodOrMessage fd ) { } private Block generate ( Stmt stmt , HashMap < String , Integer > environment ) { } private Block generate ( Assign s , HashMap < String , Integer > environment ) { } private Pair < Expr . AssignedVariable , Integer > extractLVal ( Expr e , ArrayList < String > fields , Block blk , HashMap < String , Integer > environment ) { } private Block generate ( Assert s , HashMap < String , Integer > environment ) { } private Block generate ( Return s , HashMap < String , Integer > environment ) { } private Block generate ( Skip s , HashMap < String , Integer > environment ) { } private Block generate ( Debug s , HashMap < String , Integer > environment ) { } private Block generate ( IfElse s , HashMap < String , Integer > environment ) { } private Block generate ( Throw s , HashMap < String , Integer > environment ) { } private Block generate ( Break s , HashMap < String , Integer > environment ) { } private Block generate ( Switch s , HashMap < String , Integer > environment ) throws ResolveError { } private Block generate ( TryCatch s , HashMap < String , Integer > environment ) throws ResolveError { } private Block generate ( While s , HashMap < String , Integer > environment ) { } private Block generate ( DoWhile s , HashMap < String , Integer > environment ) { } private Block generate ( ForAll s , HashMap < String , Integer > environment ) { } private static int allocate ( HashMap < String , Integer > environment ) { } private static int allocate ( String var , HashMap < String , Integer > environment ) { } private static Expr invert ( Expr e ) { } private static Collection < Attribute > attributes ( SyntacticElement elem ) { } private < T extends CodeGeneration . Scope > T findEnclosingScope ( Class < T > c ) { } private abstract class Scope { } private class BreakScope extends CodeGeneration . Scope { public String label ; public BreakScope ( String l ) { } } private class ContinueScope extends CodeGeneration . Scope { public String label ; public ContinueScope ( String l ) { } } }

Fix:
constraint = globalGenerator . generate ( td . unresolvedType , td ) ;